Skip to content

Commit

Permalink
Fixed last error in document, have shift, shift type, and shift parti…
Browse files Browse the repository at this point in the history
…cipant test passing
  • Loading branch information
Rumby Wilson committed Feb 27, 2017
1 parent 28dfa79 commit aecbc8c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
3 changes: 1 addition & 2 deletions test/unit/document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class DocumentTest < ActiveSupport::TestCase
#scopes
should "show that search scope works" do
@doc = Document.search('booth')
#When actually testing you can see the name, but will default back to document when asserting it for some reason
assert_equal 'Booth', @doc
assert_equal 'Booth', @doc[0].name

end

Expand Down
15 changes: 13 additions & 2 deletions test/unit/shift_participant_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,30 @@ class ShiftParticipantTest < ActiveSupport::TestCase

context "With a proper context, " do
setup do
FactoryGirl.create(:shift_participant)
@shift = FactoryGirl.create(:shift, :ends_at => Time.zone.now + 2.hour, :starts_at => Time.zone.now)
@late= FactoryGirl.create(:shift_participant, :shift_id => @shift.id, :clocked_in_at => Time.zone.now + 1.hour)
@not_late= FactoryGirl.create(:shift_participant, :shift_id => @shift.id, :clocked_in_at => Time.zone.now)
end

teardown do
end

should "show that all factories are properly created" do
assert_equal 1, ShiftParticipant.all.size
assert_equal 2, ShiftParticipant.all.size
end

# Scopes
should "show that scope 'checked in late' is working" do
assert_equal @late.id , ShiftParticipant.checked_in_late[0].id
end

# Methods

end
end






48 changes: 42 additions & 6 deletions test/unit/shift_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ class ShiftTest < ActiveSupport::TestCase
#does not need to have an organization
should validate_presence_of(:starts_at)
should validate_presence_of(:ends_at)
should validate_presence_of(:shift_type)
should validate_presence_of(:required_number_of_participants)

context "With a proper context, " do
setup do
# Create 3 shifts
@upcomming = FactoryGirl.create(:shift, :ends_at => Time.local(2021,1,1,15,0,0), :starts_at => Time.now + 1.hour)
@current = FactoryGirl.create(:shift, :ends_at => Time.local(2020,1,1,15,0,0), :starts_at => Time.local(2014,1,1,13,4,0))
@past = FactoryGirl.create(:shift, :ends_at => Time.local(2001,1,1,15,0,0), :starts_at => Time.local(2000,1,1,14,10,0))
@not_checked_in = FactoryGirl.create(:shift, :required_number_of_participants => 1 )
@checked_in = FactoryGirl.create(:shift, :required_number_of_participants => 2)
@type1 = FactoryGirl.create(:shift_type, :id => 1)
@type2 = FactoryGirl.create(:shift_type, :id => 2)
@type3 = FactoryGirl.create(:shift_type, :id => 3)

@upcomming = FactoryGirl.create(:shift, :shift_type_id => @type1.id, :ends_at => Time.local(2021,1,1,16,0,0), :starts_at => Time.zone.now + 1.hour)
@future = FactoryGirl.create(:shift, :shift_type_id => @type2.id, :ends_at => Time.local(2021,1,1,16,0,0), :starts_at => Time.zone.now + 7.hour)
@current = FactoryGirl.create(:shift, :shift_type_id => @type3.id, :ends_at => Time.local(2020,1,1,16,0,0), :starts_at => Time.local(2016,1,1,13,4,0))
@past = FactoryGirl.create(:shift, :shift_type_id => @type1.id, :ends_at => Time.local(2001,1,1,16,0,0), :starts_at => Time.local(2000,1,1,14,10,0))
@not_checked_in = FactoryGirl.create(:shift, :shift_type_id => @type2.id, :required_number_of_participants => 1, :ends_at => Time.local(2001,1,1,16,0,0), :starts_at => Time.local(2000,1,1,14,10,0))
@checked_in = FactoryGirl.create(:shift, :shift_type_id => @type2.id, :required_number_of_participants => 2, :ends_at => Time.local(2001,1,1,16,0,0), :starts_at => Time.local(2000,1,1,14,10,0))
FactoryGirl.create(:shift_participant, :shift => @checked_in)
FactoryGirl.create(:shift_participant, :shift => @checked_in)
end
Expand All @@ -53,7 +59,7 @@ class ShiftTest < ActiveSupport::TestCase
end

should "show that all factories are properly created" do
assert_equal 5, Shift.all.size
assert_equal 6, Shift.all.size
end

# Scopes
Expand All @@ -65,11 +71,41 @@ class ShiftTest < ActiveSupport::TestCase
assert_equal 1, Shift.upcoming.size
end

should "have a scope 'future' that works" do
assert_equal 2, Shift.future.size
end

should "have a scope 'past' that works" do
assert_equal 3, Shift.past.size
end

should "have a scope 'missed' that works" do
assert_equal 5, Shift.missed.size
end

should "have a scope 'watch_shifts' that works" do
assert_equal 2, Shift.watch_shifts.size
end

should "have a scope 'sec_shifts' that works" do
assert_equal 3, Shift.sec_shifts.size
end

should "have a scope 'coord_shifts' that works" do
assert_equal 1, Shift.coord_shifts.size
end

# Methods

should "have a method 'is_checked_in' that works" do
assert_equal true, @checked_in.is_checked_in
assert_equal false, @not_checked_in.is_checked_in
end

should "have a method 'formatted_name' that works" do
@type = FactoryGirl.create(:shift_type, :name => "Bob")
@ex = FactoryGirl.create(:shift, :shift_type_id => @type.id, :ends_at => Time.local(2001,1,1,16,0,0), :starts_at => Time.local(2000,1,1,14,10,0))
assert_equal 'Bob @ Jan 1 at 2:10 PM', @ex.formatted_name
end
end
end

0 comments on commit aecbc8c

Please sign in to comment.