Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove machinist gem in favor of factory_bot #348

Merged
merged 4 commits into from
Jun 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,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)
Expand Down Expand Up @@ -384,7 +383,6 @@ DEPENDENCIES
jquery-rails
kaminari
launchy
machinist
omniauth
omniauth-github
omniauth-google-oauth2
Expand Down
2 changes: 0 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/applications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/members/applications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
render_views

before :each do
@applicant = User.make!(:applicant)
@applicant = create(:user, state: :applicant)
end

describe 'GET show' do
Expand Down Expand Up @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand All @@ -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

Expand Down
13 changes: 7 additions & 6 deletions spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/models/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions spec/models/vote_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 0 additions & 34 deletions spec/support/blueprints.rb

This file was deleted.