Skip to content

Commit

Permalink
FactoryGirl -> FactoryBot
Browse files Browse the repository at this point in the history
  • Loading branch information
boone committed Oct 30, 2017
1 parent 946c9ac commit 2b2904b
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem 'turbolinks', '~> 5.0.1'

group :test do
gem 'shoulda'
gem 'factory_girl_rails'
gem 'factory_bot_rails'
gem 'capybara'
gem 'launchy'
gem 'ruby-prof'
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ GEM
crass (1.0.2)
erubi (1.7.0)
execjs (2.7.0)
factory_girl (4.7.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
ffi (1.9.18)
globalid (0.4.0)
Expand Down Expand Up @@ -164,7 +164,7 @@ PLATFORMS
DEPENDENCIES
capybara
coffee-rails
factory_girl_rails
factory_bot_rails
jquery-rails
kaminari
launchy
Expand Down
8 changes: 4 additions & 4 deletions test/factories.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FactoryGirl.define do
FactoryBot.define do
factory :client do
name 'Foo Inc.'
end

factory :project do
client
title 'Hard Work'
end

factory :event do |f|
f.project
f.comment 'An event'
f.start { 1.hour.ago }
f.end { Time.now }
end
end
end
2 changes: 1 addition & 1 deletion test/functional/clients_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ClientsControllerTest < ActionController::TestCase
setup do
@client = FactoryGirl.create(:client)
@client = FactoryBot.create(:client)
end

test "should get index" do
Expand Down
6 changes: 3 additions & 3 deletions test/functional/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class EventsControllerTest < ActionController::TestCase
setup do
@event = FactoryGirl.create(:event)
@event = FactoryBot.create(:event)
end

test "should get index" do
Expand All @@ -18,7 +18,7 @@ class EventsControllerTest < ActionController::TestCase
end

test "should create event" do
new_event = FactoryGirl.build(:event, end: nil, comment: 'New Event')
new_event = FactoryBot.build(:event, end: nil, comment: 'New Event')
assert_difference('Event.count') do
post :create, params: { event: @event.attributes }
end
Expand Down Expand Up @@ -63,7 +63,7 @@ class EventsControllerTest < ActionController::TestCase
end

test 'should stop' do
current_event = FactoryGirl.create(:event, end: nil, comment: 'Current event')
current_event = FactoryBot.create(:event, end: nil, comment: 'Current event')
put :stop, params: { id: current_event.to_param }
assert_redirected_to events_url
end
Expand Down
4 changes: 2 additions & 2 deletions test/functional/projects_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ProjectsControllerTest < ActionController::TestCase
setup do
@project = FactoryGirl.create(:project)
@project = FactoryBot.create(:project)
end

test "should get index" do
Expand All @@ -18,7 +18,7 @@ class ProjectsControllerTest < ActionController::TestCase
end

test "should create project" do
new_project = FactoryGirl.build(:project, title: 'New Project')
new_project = FactoryBot.build(:project, title: 'New Project')
assert_difference('Project.count') do
post :create, params: { client_id: new_project.client,
project: new_project.attributes }
Expand Down
2 changes: 1 addition & 1 deletion test/functional/reports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ReportsControllerTest < ActionController::TestCase
setup do
@client = FactoryGirl.create(:event).project.client
@client = FactoryBot.create(:event).project.client
end

test 'should show report' do
Expand Down
18 changes: 9 additions & 9 deletions test/integration/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class IntegrationTest

class MainTest < ActionDispatch::IntegrationTest
should 'be able to start an event' do
FactoryGirl.create(:project, title: 'One Project') # form needs a project
FactoryBot.create(:project, title: 'One Project') # form needs a project
visit '/events'
click_link 'New Event'
assert page.has_content?('New Event'), 'checking for New event on page'
Expand All @@ -27,25 +27,25 @@ class MainTest < ActionDispatch::IntegrationTest
end

should 'not permit a project to be deleted if it has events' do
event = FactoryGirl.create(:event)
event = FactoryBot.create(:event)
visit client_project_path(event.project.client, event.project)
assert page.has_no_content?('Delete')
end

should 'permit a project to be deleted if it has no events' do
project = FactoryGirl.create(:project)
project = FactoryBot.create(:project)
visit client_project_path(project.client, project)
assert page.has_content?('Delete')
end

should 'not permit a client to be deleted if it has projects' do
project = FactoryGirl.create(:project)
project = FactoryBot.create(:project)
visit client_path(project.client)
assert page.has_no_content?('Delete')
end

should 'permit a client to be deleted if it has no projects' do
client = FactoryGirl.create(:client)
client = FactoryBot.create(:client)
visit client_path(client)
assert page.has_content?('Delete')
end
Expand All @@ -62,7 +62,7 @@ class MainTest < ActionDispatch::IntegrationTest

should 'create a new project' do
project_name = 'Difficult Task'
client = FactoryGirl.create(:client)
client = FactoryBot.create(:client)
visit client_projects_path(client)
click_link 'New'
fill_in 'Title', with: project_name
Expand All @@ -72,7 +72,7 @@ class MainTest < ActionDispatch::IntegrationTest
end

should 'create a new event' do
project = FactoryGirl.create(:project)
project = FactoryBot.create(:project)
visit events_path
click_link 'New Event'
fill_in 'Comment', with: 'Details'
Expand All @@ -83,12 +83,12 @@ class MainTest < ActionDispatch::IntegrationTest
end

should 'only allow one current event' do
current_event = FactoryGirl.create(:event, end: nil)
current_event = FactoryBot.create(:event, end: nil)

visit new_event_path
fill_in 'Comment', with: 'Second running event'
click_button 'Create Event'
assert page.has_content?('Cannot start a new current event while another is running')
end

end
end
4 changes: 2 additions & 2 deletions test/unit/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
class ClientTest < ActiveSupport::TestCase
should have_many(:projects)
should validate_presence_of(:name)

should 'not be destroyable if there are projects' do
project = FactoryGirl.create(:project)
project = FactoryBot.create(:project)
client = project.client
assert_raise(ActiveRecord::DeleteRestrictionError) { client.destroy }
assert !client.destroyed?, 'check for !client.destroyed?'
Expand Down
40 changes: 20 additions & 20 deletions test/unit/event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,64 @@ class EventTest < ActiveSupport::TestCase
should belong_to(:project)
should validate_presence_of(:project)
should validate_presence_of(:start)

should 'allow start time before end time' do
event = FactoryGirl.build(:event, start: 1.hour.ago, end: Time.now)
event = FactoryBot.build(:event, start: 1.hour.ago, end: Time.now)
assert event.valid?
end

should 'not allow start time after end time' do
event = FactoryGirl.build(:event, end: 1.hour.ago, start: Time.now)
event = FactoryBot.build(:event, end: 1.hour.ago, start: Time.now)
assert !event.valid?
assert event.errors[:end]
end

should 'not allow multiple current events' do
current_event = FactoryGirl.build(:event, end: nil)
current_event = FactoryBot.build(:event, end: nil)
event = Event.new(start: Time.now, comment: 'Second event')
assert !event.valid?
assert event.errors[:base]
end

should 'compute zero for daily time when there are no events today' do
FactoryGirl.create(:event, start: 1.day.ago.beginning_of_day, end: 1.day.ago.beginning_of_day + 1.hour) # yesterday
FactoryBot.create(:event, start: 1.day.ago.beginning_of_day, end: 1.day.ago.beginning_of_day + 1.hour) # yesterday
assert_equal 0, Event.time_today
end

should 'compute correct daily time when there is no current event' do
FactoryGirl.create(:event, start: 1.day.ago.beginning_of_day, end: 1.day.ago.beginning_of_day + 1.hour) # yesterday
FactoryGirl.create(:event, start: Time.now.beginning_of_day, end: Time.now.beginning_of_day + 1.hour) # 1 hour
FactoryGirl.create(:event, start: Time.now.beginning_of_day + 2.hours, end: Time.now.beginning_of_day + 3.hours) # 1.hour
FactoryBot.create(:event, start: 1.day.ago.beginning_of_day, end: 1.day.ago.beginning_of_day + 1.hour) # yesterday
FactoryBot.create(:event, start: Time.now.beginning_of_day, end: Time.now.beginning_of_day + 1.hour) # 1 hour
FactoryBot.create(:event, start: Time.now.beginning_of_day + 2.hours, end: Time.now.beginning_of_day + 3.hours) # 1.hour
assert_equal 2, Event.today.count
assert_equal 2.hours, Event.time_today
end

should 'compute correct daily time when there is a current event' do
FactoryGirl.create(:event, start: 1.day.ago.beginning_of_day, end: 1.day.ago.beginning_of_day + 1.hour) # yesterday
FactoryGirl.create(:event, start: Time.now.beginning_of_day, end: Time.now.beginning_of_day + 1.hour) # 1 hour
FactoryGirl.create(:event, start: Time.now.beginning_of_day, end: nil)
FactoryBot.create(:event, start: 1.day.ago.beginning_of_day, end: 1.day.ago.beginning_of_day + 1.hour) # yesterday
FactoryBot.create(:event, start: Time.now.beginning_of_day, end: Time.now.beginning_of_day + 1.hour) # 1 hour
FactoryBot.create(:event, start: Time.now.beginning_of_day, end: nil)

assert_equal 2, Event.today.count

# Time.now calls at different stages will not be exact, so assert the results are the same to thousandths of an hour
expected_time = ((1.hour + (Time.now - Time.now.beginning_of_day)) / 3.6).to_i
actual_time = (Event.time_today / 3.6).to_i
assert_equal expected_time, actual_time
end

should 'be able to resume a completed event' do
original_event = FactoryGirl.create(:event)
original_event = FactoryBot.create(:event)
original_start_time = original_event.start.to_i # typecast to avoid nanosecond comparions
original_end_time = original_event.end.to_i # typecast to avoid nanosecond comparions
assert_equal 1, Event.count

original_event.resume!
original_event.reload

# test that the original event's times have not been modified
assert_equal original_start_time, original_event.start.to_i
assert_equal original_end_time, original_event.end.to_i

# test that the original event and the new event are present
assert_equal 2, Event.count
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ProjectTest < ActiveSupport::TestCase
should validate_presence_of(:title)

should 'not be destroyable if there are events' do
event = FactoryGirl.create(:event)
event = FactoryBot.create(:event)
project = event.project
assert_raise(ActiveRecord::DeleteRestrictionError) { project.destroy }
assert !project.destroyed?, 'check for !project.destroyed?'
Expand Down

0 comments on commit 2b2904b

Please sign in to comment.