remarkable_activerecord 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. data/CHANGELOG +46 -46
  2. data/LICENSE +1 -1
  3. data/README +64 -64
  4. data/lib/remarkable_activerecord.rb +1 -1
  5. data/lib/remarkable_activerecord/base.rb +40 -40
  6. data/lib/remarkable_activerecord/human_names.rb +24 -24
  7. data/lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb +14 -14
  8. data/lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb +70 -70
  9. data/lib/remarkable_activerecord/matchers/association_matcher.rb +197 -197
  10. data/lib/remarkable_activerecord/matchers/have_column_matcher.rb +29 -29
  11. data/lib/remarkable_activerecord/matchers/have_index_matcher.rb +20 -20
  12. data/lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb +7 -7
  13. data/lib/remarkable_activerecord/matchers/have_scope_matcher.rb +34 -34
  14. data/lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb +37 -37
  15. data/lib/remarkable_activerecord/matchers/validate_associated_matcher.rb +75 -75
  16. data/lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb +44 -44
  17. data/lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb +17 -17
  18. data/lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb +20 -20
  19. data/lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb +14 -14
  20. data/lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb +80 -61
  21. data/locale/en.yml +253 -253
  22. data/spec/allow_mass_assignment_of_matcher_spec.rb +50 -50
  23. data/spec/allow_values_for_matcher_spec.rb +45 -45
  24. data/spec/association_matcher_spec.rb +612 -612
  25. data/spec/have_column_matcher_spec.rb +67 -67
  26. data/spec/have_index_matcher_spec.rb +61 -61
  27. data/spec/have_readonly_attributes_matcher_spec.rb +40 -40
  28. data/spec/have_scope_matcher_spec.rb +60 -60
  29. data/spec/model_builder.rb +101 -101
  30. data/spec/spec_helper.rb +25 -25
  31. data/spec/validate_acceptance_of_matcher_spec.rb +64 -64
  32. data/spec/validate_associated_matcher_spec.rb +118 -118
  33. data/spec/validate_confirmation_of_matcher_spec.rb +54 -54
  34. data/spec/validate_exclusion_of_matcher_spec.rb +76 -76
  35. data/spec/validate_inclusion_of_matcher_spec.rb +72 -72
  36. data/spec/validate_numericality_of_matcher_spec.rb +100 -100
  37. data/spec/validate_presence_of_matcher_spec.rb +40 -40
  38. data/spec/validate_uniqueness_of_matcher_spec.rb +158 -139
  39. metadata +3 -3
@@ -1,73 +1,73 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe 'have_column_matcher' do
3
+ describe 'have_column_matcher' do
4
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'
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"}'
22
34
  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_not_have_column :name, :null => false
67
- should_not_have_column :email, :limit => 400
68
- should_not_have_column :email, :default => ''
69
- should_not_have_column :price, :precision => 1
70
- should_not_have_column :price, :precision => 10, :scale => 5
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_not_have_column :name, :null => false
67
+ should_not_have_column :email, :limit => 400
68
+ should_not_have_column :email, :default => ''
69
+ should_not_have_column :price, :precision => 1
70
+ should_not_have_column :price, :precision => 10, :scale => 5
71
71
  end
72
72
  end
73
-
73
+
@@ -1,68 +1,68 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe 'have_index_matcher' do
3
+ describe 'have_index_matcher' do
4
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
- ActiveRecord::Base.connection.add_index :users, :name
13
- ActiveRecord::Base.connection.add_index :users, :email, :unique => true
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
+ ActiveRecord::Base.connection.add_index :users, :name
13
+ ActiveRecord::Base.connection.add_index :users, :email, :unique => true
14
14
  ActiveRecord::Base.connection.add_index :users, [:email, :name], :unique => true
15
- end
16
-
17
- describe 'messages' do
18
-
19
- it 'should contain a description' do
20
- @matcher = have_index(:name)
21
- @matcher.description.should == 'have index for column(s) name'
22
-
23
- @matcher.unique
24
- @matcher.description.should == 'have index for column(s) name with unique values'
15
+ end
16
+
17
+ describe 'messages' do
18
+
19
+ it 'should contain a description' do
20
+ @matcher = have_index(:name)
21
+ @matcher.description.should == 'have index for column(s) name'
22
+
23
+ @matcher.unique
24
+ @matcher.description.should == 'have index for column(s) name with unique values'
25
+ end
26
+
27
+ it 'should set index_exists? message' do
28
+ @matcher = have_index(:password)
29
+ @matcher.matches?(@model)
30
+ @matcher.failure_message.should == 'Expected index password to exist on table users'
31
+ end
32
+
33
+ it 'should set is_unique? message' do
34
+ @matcher = have_index(:email, :unique => false)
35
+ @matcher.matches?(@model)
36
+ @matcher.failure_message.should == 'Expected index on email with unique equals to false, got true'
25
37
  end
26
-
27
- it 'should set index_exists? message' do
28
- @matcher = have_index(:password)
29
- @matcher.matches?(@model)
30
- @matcher.failure_message.should == 'Expected index password to exist on table users'
31
- end
32
-
33
- it 'should set is_unique? message' do
34
- @matcher = have_index(:email, :unique => false)
35
- @matcher.matches?(@model)
36
- @matcher.failure_message.should == 'Expected index on email with unique equals to false, got true'
37
- end
38
- end
39
-
40
- describe 'matchers' do
41
- it { should have_index(:name) }
42
- it { should have_index(:email) }
43
- it { should have_index([:email, :name]) }
44
- it { should have_indices(:name, :email) }
45
-
46
- it { should have_index(:name).unique(false) }
47
- it { should have_index(:email).unique }
48
-
49
- it { should_not have_index(:password) }
50
- it { should_not have_index(:name).unique(true) }
51
- it { should_not have_index(:email).unique(false) }
52
- end
53
-
54
- describe 'macros' do
55
- should_have_index :name
56
- should_have_index :email
57
- should_have_index [:email, :name]
58
- should_have_indices :name, :email
59
-
60
- should_have_index :name, :unique => false
61
- should_have_index :email, :unique => true
62
-
63
- should_not_have_index :password
64
- should_not_have_index :name, :unique => true
65
- should_not_have_index :email, :unique => false
38
+ end
39
+
40
+ describe 'matchers' do
41
+ it { should have_index(:name) }
42
+ it { should have_index(:email) }
43
+ it { should have_index([:email, :name]) }
44
+ it { should have_indices(:name, :email) }
45
+
46
+ it { should have_index(:name).unique(false) }
47
+ it { should have_index(:email).unique }
48
+
49
+ it { should_not have_index(:password) }
50
+ it { should_not have_index(:name).unique(true) }
51
+ it { should_not have_index(:email).unique(false) }
52
+ end
53
+
54
+ describe 'macros' do
55
+ should_have_index :name
56
+ should_have_index :email
57
+ should_have_index [:email, :name]
58
+ should_have_indices :name, :email
59
+
60
+ should_have_index :name, :unique => false
61
+ should_have_index :email, :unique => true
62
+
63
+ should_not_have_index :password
64
+ should_not_have_index :name, :unique => true
65
+ should_not_have_index :email, :unique => false
66
66
  end
67
67
  end
68
-
68
+
@@ -1,47 +1,47 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe 'have_readonly_attributes' do
3
+ describe 'have_readonly_attributes' do
4
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)
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
19
  @matcher.description.should == 'make title and category read-only'
20
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
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
45
  end
46
46
  end
47
-
47
+
@@ -1,69 +1,69 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe 'have_scope' do
3
+ describe 'have_scope' do
4
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
-
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
+
11
11
  def self.beginning(c)
12
12
  scoped(:offset => c)
13
- end
14
-
15
- def self.null
16
- nil
17
- end
18
- end
19
- end
20
-
21
- describe 'messages' do
22
-
23
- it 'should contain a description' do
24
- @matcher = have_scope(:title)
25
- @matcher.description.should == 'have to scope itself to {} when :title is called'
26
-
27
- @matcher.with(1)
13
+ end
14
+
15
+ def self.null
16
+ nil
17
+ end
18
+ end
19
+ end
20
+
21
+ describe 'messages' do
22
+
23
+ it 'should contain a description' do
24
+ @matcher = have_scope(:title)
25
+ @matcher.description.should == 'have to scope itself to {} when :title is called'
26
+
27
+ @matcher.with(1)
28
28
  @matcher.description.should == 'have to scope itself to {} when :title is called with 1 as argument'
29
29
  end
30
-
31
- it 'should set is_scope? message' do
32
- @matcher = have_scope(:null)
33
- @matcher.matches?(@model)
34
- @matcher.failure_message.should == 'Expected :null when called on Product return a ActiveRecord::NamedScope::Scope object'
35
- end
36
-
37
- it 'should set options_match? message' do
38
- @matcher = have_scope(:recent, :conditions => {:special => true})
39
- @matcher.matches?(@model)
40
- @matcher.failure_message.should == 'Expected :recent when called on Product scope to {:conditions=>{:special=>true}}, got {:order=>"created_at DESC"}'
41
- end
42
-
43
- end
44
-
45
- describe 'matchers' do
46
- it { should have_scope(:recent) }
47
- it { should have_scope(:recent, :order => 'created_at DESC') }
48
-
49
- it { should have_scope(:latest, :with => 10, :limit => 10) }
50
- it { should have_scope(:beginning, :with => 10, :offset => 10) }
51
-
52
- it { should_not have_scope(:null) }
53
- it { should_not have_scope(:latest, :with => 5, :limit => 10) }
54
- it { should_not have_scope(:beginning, :with => 5, :offset => 10) }
55
- end
56
-
57
- describe 'macros' do
58
- should_have_scope :recent
59
- should_have_scope :recent, :order => 'created_at DESC'
60
-
61
- should_have_scope :latest, :with => 10, :limit => 10
62
- should_have_scope :beginning, :with => 10, :offset => 10
63
-
64
- should_not_have_scope :null
65
- should_not_have_scope :latest, :with => 5, :limit => 10
66
- should_not_have_scope :beginning, :with => 5, :offset => 10
30
+
31
+ it 'should set is_scope? message' do
32
+ @matcher = have_scope(:null)
33
+ @matcher.matches?(@model)
34
+ @matcher.failure_message.should == 'Expected :null when called on Product return a ActiveRecord::NamedScope::Scope object'
35
+ end
36
+
37
+ it 'should set options_match? message' do
38
+ @matcher = have_scope(:recent, :conditions => {:special => true})
39
+ @matcher.matches?(@model)
40
+ @matcher.failure_message.should == 'Expected :recent when called on Product scope to {:conditions=>{:special=>true}}, got {:order=>"created_at DESC"}'
41
+ end
42
+
43
+ end
44
+
45
+ describe 'matchers' do
46
+ it { should have_scope(:recent) }
47
+ it { should have_scope(:recent, :order => 'created_at DESC') }
48
+
49
+ it { should have_scope(:latest, :with => 10, :limit => 10) }
50
+ it { should have_scope(:beginning, :with => 10, :offset => 10) }
51
+
52
+ it { should_not have_scope(:null) }
53
+ it { should_not have_scope(:latest, :with => 5, :limit => 10) }
54
+ it { should_not have_scope(:beginning, :with => 5, :offset => 10) }
55
+ end
56
+
57
+ describe 'macros' do
58
+ should_have_scope :recent
59
+ should_have_scope :recent, :order => 'created_at DESC'
60
+
61
+ should_have_scope :latest, :with => 10, :limit => 10
62
+ should_have_scope :beginning, :with => 10, :offset => 10
63
+
64
+ should_not_have_scope :null
65
+ should_not_have_scope :latest, :with => 5, :limit => 10
66
+ should_not_have_scope :beginning, :with => 5, :offset => 10
67
67
  end
68
68
  end
69
-
69
+