Skip to content
Browse files

Integration tests for events.

  • Loading branch information...
1 parent 9de92cc commit cbada934ae006d1b38309d5e89d22ec3226ef8ab @Loremaster committed May 8, 2012
Showing with 109 additions and 10 deletions.
  1. +109 −10 spec/requests/class_heads_spec.rb
View
119 spec/requests/class_heads_spec.rb
@@ -51,19 +51,118 @@
click_button "Войти"
end
- it "should have correct links in toolbar with active states" do
- # State of button when user log-in
- response.should be_success
- response.body.should have_selector( "li.active") do
- have_selector('a', :content => 'Мероприятия')
- end
+ describe "Toolbar" do
+ it "should have correct links in toolbar with active states" do
+ # State of button when user log-in
+ response.should be_success
+ response.body.should have_selector( "li.active") do
+ have_selector('a', :content => 'Мероприятия')
+ end
- click_link "Мероприятия"
+ click_link "Мероприятия"
- response.should be_success
- response.body.should have_selector( "li.active") do
- have_selector('a', :content => 'Мероприятия')
+ response.should be_success
+ response.body.should have_selector( "li.active") do
+ have_selector('a', :content => 'Мероприятия')
+ end
+ end
+ end
+
+ describe "Event" do
+ describe "Creating" do
+ describe "View" do
+ before(:each) do
+ click_link "Мероприятия"
+ click_link "Создать"
+ end
+
+ it "should have placeholders" do
+ inputs_text = [ "event[event_begin_date]", "event[event_end_date]",
+ "event[event_cost]" ]
+ inputs_textarea = [ "event[event_place]", "event[event_place_of_start]" ]
+
+ inputs_text.each do |inp|
+ response.should have_selector( 'input',
+ :name => inp,
+ :placeholder => @everpresent_field_placeholder )
+ end
+
+ inputs_textarea.each do |inp|
+ response.should have_selector( 'textarea',
+ :name => inp,
+ :placeholder => @everpresent_field_placeholder )
+ end
+ end
+ end
+
+ describe "Create" do
+ before(:each) do
+ teacher = FactoryGirl.create( :teacher )
+ click_link "Мероприятия"
+ click_link "Создать"
+ end
+
+ it "should save event with correct params" do
+ expect do
+ fill_in "Место проведения мероприятия", :with => "USA"
+ fill_in "Место сбора на мероприятие", :with => "Moscow"
+ fill_in "Дата начала мероприятия",
+ :with => "#{Date.today.strftime("%d.%m.%Y")}"
+ fill_in "Дата окончания мероприятия",
+ :with => "#{Date.today.strftime("%d.%m.%Y")}"
+ fill_in "Стоимость мероприятия", :with => 0
+
+ click_button "Создать"
+ end.should change( Event, :count ).by( 1 )
+ end
+
+ it "should not save event with invalid params" do
+ expect do
+ fill_in "Место проведения мероприятия", :with => ""
+ fill_in "Место сбора на мероприятие", :with => ""
+ fill_in "Дата начала мероприятия",:with => ""
+ fill_in "Дата окончания мероприятия", :with => ""
+ fill_in "Стоимость мероприятия", :with => -1
+
+ click_button "Создать"
+ end.should_not change( Event, :count )
+ end
+ end
+
+ describe "Update" do
+ before(:each) do
+ @event = FactoryGirl.create( :event )
+ visit edit_event_path( :id => @event )
+ end
+
+ it "should update event with valid params" do
+ fill_in "Место проведения мероприятия", :with => "USA"
+ fill_in "Место сбора на мероприятие", :with => "Moscow"
+ fill_in "Дата начала мероприятия",
+ :with => "#{Date.today.strftime("%d.%m.%Y")}"
+ fill_in "Дата окончания мероприятия",
+ :with => "#{Date.today.strftime("%d.%m.%Y")}"
+ fill_in "Стоимость мероприятия", :with => 0
+
+ click_button "Обновить"
+
+ flash[:success].should =~ /Мероприятие успешно обновлено!/i
+ end
+
+ it "should not update event with invalid params" do
+ fill_in "Место проведения мероприятия", :with => ""
+ fill_in "Место сбора на мероприятие", :with => ""
+ fill_in "Дата начала мероприятия",:with => ""
+ fill_in "Дата окончания мероприятия", :with => ""
+ fill_in "Стоимость мероприятия", :with => -1
+
+ click_button "Обновить"
+
+ flash[:error].should_not be_nil
+ end
+ end
end
end
end
+
end

0 comments on commit cbada93

Please sign in to comment.
Something went wrong with that request. Please try again.