From 302eefd8409e0778d83bb8115ba7d04c83403acb Mon Sep 17 00:00:00 2001 From: Linda Goldstein Date: Sat, 15 Jun 2019 01:05:11 -0700 Subject: [PATCH 1/2] Move from machinist to factory_bot for test data creation --- spec/controllers/applications_controller_spec.rb | 4 ++-- .../members/applications_controller_spec.rb | 10 +++++----- spec/models/comment_spec.rb | 13 +++++++------ spec/models/profile_spec.rb | 2 +- spec/models/user_spec.rb | 4 ++-- spec/models/vote_spec.rb | 16 ++++++++-------- spec/spec_helper.rb | 2 +- spec/support/blueprints.rb | 2 +- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/spec/controllers/applications_controller_spec.rb b/spec/controllers/applications_controller_spec.rb index 261f1192..b16c340e 100644 --- a/spec/controllers/applications_controller_spec.rb +++ b/spec/controllers/applications_controller_spec.rb @@ -66,7 +66,7 @@ describe 'GET edit' do it 'should redirect to root if not logged in' do - get :edit, id: User.make!(:applicant).application.id + get :edit, id: create(:user, state: :applicant).application.id expect(response).to redirect_to :root end @@ -102,7 +102,7 @@ describe 'POST update' do it 'should redirect to root if not logged in' do - post :update, id: User.make!(:applicant).application.id + post :update, id: create(:user, state: :applicant).application.id expect(response).to redirect_to :root end diff --git a/spec/controllers/members/applications_controller_spec.rb b/spec/controllers/members/applications_controller_spec.rb index 30f9d8de..179ccc10 100644 --- a/spec/controllers/members/applications_controller_spec.rb +++ b/spec/controllers/members/applications_controller_spec.rb @@ -6,7 +6,7 @@ render_views before :each do - @applicant = User.make!(:applicant) + @applicant = create(:user, state: :applicant) end describe 'GET show' do @@ -38,7 +38,7 @@ it 'renders if application is in submitted state' do login_as(:member) - applicant = User.make!(:applicant) + applicant = create(:user, state: :applicant) application = applicant.application application.update_attribute(:state, 'submitted') @@ -49,7 +49,7 @@ it 'redirects if application is in approved state' do login_as(:member) - applicant = User.make!(:applicant) + applicant = create(:user, state: :applicant) application = applicant.application application.update_attribute(:state, 'approved') @@ -60,7 +60,7 @@ it 'redirects if application is in rejected state' do login_as(:member) - applicant = User.make!(:applicant) + applicant = create(:user, state: :applicant) application = applicant.application application.update_attribute(:state, 'rejected') @@ -71,7 +71,7 @@ describe 'for submitted application' do before :each do - @submitted_application = User.make!(:applicant).application + @submitted_application = create(:user, state: :applicant).application @submitted_application.update_attribute(:state, 'submitted') end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index f43d6d78..b2a7865a 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -15,31 +15,32 @@ it 'should not be valid for visitor' do comment = Comment.new - comment.user = User.make!(:visitor) + comment.user = create(:user, state: :visitor) expect(comment.tap(&:valid?)).to have_at_least(1).errors_on(:user) end it 'should not be valid for applicant' do - comment = Comment.new(user: User.make!(:applicant)) + comment = Comment.new(user: create(:user, state: :applicant)) expect(comment.tap(&:valid?)).to have_at_least(1).errors_on(:user) end it 'should be valid for member' do comment = Comment.new - comment.user = User.make!(:member) + comment.user = create(:user, state: :member) expect(comment.tap(&:valid?)).to have(0).errors_on(:user) end it 'should be valid for voting member' do comment = Comment.new - comment.user = User.make!(:voting_member) + comment.user = create(:user, state: :voting_member) expect(comment.tap(&:valid?)).to have(0).errors_on(:user) end it 'should be saved for member' do comment = Comment.new(body: 'hello') - comment.application = Application.make!(:with_user) - comment.user = User.make!(:member) + user = create(:user, state: :applicant) + comment.application = create(:application, user: user) + comment.user = create(:user, state: :member) expect(comment.save).to be_truthy end end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 0076a2d5..7f74ab7c 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -7,7 +7,7 @@ it 'should be valid with user id' do profile = Profile.new - profile.user = User.make! + profile.user = create(:user) expect(profile.valid?).to be_truthy end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ab3c68ac..f458b139 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -28,11 +28,11 @@ it 'should have profile after created' do expect(User.new.profile).to be_nil - expect(User.make!.profile).to be_an_instance_of(Profile) + expect(create(:user).profile).to be_an_instance_of(Profile) end it 'should accept nested attributes for profile' do - user = User.make! + user = create(:user) expect(user.profile.twitter).to be_nil user.update_attributes!(profile_attributes: { id: user.profile.id, diff --git a/spec/models/vote_spec.rb b/spec/models/vote_spec.rb index d8e3479f..cb040c1a 100644 --- a/spec/models/vote_spec.rb +++ b/spec/models/vote_spec.rb @@ -16,8 +16,8 @@ it 'should be invalid if voter is member' do vote = Vote.new - vote.user = User.make!(:member) - vote.application = Application.make!(user: User.make!(:applicant)) + vote.user = create(:user, state: :member) + vote.application = create(:application, user: create(:user, state: :applicant)) vote.value = true expect(vote.valid?).to be_falsey expect(vote).to have_at_least(1).errors_on(:user) @@ -26,17 +26,17 @@ it 'should be valid if voter is voting member' do vote = Vote.new - vote.user = User.make!(:voting_member) - vote.application = Application.make!(user: User.make!(:applicant)) + vote.user = create(:user, state: :voting_member) + vote.application = create(:application, user: create(:user, state: :applicant)) vote.value = true expect(vote.valid?).to be_truthy end it 'should validate uniqueness per user and application' do - applicant = User.make!(:applicant) - application = Application.make!(user: applicant) - voter = User.make!(:voting_member) - vote = Vote.make!(application: application, user: voter) + applicant = create(:user, state: :applicant) + application = create(:application, user: applicant) + voter = create(:user, state: :voting_member) + vote = create(:vote, application: application, user: voter) invalid = Vote.new(application: application, user: voter, diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aa0d6e39..0c43e1bf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -89,7 +89,7 @@ module AuthHelper def login_as(user_or_state, attrs = {}) user = user_or_state.is_a?(User) ? user_or_state : nil - user ||= User.make!(user_or_state, attrs) + user ||= create(:user, attrs.merge(state: user_or_state)) allow(controller).to receive(:current_user).and_return(user) user end diff --git a/spec/support/blueprints.rb b/spec/support/blueprints.rb index dc7824a4..506f0c1b 100644 --- a/spec/support/blueprints.rb +++ b/spec/support/blueprints.rb @@ -23,7 +23,7 @@ Application.blueprint do end -Application.blueprint(:with_user) { user { User.make!(:applicant) } } +Application.blueprint(:with_user) { user { create(:user, state: :applicant) } } Vote.blueprint do value { true } From 2b085cad570fe0fe9a3d449e6516254fed147017 Mon Sep 17 00:00:00 2001 From: Linda Goldstein Date: Sat, 15 Jun 2019 01:15:55 -0700 Subject: [PATCH 2/2] Remove blueprints.rb and machinist gem --- Gemfile | 1 - Gemfile.lock | 2 -- config/application.rb | 2 -- spec/support/blueprints.rb | 34 ---------------------------------- 4 files changed, 39 deletions(-) delete mode 100644 spec/support/blueprints.rb diff --git a/Gemfile b/Gemfile index c34ce356..6653da77 100644 --- a/Gemfile +++ b/Gemfile @@ -65,7 +65,6 @@ group :test do gem 'email_spec' gem 'factory_girl_rails' gem 'launchy' - gem 'machinist' gem 'rspec-collection_matchers' gem 'selenium-webdriver' gem 'shoulda-matchers' diff --git a/Gemfile.lock b/Gemfile.lock index 39f24fb1..521d7a5a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -179,7 +179,6 @@ GEM loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) - machinist (2.0) mail (2.7.1) mini_mime (>= 0.1.1) method_source (0.9.2) @@ -376,7 +375,6 @@ DEPENDENCIES jquery-rails kaminari launchy - machinist omniauth omniauth-github omniauth-google-oauth2 diff --git a/config/application.rb b/config/application.rb index 3fdab3f6..5a30e3e3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -19,8 +19,6 @@ class Application < Rails::Application g.test_framework :rspec, fixture: true - g.fixture_replacement :machinist - g.view_specs false g.helper_specs false end diff --git a/spec/support/blueprints.rb b/spec/support/blueprints.rb deleted file mode 100644 index 506f0c1b..00000000 --- a/spec/support/blueprints.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'machinist/active_record' - -# Add your blueprints here. -# -# e.g. -# Post.blueprint do -# title { "Post #{sn}" } -# body { "Lorem ipsum..." } -# end - -User.blueprint do - username { "user#{sn}" } - email { "#{sn}@example.com" } - # Attributes here -end - -User.blueprint(:visitor) { state { 'visitor' } } -User.blueprint(:applicant) { state { 'applicant' } } -User.blueprint(:member) { state { 'member' } } -User.blueprint(:key_member) { state { 'key_member' } } -User.blueprint(:voting_member) { state { 'voting_member' } } - -Application.blueprint do -end - -Application.blueprint(:with_user) { user { create(:user, state: :applicant) } } - -Vote.blueprint do - value { true } -end - -Comment.blueprint do - # Attributes here -end