diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-09-05 15:39:19 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-09-05 15:40:35 +0100 |
commit | 2f1cca7df58c93ef7844831af892a716b9b17f48 (patch) | |
tree | 2c5fa964a729a38fb338f3105adf6d6ec3f6a97e /spec/models | |
parent | 6518bfde0d974092777522c8dd883fd498b2972c (diff) |
Don't dirty every attribute in checking for whitespace.
Check to see if the stripped version is different before setting it on
the record. If we don't do this, the subsequent call to write_attribute
in Globalize3 which uses attribute_will_change! means we're storing
versions when there hasn't really been any change.
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/public_body_spec.rb | 46 |
1 files changed, 31 insertions, 15 deletions
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 |