Skip to content

Commit

Permalink
Merge branch 'rails6'
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Sep 18, 2019
2 parents ee57081 + 6ffbb8b commit 57acb10
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 46 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ services:
addons:
postgresql: "9.4"
apt:
sources:
- google-chrome
packages:
- google-chrome-stable

- chromium-browser
- libgconf-2-4
chrome: stable

before_script:
- sleep 10
- sh -e /etc/init.d/xvfb start
Expand Down
10 changes: 7 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'rspec-rails'

gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails', branch: '4-0-dev'

#%w[rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
# gem lib , :git => "https://github.com/rspec/#{lib}.git", :branch => 'master'
#end

gem 'awesome_print'
gem 'bundler-audit'
gem 'pry-byebug'
Expand All @@ -92,8 +98,6 @@ group :test do
#gem 'selenium-webdriver'
gem 'webdrivers', '~> 4.0'

# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'faker'
Expand Down
31 changes: 15 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ GIT
friendly_id (5.2.5)
activerecord (>= 4.0.0)

GIT
remote: https://github.com/rspec/rspec-rails
revision: c11a1b6fff72c6c45c67727480d4558742eb292c
branch: 4-0-dev
specs:
rspec-rails (4.0.0.beta2)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.8)
rspec-expectations (~> 3.8)
rspec-mocks (~> 3.8)
rspec-support (~> 3.8)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -65,8 +79,6 @@ GEM
zeitwerk (~> 2.1, >= 2.1.8)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
archive-zip (0.12.0)
io-like (~> 0.3.0)
autoprefixer-rails (9.6.1.1)
execjs
awesome_print (1.8.0)
Expand Down Expand Up @@ -113,9 +125,6 @@ GEM
xpath (~> 3.2)
childprocess (2.0.0)
rake (< 13.0)
chromedriver-helper (2.1.1)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
coderay (1.1.2)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -163,7 +172,6 @@ GEM
hashie (3.6.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
io-like (0.3.0)
jbuilder (2.9.1)
activesupport (>= 4.2.0)
jmespath (1.4.0)
Expand Down Expand Up @@ -295,14 +303,6 @@ GEM
rspec-mocks (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
ruby_dep (1.5.0)
rubyzip (1.2.4)
Expand Down Expand Up @@ -386,7 +386,6 @@ DEPENDENCIES
bundler-audit
byebug
capybara (>= 2.15)
chromedriver-helper
coffee-rails (~> 4.2)
dalli
database_cleaner
Expand All @@ -410,7 +409,7 @@ DEPENDENCIES
rails-controller-testing
rb-readline
react-rails
rspec-rails
rspec-rails!
sass-rails (~> 5.0)
searchkick
sidekiq
Expand Down
15 changes: 10 additions & 5 deletions spec/controllers/posts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

RSpec.describe PostsController do

let(:user){create(:user)}

describe "Access Control" do
describe "GET #show" do
let(:post) { create(:post) }
let(:post) { create(:post, user: user) }

it "non-logged-in user can also access the page" do
get :show, params: {id: post.slug}
Expand Down Expand Up @@ -40,7 +42,7 @@
end

describe "PATCH #update" do
let(:post) { create(:post) }
let(:post) { create(:post, user: user) }
it "requires a logged-in user" do
patch :update, params: {
id: post.id,
Expand All @@ -51,7 +53,7 @@
end

describe "DELETE #destroy" do
let(:post) { create(:post) }
let(:post) { create(:post, user: user) }
it "requires a logged-in user" do
delete :destroy, params: {id: post.id}
expect(response).to redirect_to(new_user_session_path)
Expand Down Expand Up @@ -109,7 +111,10 @@

describe "POST #create_and_edit" do
it "creates a post and redirect_to edit page" do
@draft = build(:draft, title: " ", body: "this is a story of my life")
@draft = build(:draft, title: " ",
body: "this is a story of my life",
user: user
)
expect{
post :create_and_edit, params: {
post: {
Expand All @@ -121,7 +126,7 @@
end

it "redirects to edit page" do
@draft = build(:draft, title: "", body: "hello world")
@draft = build(:draft, title: "", body: "hello world", user: user)
post :create_and_edit, params: {
post: {
title: @draft.title,
Expand Down
2 changes: 1 addition & 1 deletion spec/features/user_bookmarks_post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.feature "Bookmarking a post" do
let(:user) { create(:user) }
let(:post) { create(:post) }
let(:post) { create(:post, user: user) }

scenario "signed-in user bookmarks a post successfully", js: true do
sign_in user
Expand Down
4 changes: 2 additions & 2 deletions spec/features/user_bookmarks_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

RSpec.feature "Bookmarking a response" do
let(:user) { create(:user) }
let(:post) { create(:post) }
let(:response) { build(:post) }
let(:post) { create(:post, user: user) }
let(:response) { build(:post, user: user) }

background do
post.responses << response
Expand Down
4 changes: 2 additions & 2 deletions spec/features/user_likes_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

RSpec.feature "Liking a response" do
let(:user) { create(:user) }
let(:post) { create(:post) }
let(:response) { build(:post) }
let(:post) { create(:post, user: user) }
let(:response) { build(:post, user: user) }

background do
post.responses << response
Expand Down
21 changes: 12 additions & 9 deletions spec/models/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
require "rails_helper"

RSpec.describe Post do
let(:user) { create(:user) }

describe "validations" do
let(:post) { build(:post) }
let(:post) { build(:post, user: user) }

it "requires a body" do
post.body = " "
Expand All @@ -35,8 +37,8 @@
end

describe "scopes" do
let!(:post) { create(:post) }
let!(:draft) { create(:draft) }
let!(:post) { create(:post, user: user) }
let!(:draft) { create(:draft, user: user) }

describe "published" do
it "returns published posts" do
Expand Down Expand Up @@ -103,33 +105,33 @@

describe "#publish" do
it "sets published_at and saves the record" do
post = build(:draft)
post = build(:draft, user: user)
post.publish
expect(post.published_at).to be_present
expect(post).to be_persisted
end

it "sets appropriate slug when there are multiple posts with the same title" do
post1 = build(:draft, plain: "My favorite music")
post1 = build(:draft, plain: "My favorite music", user: user)
post1.publish
expect(post1.slug).to eq('my-favorite-music')

post2 = build(:draft, plain: "My favorite music")
post2 = build(:draft, plain: "My favorite music", user: user)
post2.publish
expect(post2).to be_persisted
expect(post2.slug).not_to eq("my-favorite-music")
expect(post2.slug).to match(/my-favorite-music/)
end

it "returns falsly value when it fails validations" do
post = build(:draft, body: ' ')
post = build(:draft, body: ' ', user: user)
expect(post.publish).to be_falsy
end
end

describe "#save_as_draft" do
it "sets published_at to nil and saves the record" do
post = build(:draft)
post = build(:draft, user: user)
post.save_as_draft
expect(post.published_at).to be_nil
expect(post).to be_persisted
Expand All @@ -139,7 +141,8 @@
describe "words and word_count" do
let(:post) { build(:post,
body: "{}",
plain: "This is five words long.")
plain: "This is five words long." ,
user: user)
}

it "returns an array of words" do
Expand Down
6 changes: 3 additions & 3 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@

describe "adding likes" do
let(:user) { create(:user) }
let(:post) { create(:post) }
let(:response) { build(:post) }
let(:post) { create(:post, user: user) }
let(:response) { build(:post, user: user) }
before :each do
post.responses << response
end
Expand Down Expand Up @@ -119,7 +119,7 @@
describe "adding bookmarks" do
let(:user) { create(:user) }
let(:post) { create(:post) }
let(:response) { build(:post) }
let(:response) { build(:post, user: user) }
before :each do
post.responses << response
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/setup_capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
desired_capabilities: capabilities
end

Capybara.javascript_driver = ENV['CODESHIP'].present? ? :headless_chrome : :chrome
Capybara.javascript_driver = ENV['CI'].present? ? :headless_chrome : :chrome

# Capybara.default_max_wait_time = 300

0 comments on commit 57acb10

Please sign in to comment.