Sha256: f68d0307fe2230800ca0a66ffcada5c1f0a7b39a7c26d98291a02ba4a0536a93
Contents?: true
Size: 1.87 KB
Versions: 4
Compression:
Stored size: 1.87 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe SurveySection, "when saving a survey_section" do before(:each) do @valid_attributes={:title => "foo", :survey_id => 2, :display_order => 4} @survey_section = SurveySection.new(@valid_attributes) end it "should be invalid without title" do @survey_section.title = nil @survey_section.should have(1).error_on(:title) end it "should have a parent survey" do # this causes issues with building and saving # @survey_section.survey_id = nil # @survey_section.should have(1).error_on(:survey) end it "should protect timestamps" do saved_attrs = @survey_section.attributes if defined? ActiveModel::MassAssignmentSecurity::Error lambda {@survey_section.update_attributes(:created_at => 3.days.ago, :updated_at => 3.hours.ago)}.should raise_error(ActiveModel::MassAssignmentSecurity::Error) else @survey_section.attributes = {:created_at => 3.days.ago, :updated_at => 3.hours.ago} # automatically protected by Rails end @survey_section.attributes.should == saved_attrs end end describe SurveySection, "with questions" do before(:each) do @survey_section = Factory(:survey_section, :title => "Rhymes", :display_order => 4) @q1 = @survey_section.questions.create(:text => "Peep", :display_order => 3) @q2 = @survey_section.questions.create(:text => "Little", :display_order => 1) @q3 = @survey_section.questions.create(:text => "Bo", :display_order => 2) end it "should return questions sorted in display order" do @survey_section.questions.should have(3).questions @survey_section.questions.should == [@q2,@q3,@q1] end it "should delete questions when it is deleted" do question_ids = @survey_section.questions.map(&:id) @survey_section.destroy question_ids.each{|id| Question.find_by_id(id).should be_nil} end end
Version data entries
4 entries across 4 versions & 1 rubygems