Skip to content

Commit 8ea5419

Browse files
committed
Merge branch 'with_factory_girl'
2 parents 8f18c64 + af91f1b commit 8ea5419

11 files changed

+210
-1
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ group :test do
3535
gem 'cucumber', '~> 0.6.2', :require => false
3636
gem 'cucumber-rails', '~> 0.2.4', :require => false
3737
gem 'database_cleaner', '~> 0.4.3', :require => false
38+
gem 'factory_girl', '~> 1.2.4', :require => false
3839
gem 'rcov', '~> 0.9.7', :require => false
3940
gem 'rspec', '~> 1.3.0', :require => false
4041
gem 'rspec-rails', '~> 1.3.0', :require => false

spec/controllers/proposals_controller_spec.rb

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,111 @@ def assert_show(opts={}, &block)
534534
proposal = assigns(:proposal)
535535
proposal.presenter.should == user.fullname
536536
end
537+
538+
describe "when event has tracks" do
539+
describe "when there are no tracks" do
540+
it "should display new event form for admin user" do
541+
event = Factory(:event, :tracks => [])
542+
user = Factory(:admin)
543+
login_as(user)
544+
545+
get :new, :event_id => event.slug
546+
547+
flash[:failure].should =~ /no tracks/i
548+
response.should redirect_to(new_event_track_path(event))
549+
end
550+
551+
it "should display error for non-admin user" do
552+
event = Factory(:event, :tracks => [])
553+
user = Factory(:user)
554+
login_as(user)
555+
556+
get :new, :event_id => event.slug
557+
558+
flash[:failure].should =~ /no tracks/i
559+
response.should redirect_to(event_proposals_path(event))
560+
end
561+
end
562+
563+
it "should assign a track if there's only one" do
564+
event = Factory(:event, :tracks => [])
565+
track = Factory(:track, :event => event)
566+
user = Factory(:user)
567+
login_as(user)
568+
569+
get :new, :event_id => event.slug
570+
571+
flash[:failure].should be_nil
572+
assigns[:proposal].track.should == track
573+
end
574+
575+
it "should not assign a track if there's more than one" do
576+
event = Factory(:event, :tracks => [])
577+
track1 = Factory(:track, :event => event)
578+
track2 = Factory(:track, :event => event)
579+
user = Factory(:user)
580+
login_as(user)
581+
582+
get :new, :event_id => event.slug
583+
584+
flash[:failure].should be_nil
585+
assigns[:proposal].track.should be_nil
586+
end
587+
end
588+
589+
describe "when event has session types" do
590+
describe "when there are no session types" do
591+
it "should display new event form for admin user" do
592+
event = Factory(:event, :session_types => [])
593+
user = Factory(:admin)
594+
login_as(user)
595+
596+
get :new, :event_id => event.slug
597+
598+
response.should redirect_to(new_event_session_type_path(event))
599+
flash[:failure].should =~ /no session types/i
600+
end
601+
602+
it "should display error for non-admin user" do
603+
event = Factory(:event, :session_types => [])
604+
user = Factory(:user)
605+
login_as(user)
606+
607+
get :new, :event_id => event.slug
608+
609+
response.should redirect_to(event_proposals_path(event))
610+
flash[:failure].should =~ /no session types/i
611+
end
612+
end
613+
614+
it "should assign a session type if there's only one" do
615+
event = Factory(:event, :session_types => [])
616+
session_type = Factory(:session_type, :event => event)
617+
user = Factory(:user)
618+
login_as(user)
619+
620+
get :new, :event_id => event.slug
621+
622+
assigns[:proposal].session_type.should == session_type
623+
end
624+
625+
it "should not assign a session type if there's more than one" do
626+
event = Factory(:event, :session_types => [])
627+
session_type1 = Factory(:session_type, :event => event)
628+
session_type2 = Factory(:session_type, :event => event)
629+
user = Factory(:user)
630+
login_as(user)
631+
632+
get :new, :event_id => event.slug
633+
634+
assigns[:proposal].session_type.should be_nil
635+
end
636+
end
537637
end
638+
end
538639

539-
it "should not display form for closed events" do
640+
describe "with closed event" do
641+
it "should not display form" do
540642
login_as(users(:quentin))
541643
event = events(:closed)
542644
get :new, :event_id => event.slug

spec/factories/common_factory.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Factory.sequence(:email) { |n| "user#{n}@provider.com" }
2+
3+
Factory.sequence(:website) { |n| "http://provider.com/~user#{n}" }

spec/factories/event_factory.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Factory.define :event do |f|
2+
f.sequence(:title) { |n| "Event #{n}" }
3+
f.deadline { Date.today.to_time + 1.day }
4+
f.open_text "We're accepting proposals"
5+
f.closed_text "We're not accepting proposals"
6+
f.proposal_status_published false
7+
f.session_text "We have sessions"
8+
f.tracks_text "We have tracks"
9+
f.start_date { Date.today.to_time + 2.days }
10+
f.end_date { Date.today.to_time + 3.days }
11+
f.accept_proposal_comments_after_deadline false
12+
f.slug { |record| record.title.downcase.gsub(/[^\w]/, '') }
13+
f.schedule_published false
14+
f.parent_id nil
15+
f.proposal_titles_locked false
16+
17+
# :has_many associations
18+
f.tracks { |record| [record.association(:track, :event => record.result)] }
19+
f.rooms { |record| [record.association(:room, :event => record.result)] }
20+
f.session_types { |record| [record.association(:session_type, :event => record.result)] }
21+
end

spec/factories/proposal_factory.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# NOTE: A proposal's relationship to it's user profile information is
2+
# configurable. If `SETTINGS.have_user_profiles` is false, then the proposal
3+
# contains the user profile information (e.g., presenter's name). However,
4+
# if false, the proposal has many users that each have their own profile as
5+
# part of their user record.
6+
Factory.define :proposal do |f|
7+
f.user_id nil
8+
f.presenter "Presenter name"
9+
f.affiliation "My affiliation"
10+
f.email { Factory.next(:email) }
11+
f.website { Factory.next(:website) }
12+
f.biography "My biography"
13+
f.sequence(:title) { |n| "Proposal #{n}" }
14+
f.description "My proposal description"
15+
f.agreement true
16+
f.note_to_organizers "My note to organizers"
17+
f.excerpt "My excerpt"
18+
f.status "proposed"
19+
f.start_time nil
20+
21+
# :belongs_to associations
22+
f.association :event
23+
f.association :track
24+
f.association :session_type
25+
f.association :room
26+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Factory.define :proposal_user do |f|
2+
# :belongs_to associations
3+
f.association :proposal
4+
f.association :user
5+
end

spec/factories/room_factory.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Factory.define :room do |f|
2+
f.name { |n| "Room #{n}" }
3+
f.capacity 40
4+
f.size "12 x 20 feet"
5+
f.seating_configuration "Theater"
6+
7+
# :belongs_to association
8+
f.association :event
9+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Factory.define :session_type do |f|
2+
f.sequence(:title) { |n| "Session Type #{n}" }
3+
f.description { |record| "#{record.title} description" }
4+
f.duration "45"
5+
6+
# :belongs_to association
7+
f.association :event
8+
end

spec/factories/track_factory.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Factory.define :track do |f|
2+
f.sequence(:title) { |n| "Track #{n}" }
3+
f.description { |record| "#{record.title} description" }
4+
f.color "#000000"
5+
f.excerpt "A track"
6+
7+
# :belongs_to association
8+
f.association :event
9+
end

spec/factories/user_factory.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Factory.define :user do |f|
2+
f.sequence(:login) { |n| "user#{n}" }
3+
f.email { Factory.next(:email) }
4+
f.admin false
5+
f.remember_token nil
6+
f.remember_token_expires_at nil
7+
f.using_openid true
8+
f.affiliation "My affiliation"
9+
f.biography "My biography"
10+
f.website { Factory.next(:website) }
11+
f.complete_profile true
12+
f.sequence(:first_name) { |n| "user_first_name-#{n}" }
13+
f.sequence(:last_name) { |n| "user_last_name-#{n}" }
14+
f.blog_url { Factory.next(:website) }
15+
f.identica { |record| record.fullname.gsub(/[^\w]/, '_').downcase }
16+
f.twitter { |record| record.fullname.gsub(/[^\w]/, '_').downcase }
17+
end
18+
19+
Factory.define :admin, :parent => :user do |f|
20+
f.admin true
21+
end

0 commit comments

Comments
 (0)