remarkable_activerecord 3.1.9 → 3.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,102 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- RAILS_I18n = true
4
-
5
- class Post
6
- attr_accessor :published, :public, :deleted
7
-
8
- def attributes=(attributes={}, guard=true)
9
- attributes.each do |key, value|
10
- send(:"#{key}=", value) unless guard
11
- end
12
- end
13
-
14
- def self.human_name(*args)
15
- "MyPost"
16
- end
17
- end
18
-
19
- describe Post do
20
- it "should use human name on description" do
21
- self.class.description.should == "MyPost"
22
- end
23
-
24
- describe "default attributes as a hash" do
25
- subject_attributes :deleted => true
26
-
27
- it "should set the subject with deleted equals to true" do
28
- subject.deleted.should be_true
29
- end
30
-
31
- it "should not change the description" do
32
- self.class.description.should == "MyPost default attributes as a hash"
33
- end
34
- end
35
-
36
- describe "default attributes as a proc" do
37
- subject_attributes { my_attributes }
38
-
39
- it "should set the subject with deleted equals to true" do
40
- subject.deleted.should be_true
41
- end
42
-
43
- it "should not change the description" do
44
- self.class.description.should == "MyPost default attributes as a proc"
45
- end
46
-
47
- def my_attributes
48
- { :deleted => true }
49
- end
50
- end
51
-
52
- describe :published => true do
53
- it "should set the subject with published equals to true" do
54
- subject.published.should be_true
55
- end
56
-
57
- it "should generate a readable description" do
58
- self.class.description.should == "MyPost when published is true"
59
- end
60
-
61
- it "should call human name attribute on the described class" do
62
- Post.should_receive(:human_attribute_name).with("comments_count", :locale => :en).and_return("__COMMENTS__COUNT__")
63
- self.class.describe(:comments_count => 5) do
64
- self.description.should == 'MyPost when published is true and __comments__count__ is 5'
65
- end
66
- end
67
-
68
- describe :public => false do
69
- it "should nest subject attributes" do
70
- subject.published.should be_true
71
- subject.public.should be_false
72
- end
73
-
74
- it "should nest descriptions" do
75
- self.class.description.should == "MyPost when published is true and public is false"
76
- end
77
-
78
- describe "default attributes as a hash" do
79
- subject_attributes :deleted => true
80
-
81
- it "should merge describe attributes with subject attributes" do
82
- subject.published.should be_true
83
- subject.public.should be_false
84
- subject.deleted.should be_true
85
- end
86
- end
87
- end
88
- end
89
-
90
- describe :published => true, :public => false do
91
- it "should set the subject with published equals to true and public equals to false" do
92
- subject.published.should be_true
93
- subject.public.should be_false
94
- end
95
-
96
- it "should include both published and public in descriptions" do
97
- self.class.description.should match(/MyPost/)
98
- self.class.description.should match(/public is false/)
99
- self.class.description.should match(/published is true/)
100
- end
101
- end
102
- end
@@ -1,78 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe 'have_column_matcher' do
4
- include ModelBuilder
5
-
6
- before(:each) do
7
- @model = define_model :product, :table => lambda {|table|
8
- table.string :name, :null => true
9
- table.string :email, :limit => '255', :default => 'jose.valim@gmail.com'
10
- table.decimal :price, :precision => 10, :scale => 2
11
- }
12
- end
13
-
14
- describe 'messages' do
15
-
16
- it 'should contain a description' do
17
- @matcher = have_column(:name, :email)
18
- @matcher.description.should == 'have column(s) named name and email'
19
-
20
- @matcher.type(:string)
21
- @matcher.description.should == 'have column(s) named name and email with type :string'
22
- end
23
-
24
- it 'should set column_exists? message' do
25
- @matcher = have_column(:password)
26
- @matcher.matches?(@model)
27
- @matcher.failure_message.should == 'Expected Product to have column named password'
28
- end
29
-
30
- it 'should set options_match? message' do
31
- @matcher = have_column(:name, :type => :integer)
32
- @matcher.matches?(@model)
33
- @matcher.failure_message.should == 'Expected Product to have column name with options {:type=>"integer"}, got {:type=>"string"}'
34
- end
35
- end
36
-
37
- describe 'matchers' do
38
- it { should have_column(:name) }
39
- it { should have_columns(:name, :email) }
40
- it { should have_columns(:name, :email, :price) }
41
-
42
- it { should have_column(:name).null }
43
- it { should have_column(:email).limit(255) }
44
- it { should have_column(:email).default('jose.valim@gmail.com') }
45
- it { should have_column(:price).precision(10) }
46
- it { should have_column(:price).precision(10).scale(2) }
47
-
48
- it { should_not have_column(:name).null(false) }
49
- it { should_not have_column(:email).limit(400) }
50
- it { should_not have_column(:email).default('') }
51
- it { should_not have_column(:price).precision(1) }
52
- it { should_not have_column(:price).precision(10).scale(5) }
53
- end
54
-
55
- describe 'macros' do
56
- should_have_column :name
57
- should_have_columns :name, :email
58
- should_have_columns :name, :email, :price
59
-
60
- should_have_column :name, :null => true
61
- should_have_column :email, :limit => 255
62
- should_have_column :email, :default => 'jose.valim@gmail.com'
63
- should_have_column :price, :precision => 10
64
- should_have_column :price, :precision => 10, :scale => 2
65
-
66
- should_have_column :price do |m|
67
- m.scale = 2
68
- m.precision = 10
69
- end
70
-
71
- should_not_have_column :name, :null => false
72
- should_not_have_column :email, :limit => 400
73
- should_not_have_column :email, :default => ''
74
- should_not_have_column :price, :precision => 1
75
- should_not_have_column :price, :precision => 10, :scale => 5
76
- end
77
- end
78
-
@@ -1,52 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- if RAILS_VERSION == '2.3.3'
4
- describe 'have_default_scope' do
5
- include ModelBuilder
6
-
7
- before(:each) do
8
- @model = define_model :product, :published => :boolean do
9
- default_scope :order => 'created_at DESC'
10
- default_scope :conditions => { :published => true }
11
- end
12
- end
13
-
14
- describe 'messages' do
15
-
16
- it 'should contain a description' do
17
- matcher = have_default_scope(:conditions => {:special => true})
18
- matcher.description.should == 'have a default scope with {:conditions=>{:special=>true}}'
19
- end
20
-
21
- it 'should set options_match? message' do
22
- matcher = have_default_scope(:conditions => {:special => true})
23
- matcher.matches?(@model)
24
- matcher.failure_message.should == 'Expected default scope with {:conditions=>{:special=>true}}, got [{:order=>"created_at DESC"}, {:conditions=>{:published=>true}}]'
25
- end
26
-
27
- end
28
-
29
- describe 'matchers' do
30
- it { should have_default_scope(:order => 'created_at DESC') }
31
- it { should have_default_scope(:conditions => { :published => true }) }
32
-
33
- it { should_not have_default_scope(:order => 'created_at ASC') }
34
- it { should_not have_default_scope(:conditions => { :published => false }) }
35
- it { should_not have_default_scope(:conditions => { :published => true }, :order => 'created_at DESC') }
36
-
37
- describe 'when the model has no default scope' do
38
- before(:each){ @model = define_model(:task) }
39
- it { @model.should_not have_default_scope }
40
- end
41
- end
42
-
43
- describe 'macros' do
44
- should_have_default_scope :order => 'created_at DESC'
45
- should_have_default_scope :conditions => { :published => true }
46
-
47
- should_not_have_default_scope :order => 'created_at ASC'
48
- should_not_have_default_scope :conditions => { :published => false }
49
- should_not_have_default_scope :conditions => { :published => true }, :order => 'created_at DESC'
50
- end
51
- end
52
- end
@@ -1,87 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe 'have_index_matcher' do
4
- include ModelBuilder
5
-
6
- before(:each) do
7
- @model = define_model :users, :table => lambda {|table|
8
- table.string :name, :null => true
9
- table.string :email, :limit => '255', :default => 'jose.valim@gmail.com'
10
- }
11
-
12
- create_table "users_watchers" do |t|
13
- t.integer :user_id
14
- t.integer :watcher_id
15
- end
16
-
17
- ActiveRecord::Base.connection.add_index :users, :name
18
- ActiveRecord::Base.connection.add_index :users, :email, :unique => true
19
- ActiveRecord::Base.connection.add_index :users, [:email, :name], :unique => true
20
- ActiveRecord::Base.connection.add_index :users_watchers, :user_id
21
- end
22
-
23
- describe 'messages' do
24
- it 'should contain a description' do
25
- @matcher = have_index(:name)
26
- @matcher.description.should == 'have index for column(s) name'
27
-
28
- @matcher.unique
29
- @matcher.description.should == 'have index for column(s) name with unique values'
30
-
31
- @matcher.table_name("another")
32
- @matcher.description.should == 'have index for column(s) name on table another and with unique values'
33
- end
34
-
35
- it 'should set index_exists? message' do
36
- @matcher = have_index(:password).table_name("special_users")
37
- @matcher.matches?(@model)
38
- @matcher.failure_message.should == 'Expected index password to exist on table special_users'
39
- end
40
-
41
- it 'should set is_unique? message' do
42
- @matcher = have_index(:email, :unique => false)
43
- @matcher.matches?(@model)
44
- @matcher.failure_message.should == 'Expected index on email with unique equals to false, got true'
45
- end
46
- end
47
-
48
- describe 'matchers' do
49
- it { should have_index(:name) }
50
- it { should have_index(:email) }
51
- it { should have_index([:email, :name]) }
52
- it { should have_index(:name, :email) }
53
-
54
- it { should have_index(:name).unique(false) }
55
- it { should have_index(:email).unique }
56
- it { should have_index(:user_id).table_name(:users_watchers) }
57
-
58
- it { should_not have_index(:password) }
59
- it { should_not have_index(:name).unique(true) }
60
- it { should_not have_index(:email).unique(false) }
61
- it { should_not have_index(:watcher_id).table_name(:users_watchers) }
62
- end
63
-
64
- describe 'macros' do
65
- should_have_index :name
66
- should_have_index :email
67
- should_have_index [:email, :name]
68
- should_have_index :name, :email
69
-
70
- should_have_index :name, :unique => false
71
- should_have_index :email, :unique => true
72
- should_have_index :user_id, :table_name => :users_watchers
73
-
74
- should_not_have_index :password
75
- should_not_have_index :name, :unique => true
76
- should_not_have_index :email, :unique => false
77
- should_not_have_index :watcher_id, :table_name => :users_watchers
78
- end
79
-
80
- describe "aliases" do
81
- should_have_indices :name
82
- should_have_db_index :name
83
- should_have_db_indices :name
84
- end
85
-
86
- end
87
-
@@ -1,47 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe 'have_readonly_attributes' do
4
- include ModelBuilder
5
-
6
- def define_and_validate(options={})
7
- @model = define_model :product, :title => :string, :category => :string do
8
- attr_readonly :title, :category if options[:readonly] == true
9
- attr_readonly *options[:readonly] if options[:readonly].is_a?(Array)
10
- end
11
-
12
- have_readonly_attributes(:title, :category)
13
- end
14
-
15
- describe 'messages' do
16
-
17
- it 'should contain a description' do
18
- @matcher = have_readonly_attributes(:title, :category)
19
- @matcher.description.should == 'make title and category read-only'
20
- end
21
-
22
- it 'should set is_readonly? message' do
23
- @matcher = define_and_validate(:readonly => [:another])
24
- @matcher.matches?(@model)
25
- @matcher.failure_message.should == 'Expected Product to make title read-only, got ["another"]'
26
- end
27
-
28
- end
29
-
30
- describe 'matchers' do
31
- it { should define_and_validate(:readonly => true) }
32
- it { should_not define_and_validate(:readonly => false) }
33
- it { should_not define_and_validate(:accessible => [:another]) }
34
- end
35
-
36
- describe 'macros' do
37
- before(:each){ define_and_validate(:readonly => true) }
38
-
39
- should_have_readonly_attributes :title
40
- should_have_readonly_attributes :category
41
- should_have_readonly_attributes :title, :category
42
-
43
- should_not_have_readonly_attributes :another
44
- should_not_have_readonly_attributes :title, :another
45
- end
46
- end
47
-
@@ -1,85 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe 'have_scope' do
4
- include ModelBuilder
5
-
6
- before(:each) do
7
- @model = define_model :product, :title => :string, :category => :string do
8
- named_scope :recent, :order => 'created_at DESC'
9
- named_scope :latest, lambda {|c| {:limit => c}}
10
- named_scope :since, lambda {|t| {:conditions => ['created_at > ?', t]}}
11
- named_scope :between, lambda { |a, b| { :conditions => [ 'created_at > ? and created_at < ?', a, b ] } }
12
-
13
- def self.beginning(c)
14
- scoped(:offset => c)
15
- end
16
-
17
- def self.null
18
- nil
19
- end
20
- end
21
- end
22
-
23
- describe 'messages' do
24
-
25
- it 'should contain a description' do
26
- matcher = have_scope(:title)
27
- matcher.description.should == 'have to scope itself to {} when :title is called'
28
-
29
- matcher.with(1)
30
- matcher.description.should == 'have to scope itself to {} when :title is called with [1] as argument'
31
- end
32
-
33
- it 'should set is_scope? message' do
34
- matcher = have_scope(:null)
35
- matcher.matches?(@model)
36
- matcher.failure_message.should == 'Expected :null when called on Product return an instance of ActiveRecord::NamedScope::Scope'
37
- end
38
-
39
- it 'should set options_match? message' do
40
- matcher = have_scope(:recent, :conditions => {:special => true})
41
- matcher.matches?(@model)
42
- matcher.failure_message.should == 'Expected :recent when called on Product scope to {:conditions=>{:special=>true}}, got {:order=>"created_at DESC"}'
43
- end
44
-
45
- end
46
-
47
- describe 'matchers' do
48
- it { should have_scope(:recent) }
49
- it { should have_scope(:recent, :order => 'created_at DESC') }
50
-
51
- it { should have_scope(:latest).with(10).limit(10) }
52
- it { should have_scope(:beginning).with(10).offset(10) }
53
- it { should have_scope(:since).with(false).conditions(["created_at > ?", false]) }
54
- it { should have_scope(:since).with(Time.at(0)).conditions(["created_at > ?", Time.at(0)]) }
55
- it { should have_scope(:between).with(2, 10).conditions(["created_at > ? and created_at < ?", 2, 10]) }
56
-
57
- it { should_not have_scope(:null) }
58
- it { should_not have_scope(:latest).with(5).limit(10) }
59
- it { should_not have_scope(:beginning).with(5).offset(10) }
60
- it { should_not have_scope(:since).with(Time.at(0)).conditions(["created_at > ?", Time.at(1)]) }
61
- it { should_not have_scope(:between).with(2, 10).conditions(["updated_at > ? and updated_at < ?", 2, 10]) }
62
- end
63
-
64
- describe 'macros' do
65
- should_have_scope :recent
66
- should_have_scope :recent, :order => 'created_at DESC'
67
-
68
- should_have_scope :latest, :with => 10, :limit => 10
69
- should_have_scope :beginning, :with => 10, :offset => 10
70
- should_have_scope :since, :with => false, :conditions => ["created_at > ?", false]
71
- should_have_scope :since, :with => Time.at(0), :conditions => ["created_at > ?", Time.at(0)]
72
- should_have_scope :between, :with => [ 2, 10 ], :conditions => [ "created_at > ? and created_at < ?", 2, 10 ]
73
-
74
- should_have_scope :between do |m|
75
- m.with(2, 10)
76
- m.conditions([ "created_at > ? and created_at < ?", 2, 10 ])
77
- end
78
-
79
- should_not_have_scope :null
80
- should_not_have_scope :latest, :with => 5, :limit => 10
81
- should_not_have_scope :beginning, :with => 5, :offset => 10
82
- should_not_have_scope :since, :with => Time.at(0), :conditions => ["created_at > ?", Time.at(1)]
83
- should_not_have_scope :between, :with => [ 2, 10 ], :conditions => [ "updated_at > ? and updated_at < ?", 2, 10 ]
84
- end
85
- end