Skip to content

Commit

Permalink
Outsource event genereation to factory #233
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederike Ramin committed Jan 18, 2017
1 parent 39d44e1 commit 925865d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def lock_application_status
update(application_status_locked: true)
end

# Returns the current statse of the event (draft-, application-, selection- and execution-phase)
# Returns the current state of the event (draft-, application-, selection- and execution-phase)
#
# @param none
# @return [Symbol] state
Expand Down
29 changes: 29 additions & 0 deletions spec/factories/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,35 @@
end
end

trait :in_draft_phase do
after(:build) do |event|
event.draft = true
end
end

trait :in_application_phase do
after(:build) do |event|
event.draft = false
event.application_deadline = Date.tomorrow
end
end

trait :in_selection_phase do
after(:build) do |event|
event.draft = false
event.application_deadline = Date.yesterday
event.application_status_locked = false
end
end

trait :in_execution_phase do
after(:build) do |event|
event.draft = false
event.application_deadline = Date.yesterday
event.application_status_locked = true
end
end

factory :event_with_accepted_applications do
name "Event-Name"
description "Event-Description"
Expand Down
17 changes: 4 additions & 13 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,31 +190,22 @@
end

it "is in draft phase" do
event = FactoryGirl.build(:event)
event.draft = true
event = FactoryGirl.build(:event, :in_draft_phase)
expect(event.phase).to eq(:draft)
end

it "is in application phase" do
event = FactoryGirl.build(:event)
event.draft = false
event.application_deadline = Date.tomorrow
event = FactoryGirl.build(:event, :in_application_phase)
expect(event.phase).to eq(:application)
end

it "is in selection phase" do
event = FactoryGirl.build(:event)
event.draft = false
event.application_deadline = Date.yesterday
event.application_status_locked = false
event = FactoryGirl.build(:event, :in_selection_phase)
expect(event.phase).to eq(:selection)
end

it "is in execution phase" do
event = FactoryGirl.build(:event)
event.draft = false
event.application_deadline = Date.yesterday
event.application_status_locked = true
event = FactoryGirl.build(:event, :in_execution_phase)
expect(event.phase).to eq(:execution)
end

Expand Down

0 comments on commit 925865d

Please sign in to comment.