remarkable_activerecord 3.1.8 → 3.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +140 -138
- data/LICENSE +20 -20
- data/README +80 -80
- data/lib/remarkable_activerecord.rb +29 -29
- data/lib/remarkable_activerecord/base.rb +248 -237
- data/lib/remarkable_activerecord/describe.rb +27 -27
- data/lib/remarkable_activerecord/human_names.rb +36 -36
- data/lib/remarkable_activerecord/matchers/accept_nested_attributes_for_matcher.rb +30 -30
- data/lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb +59 -59
- data/lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb +85 -94
- data/lib/remarkable_activerecord/matchers/association_matcher.rb +283 -283
- data/lib/remarkable_activerecord/matchers/have_column_matcher.rb +68 -68
- data/lib/remarkable_activerecord/matchers/have_default_scope_matcher.rb +38 -38
- data/lib/remarkable_activerecord/matchers/have_index_matcher.rb +73 -73
- data/lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb +30 -30
- data/lib/remarkable_activerecord/matchers/have_scope_matcher.rb +85 -85
- data/lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb +50 -50
- data/lib/remarkable_activerecord/matchers/validate_associated_matcher.rb +97 -97
- data/lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb +44 -44
- data/lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb +53 -53
- data/lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb +52 -52
- data/lib/remarkable_activerecord/matchers/validate_length_of_matcher.rb +150 -150
- data/lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb +181 -181
- data/lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb +29 -29
- data/lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb +233 -233
- data/locale/en.yml +261 -261
- data/spec/accept_nested_attributes_for_matcher_spec.rb +1 -1
- data/spec/allow_mass_assignment_of_matcher_spec.rb +90 -82
- data/spec/allow_values_for_matcher_spec.rb +72 -63
- data/spec/association_matcher_spec.rb +612 -612
- data/spec/describe_spec.rb +3 -3
- data/spec/have_column_matcher_spec.rb +73 -73
- data/spec/have_default_scope_matcher_spec.rb +1 -1
- data/spec/have_index_matcher_spec.rb +87 -87
- data/spec/have_readonly_attributes_matcher_spec.rb +47 -47
- data/spec/have_scope_matcher_spec.rb +77 -77
- data/spec/model_builder.rb +101 -101
- data/spec/rcov.opts +1 -1
- data/spec/spec.opts +4 -4
- data/spec/spec_helper.rb +27 -27
- data/spec/validate_acceptance_of_matcher_spec.rb +68 -68
- data/spec/validate_associated_matcher_spec.rb +121 -121
- data/spec/validate_confirmation_of_matcher_spec.rb +58 -58
- data/spec/validate_length_of_matcher_spec.rb +218 -218
- data/spec/validate_numericality_of_matcher_spec.rb +179 -179
- data/spec/validate_presence_of_matcher_spec.rb +56 -56
- data/spec/validate_uniqueness_of_matcher_spec.rb +164 -164
- metadata +5 -5
data/spec/describe_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
RAILS_I18n = true
|
4
4
|
|
@@ -15,7 +15,7 @@ class Post
|
|
15
15
|
"MyPost"
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
describe Post do
|
20
20
|
it "should use human name on description" do
|
21
21
|
self.class.description.should == "MyPost"
|
@@ -99,4 +99,4 @@ describe Post do
|
|
99
99
|
self.class.description.should match(/published is true/)
|
100
100
|
end
|
101
101
|
end
|
102
|
-
end
|
102
|
+
end
|
@@ -1,78 +1,78 @@
|
|
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
|
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
64
|
should_have_column :price, :precision => 10, :scale => 2
|
65
65
|
|
66
66
|
should_have_column :price do |m|
|
67
67
|
m.scale = 2
|
68
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
|
-
|
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,87 +1,87 @@
|
|
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
|
+
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 +1,47 @@
|
|
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
|
+
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
|
+
|