Skip to content

Commit

Permalink
added trait for job, event factories
Browse files Browse the repository at this point in the history
  • Loading branch information
PraveenVignesh committed Mar 13, 2015
1 parent df0fda1 commit a1aac53
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
23 changes: 23 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
factory :event do
short_code { generate(:random_word) }
name Faker::Lorem.word

trait :end_tomorrow do
start_date Time.now
end_date Time.now + 1.day
end

trait :future do
start_date Time.now + 1.day
end_date Time.now + 2.day
end

trait :end_today do
start_date Time.now
end_date Time.now
end
end

factory :organization do
Expand All @@ -22,6 +37,14 @@

factory :job do
title Faker::Lorem.sentence(3)

trait :expire_tomorrow do
expires_at DateTime.now + 1.day
end

trait :expired do
expires_at DateTime.now - 1.day
end
end

factory :project do
Expand Down
8 changes: 3 additions & 5 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
it { should have_many(:users).through(:event_registrations) }

before(:each) do
@event1 = create(:event, start_date: Time.now,
end_date: Time.now + 1.day)
@event2 = create(:event, start_date: Time.now, end_date: Time.now)
@event3 = create(:event, start_date: Time.now + 1.day,
end_date: Time.now + 2.day)
@event1 = create(:event, :end_tomorrow)
@event2 = create(:event, :end_today)
@event3 = create(:event, :future)
end

describe "upcoming event scope" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/favorite_project_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require "spec_helper"

describe FavoriteProject do
it { should belong_to(:project) }
Expand Down
10 changes: 5 additions & 5 deletions spec/models/job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require 'spec_helper'
require "spec_helper"

describe Job do
it { should belong_to(:organization) }

before(:each) do
@organization = create(:organization)
@job1 = create(:job, organization_id: @organization.id, expires_at: DateTime.now + 1.day)
@job2 = create(:job, organization_id: @organization.id, expires_at: DateTime.now - 1.day)
@job1 = create(:job, :expire_tomorrow, organization_id: @organization.id)
@job2 = create(:job, :expired, organization_id: @organization.id)
@job3 = create(:job, organization_id: @organization.id)
end

describe 'active scope' do
it 'should return jobs which not expires or not had expires_at field' do
describe "active scope" do
it "should return jobs which not expires or not had expires_at field" do
expect(Job.active).to eq([@job1, @job3])
end
end
Expand Down

0 comments on commit a1aac53

Please sign in to comment.