diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-09-05 17:33:07 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-09-05 17:33:07 +0100 |
commit | 1336bf24bbca504e45480ea1b53eb1efca0f8e40 (patch) | |
tree | 711947663611485a8445ec81e8bffdfa76712f81 /spec/models | |
parent | bc29ea1129cba545a2bbc5ed7dc0eed257d454ef (diff) | |
parent | c5c815d6450b4ecd4be004ae20fb0ecb1b62fa0d (diff) |
Merge branch 'body-stats-prerelease' into rails-3-develop
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/info_request_spec.rb | 7 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 46 |
2 files changed, 37 insertions, 16 deletions
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 3f2e02189..ab36a201c 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -896,8 +896,9 @@ describe InfoRequest do describe 'when changing a described_state' do - it "should change the counts on its PublicBody" do + it "should change the counts on its PublicBody without saving a new version" do pb = public_bodies(:geraldine_public_body) + old_version_count = pb.versions.count old_successful_count = pb.info_requests_successful_count old_not_held_count = pb.info_requests_not_held_count ir = InfoRequest.new(:external_url => 'http://www.example.com', @@ -909,15 +910,19 @@ describe InfoRequest do pb.info_requests_successful_count.should == (old_successful_count + 1) ir.described_state = 'not_held' ir.save! + pb.reload pb.info_requests_successful_count.should == old_successful_count pb.info_requests_not_held_count.should == (old_not_held_count + 1) ir.described_state = 'successful' ir.save! + pb.reload pb.info_requests_successful_count.should == (old_successful_count + 1) pb.info_requests_not_held_count.should == old_not_held_count ir.destroy + pb.reload pb.info_requests_successful_count.should == old_successful_count pb.info_requests_successful_count.should == old_not_held_count + pb.versions.count.should == old_version_count end end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 90affaaaa..3578c0e9c 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -136,36 +136,32 @@ describe PublicBody, " when saving" do @public_body = PublicBody.new end + def set_default_attributes(public_body) + public_body.name = "Testing Public Body" + public_body.short_name = "TPB" + public_body.request_email = "request@localhost" + public_body.last_edit_editor = "*test*" + public_body.last_edit_comment = "This is a test" + end + it "should not be valid without setting some parameters" do @public_body.should_not be_valid end it "should not be valid with misformatted request email" do - @public_body.name = "Testing Public Body" - @public_body.short_name = "TPB" + set_default_attributes(@public_body) @public_body.request_email = "requestBOOlocalhost" - @public_body.last_edit_editor = "*test*" - @public_body.last_edit_comment = "This is a test" @public_body.should_not be_valid @public_body.should have(1).errors_on(:request_email) end it "should save" do - @public_body.name = "Testing Public Body" - @public_body.short_name = "TPB" - @public_body.request_email = "request@localhost" - @public_body.last_edit_editor = "*test*" - @public_body.last_edit_comment = "This is a test" + set_default_attributes(@public_body) @public_body.save! end it "should update first_letter" do - @public_body.name = "Testing Public Body" - @public_body.short_name = "TPB" - @public_body.request_email = "request@localhost" - @public_body.last_edit_editor = "*test*" - @public_body.last_edit_comment = "This is a test" - + set_default_attributes(@public_body) @public_body.first_letter.should be_nil @public_body.save! @public_body.first_letter.should == 'T' @@ -178,6 +174,26 @@ describe PublicBody, " when saving" do public_body.name.should == "Mark's Public Body" end + + it 'should not create a new version when nothing has changed' do + @public_body.versions.size.should == 0 + set_default_attributes(@public_body) + @public_body.save! + @public_body.versions.size.should == 1 + @public_body.save! + @public_body.versions.size.should == 1 + end + + it 'should create a new version if something has changed' do + @public_body.versions.size.should == 0 + set_default_attributes(@public_body) + @public_body.save! + @public_body.versions.size.should == 1 + @public_body.name = 'Test' + @public_body.save! + @public_body.versions.size.should == 2 + end + end describe PublicBody, "when searching" do |