/
article_spec.rb
45 lines (36 loc) · 1.73 KB
/
article_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require File.dirname(File.expand_path(__FILE__)) + '/test_helper'
describe Article do
it { should normalize_attribute(:title).from(' Social Life at the Edge of Chaos ').to('Social Life at the Edge of Chaos') }
it { should normalize_attribute(:authors).from(' Octavio Miramontes and Pedro Miramontes ').to('Octavio Miramontes and Pedro Miramontes') }
context 'normalization should not interfere with other hooks and aliases on the attribute assignment' do
before do
@article = Article.create!(:title => 'Original Title')
end
it 'should still reflect that the attribute has been changed through the call to super' do
lambda { @article.title = 'New Title' }.should change(@article, :title_changed?).from(false).to(true)
end
end
context 'when another instance of the same saved record has been changed' do
before do
@article = Article.create!(:title => 'Original Title')
@article2 = Article.find(@article.id)
@article2.update_attributes(:title => 'New Title')
end
it "should reflect the change when the record is reloaded" do
lambda { @article.reload }.should change(@article, :title).from('Original Title').to('New Title')
end
end
context 'normalization should work with multiple attributes at the same time' do
before do
@article = Article.new(:title => ' Bad Title ', :authors => ' Bad Authors ')
end
it "should apply normalizations to both attributes" do
@article.title.should == 'Bad Title'
@article.authors.should == 'Bad Authors'
end
end
context 'with the default normalizer changed' do
@article = Article.new :authors => 'testing the default normalizer'
@article.authors.should == 'testing the default normalizer'
end
end