remarkable_activerecord 3.1.8 → 3.1.9

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 (48) hide show
  1. data/CHANGELOG +140 -138
  2. data/LICENSE +20 -20
  3. data/README +80 -80
  4. data/lib/remarkable_activerecord.rb +29 -29
  5. data/lib/remarkable_activerecord/base.rb +248 -237
  6. data/lib/remarkable_activerecord/describe.rb +27 -27
  7. data/lib/remarkable_activerecord/human_names.rb +36 -36
  8. data/lib/remarkable_activerecord/matchers/accept_nested_attributes_for_matcher.rb +30 -30
  9. data/lib/remarkable_activerecord/matchers/allow_mass_assignment_of_matcher.rb +59 -59
  10. data/lib/remarkable_activerecord/matchers/allow_values_for_matcher.rb +85 -94
  11. data/lib/remarkable_activerecord/matchers/association_matcher.rb +283 -283
  12. data/lib/remarkable_activerecord/matchers/have_column_matcher.rb +68 -68
  13. data/lib/remarkable_activerecord/matchers/have_default_scope_matcher.rb +38 -38
  14. data/lib/remarkable_activerecord/matchers/have_index_matcher.rb +73 -73
  15. data/lib/remarkable_activerecord/matchers/have_readonly_attributes_matcher.rb +30 -30
  16. data/lib/remarkable_activerecord/matchers/have_scope_matcher.rb +85 -85
  17. data/lib/remarkable_activerecord/matchers/validate_acceptance_of_matcher.rb +50 -50
  18. data/lib/remarkable_activerecord/matchers/validate_associated_matcher.rb +97 -97
  19. data/lib/remarkable_activerecord/matchers/validate_confirmation_of_matcher.rb +44 -44
  20. data/lib/remarkable_activerecord/matchers/validate_exclusion_of_matcher.rb +53 -53
  21. data/lib/remarkable_activerecord/matchers/validate_inclusion_of_matcher.rb +52 -52
  22. data/lib/remarkable_activerecord/matchers/validate_length_of_matcher.rb +150 -150
  23. data/lib/remarkable_activerecord/matchers/validate_numericality_of_matcher.rb +181 -181
  24. data/lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb +29 -29
  25. data/lib/remarkable_activerecord/matchers/validate_uniqueness_of_matcher.rb +233 -233
  26. data/locale/en.yml +261 -261
  27. data/spec/accept_nested_attributes_for_matcher_spec.rb +1 -1
  28. data/spec/allow_mass_assignment_of_matcher_spec.rb +90 -82
  29. data/spec/allow_values_for_matcher_spec.rb +72 -63
  30. data/spec/association_matcher_spec.rb +612 -612
  31. data/spec/describe_spec.rb +3 -3
  32. data/spec/have_column_matcher_spec.rb +73 -73
  33. data/spec/have_default_scope_matcher_spec.rb +1 -1
  34. data/spec/have_index_matcher_spec.rb +87 -87
  35. data/spec/have_readonly_attributes_matcher_spec.rb +47 -47
  36. data/spec/have_scope_matcher_spec.rb +77 -77
  37. data/spec/model_builder.rb +101 -101
  38. data/spec/rcov.opts +1 -1
  39. data/spec/spec.opts +4 -4
  40. data/spec/spec_helper.rb +27 -27
  41. data/spec/validate_acceptance_of_matcher_spec.rb +68 -68
  42. data/spec/validate_associated_matcher_spec.rb +121 -121
  43. data/spec/validate_confirmation_of_matcher_spec.rb +58 -58
  44. data/spec/validate_length_of_matcher_spec.rb +218 -218
  45. data/spec/validate_numericality_of_matcher_spec.rb +179 -179
  46. data/spec/validate_presence_of_matcher_spec.rb +56 -56
  47. data/spec/validate_uniqueness_of_matcher_spec.rb +164 -164
  48. metadata +5 -5
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ * allow_values_for checks for any message unless otherwise given [#90]
2
+
1
3
  * Allow booleans to be given to validate_inclusion_of [#89]
2
4
 
3
5
  * Allow allow_values_for and allow_mass_assignment_of matchers to be executed in
@@ -5,141 +7,141 @@
5
7
 
6
8
  * Ensure quick subject bypass protected attributes [#87]
7
9
 
8
- * Added :token and :separator to deal with :tokenizer in validates_length_of [#77]
9
-
10
- * Deprecated validate_format_of. It does not have the same API as the respective
11
- ActiveRecord macro, raising questions frequentely about its usage [#76]
12
-
13
- * allow_mass_assignment_of when called without arguments checks if any mass
14
- assignment is possible [#80]
15
-
16
- * Add :table_name option to have_index (thanks to Lawrence Pit) [#79]
17
-
18
- * Allow default subject attributes to be given [#74]
19
- You can even mix with a fixture replacement tool and still use quick subjects:
20
-
21
- describe Post
22
- # Fixjour example
23
- subject_attributes { valid_post_attributes }
24
-
25
- describe :published => true do
26
- should_validate_presence_of :published_at
27
- end
28
- end
29
-
30
- * Bug fix when a symbol is given has join table to habtm association [#75]
31
-
32
- * Association matchers now searches in the right database for tables [#73]
33
-
34
- * validate_length_of accepts :with_kind_of to enable it to work with associations [#69]
35
- In your Post specs now you can write:
36
-
37
- should_validate_length_of :comments, :maximum => 10, :with_kind_of => Comment
38
-
39
- # v3.1
40
-
41
- * Allow validate_presence_of to work with associations [#63]
42
-
43
- * Allow validate_uniqueness_of to work when scopes are not stringfiable values.
44
- You can now give timestamps, datetime, date and boolean as scopes [#60]
45
-
46
- * Allow subjects to be overwriten quickly (quick subjects):
47
-
48
- describe Post
49
- should_validate_presente_of :title
50
-
51
- describe :published => true do
52
- should_validate_presence_of :published_at
53
- end
54
- end
55
-
56
- Is the same as:
57
-
58
- describe Post
59
- should_validate_presente_of :title
60
-
61
- describe "when published is true" do
62
- subject { Post.new(:published => true) }
63
- should_validate_presence_of :published_at
64
- end
65
- end
66
-
67
- And the string can be also localized using I18n [#57]
68
-
69
- [COMPATIBILITY] validate_associated no longer accepts a block to confgure the
70
- builder:
71
-
72
- should_validate_associated(:tasks){ |p| p.tasks.build(:captcha => 'i_am_a_robot') }
73
-
74
- The right way to do this is by giving an option called builder and a proc:
75
-
76
- should_validate_associated :tasks, :builder => proc{ |p| p.tasks.build(:captcha => 'i_am_a_robot') }
77
-
78
- * validate_uniqueness_of and accept_nested_attributes_for now use the new
79
- interpolation option {{sentence}} [#58]
80
-
81
- * Added accept_nested_attributes_for matcher [#39]
82
-
83
- * Added have_default_scope matcher [#38]
84
-
85
- * Allow :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly,
86
- :group, :having, :from, :lock as quick accessors to have_scope matcher
87
-
88
- * Allow all kind of objects to be sent to have_scope (including datetimes, arrays,
89
- booleans and nil) (thanks to Szymon Nowak and Nolan Eakins) [#53]
90
-
91
- * Added support to sql options in association_matcher: select, conditions, include,
92
- group, having, order, limit and offset, plus finder_sql and counter_sql. [#48]
93
-
94
- * :source and :source_type are now supported by association matcher [#47]
95
-
96
- * validate_inclusion_of became smarter since it now tests invalid values too [#36]
97
-
98
- * Fixed three bugs in validate_uniqueness_of matcher [#42] [#40] [#37]
99
-
100
- # v3.0
101
-
102
- * Added more options to associations matcher. Previously it was handling just
103
- :dependent and :through options. Now it deals with:
104
-
105
- :through, :class_name, :foreign_key, :dependent, :join_table, :uniq,
106
- :readonly, :validate, :autosave, :counter_cache, :polymorphic
107
-
108
- And they are much smarter! In :join_table and :through cases, they also test if
109
- the table exists or not. :counter_cache and :foreign_key also checks if the
110
- column exists or not.
111
-
112
- [COMPATIBILITY] Removed callback, have_instance_method and have_class_method
113
- matchers. They don't lead to a good TDD since you should test they behavior
114
- and not wether they exist or not.
115
-
116
- [COMPATIBILITY] ActiveRecord matches does not pick the instance variable from
117
- the spec environment. So we should target only rspec versions that supports
118
- subjects (>= 1.1.12).
119
-
120
- Previously, when we are doing this:
121
-
122
- describe Product
123
- before(:each){ @product = Product.new(:tangible => true) }
124
- should_validate_presence_of :size
125
- end
126
-
127
- It was validating the @product instance variable. However this might be not
128
- clear. The right way to do that (with subjects) is:
129
-
130
- describe Product
131
- subject{ Product.new(:tangible => true) }
132
- should_validate_presence_of :size
133
- end
134
-
135
- Is also valid to remember that previous versions of Remarkable were overriding
136
- subject definitions on rspec. This was also fixed.
137
-
138
- # v2.x
139
-
140
- * Added associations, allow_mass_assignment, allow_values_for, have_column,
141
- have_index, have_scope, have_readonly_attributes, validate_acceptance_of,
142
- validate_associated, validate_confirmation_of, validate_exclusion_of,
143
- validate_inclusion_of, validate_length_of, validate_numericality_of,
144
- validate_presence_of and validate_uniqueness_of matchers.
145
-
10
+ * Added :token and :separator to deal with :tokenizer in validates_length_of [#77]
11
+
12
+ * Deprecated validate_format_of. It does not have the same API as the respective
13
+ ActiveRecord macro, raising questions frequentely about its usage [#76]
14
+
15
+ * allow_mass_assignment_of when called without arguments checks if any mass
16
+ assignment is possible [#80]
17
+
18
+ * Add :table_name option to have_index (thanks to Lawrence Pit) [#79]
19
+
20
+ * Allow default subject attributes to be given [#74]
21
+ You can even mix with a fixture replacement tool and still use quick subjects:
22
+
23
+ describe Post
24
+ # Fixjour example
25
+ subject_attributes { valid_post_attributes }
26
+
27
+ describe :published => true do
28
+ should_validate_presence_of :published_at
29
+ end
30
+ end
31
+
32
+ * Bug fix when a symbol is given has join table to habtm association [#75]
33
+
34
+ * Association matchers now searches in the right database for tables [#73]
35
+
36
+ * validate_length_of accepts :with_kind_of to enable it to work with associations [#69]
37
+ In your Post specs now you can write:
38
+
39
+ should_validate_length_of :comments, :maximum => 10, :with_kind_of => Comment
40
+
41
+ # v3.1
42
+
43
+ * Allow validate_presence_of to work with associations [#63]
44
+
45
+ * Allow validate_uniqueness_of to work when scopes are not stringfiable values.
46
+ You can now give timestamps, datetime, date and boolean as scopes [#60]
47
+
48
+ * Allow subjects to be overwriten quickly (quick subjects):
49
+
50
+ describe Post
51
+ should_validate_presente_of :title
52
+
53
+ describe :published => true do
54
+ should_validate_presence_of :published_at
55
+ end
56
+ end
57
+
58
+ Is the same as:
59
+
60
+ describe Post
61
+ should_validate_presente_of :title
62
+
63
+ describe "when published is true" do
64
+ subject { Post.new(:published => true) }
65
+ should_validate_presence_of :published_at
66
+ end
67
+ end
68
+
69
+ And the string can be also localized using I18n [#57]
70
+
71
+ [COMPATIBILITY] validate_associated no longer accepts a block to confgure the
72
+ builder:
73
+
74
+ should_validate_associated(:tasks){ |p| p.tasks.build(:captcha => 'i_am_a_robot') }
75
+
76
+ The right way to do this is by giving an option called builder and a proc:
77
+
78
+ should_validate_associated :tasks, :builder => proc{ |p| p.tasks.build(:captcha => 'i_am_a_robot') }
79
+
80
+ * validate_uniqueness_of and accept_nested_attributes_for now use the new
81
+ interpolation option {{sentence}} [#58]
82
+
83
+ * Added accept_nested_attributes_for matcher [#39]
84
+
85
+ * Added have_default_scope matcher [#38]
86
+
87
+ * Allow :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly,
88
+ :group, :having, :from, :lock as quick accessors to have_scope matcher
89
+
90
+ * Allow all kind of objects to be sent to have_scope (including datetimes, arrays,
91
+ booleans and nil) (thanks to Szymon Nowak and Nolan Eakins) [#53]
92
+
93
+ * Added support to sql options in association_matcher: select, conditions, include,
94
+ group, having, order, limit and offset, plus finder_sql and counter_sql. [#48]
95
+
96
+ * :source and :source_type are now supported by association matcher [#47]
97
+
98
+ * validate_inclusion_of became smarter since it now tests invalid values too [#36]
99
+
100
+ * Fixed three bugs in validate_uniqueness_of matcher [#42] [#40] [#37]
101
+
102
+ # v3.0
103
+
104
+ * Added more options to associations matcher. Previously it was handling just
105
+ :dependent and :through options. Now it deals with:
106
+
107
+ :through, :class_name, :foreign_key, :dependent, :join_table, :uniq,
108
+ :readonly, :validate, :autosave, :counter_cache, :polymorphic
109
+
110
+ And they are much smarter! In :join_table and :through cases, they also test if
111
+ the table exists or not. :counter_cache and :foreign_key also checks if the
112
+ column exists or not.
113
+
114
+ [COMPATIBILITY] Removed callback, have_instance_method and have_class_method
115
+ matchers. They don't lead to a good TDD since you should test they behavior
116
+ and not wether they exist or not.
117
+
118
+ [COMPATIBILITY] ActiveRecord matches does not pick the instance variable from
119
+ the spec environment. So we should target only rspec versions that supports
120
+ subjects (>= 1.1.12).
121
+
122
+ Previously, when we are doing this:
123
+
124
+ describe Product
125
+ before(:each){ @product = Product.new(:tangible => true) }
126
+ should_validate_presence_of :size
127
+ end
128
+
129
+ It was validating the @product instance variable. However this might be not
130
+ clear. The right way to do that (with subjects) is:
131
+
132
+ describe Product
133
+ subject{ Product.new(:tangible => true) }
134
+ should_validate_presence_of :size
135
+ end
136
+
137
+ Is also valid to remember that previous versions of Remarkable were overriding
138
+ subject definitions on rspec. This was also fixed.
139
+
140
+ # v2.x
141
+
142
+ * Added associations, allow_mass_assignment, allow_values_for, have_column,
143
+ have_index, have_scope, have_readonly_attributes, validate_acceptance_of,
144
+ validate_associated, validate_confirmation_of, validate_exclusion_of,
145
+ validate_inclusion_of, validate_length_of, validate_numericality_of,
146
+ validate_presence_of and validate_uniqueness_of matchers.
147
+
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2009 Carlos Brando
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2009 Carlos Brando
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README CHANGED
@@ -1,87 +1,87 @@
1
- = Remarkable ActiveRecord
2
-
3
- Remarkable ActiveRecord is a collection of matchers to ActiveRecord. Why use
4
- Remarkable?
5
-
1
+ = Remarkable ActiveRecord
2
+
3
+ Remarkable ActiveRecord is a collection of matchers to ActiveRecord. Why use
4
+ Remarkable?
5
+
6
6
  * Matchers for all ActiveRecord validations, with support to all options. The only
7
7
  exceptions are validate_format_of (which should be invoked as allow_values_for)
8
- and the :on option;
9
-
10
- * Matchers for all ActiveRecord associations. The only one which supports all
11
- these options:
12
-
8
+ and the :on option;
9
+
10
+ * Matchers for all ActiveRecord associations. The only one which supports all
11
+ these options:
12
+
13
13
  :through, :source, :source_type, :class_name, :foreign_key, :dependent,
14
14
  :join_table, :uniq, :readonly, :validate, :autosave, :counter_cache, :polymorphic
15
15
 
16
16
  Plus SQL options:
17
17
 
18
- :select, :conditions, :include, :group, :having, :order, :limit, :offset
19
-
20
- Besides in Remarkable 3.0 matchers became much smarter. Whenever :join_table
21
- or :through is given as option, it checks if the given table exists. Whenever
22
- :foreign_key or :counter_cache is given, it checks if the given column exists;
23
-
24
- * Tests and more tests. We have a huge tests suite ready to run and tested in
25
- ActiveRecord 2.1.2, 2.2.2 and 2.3.2;
26
-
27
- * Great documentation;
28
-
29
- * I18n.
30
-
31
- == Examples
32
-
33
- All Remarkable macros can be accessed in two different ways. For those who prefer the Shoulda style, let’s look at some model tests:
34
-
35
- describe Post do
36
- should_belong_to :user
37
- should_have_many :comments
38
- should_have_and_belong_to_many :tags
39
-
40
- should_validate_presence_of :body
41
- should_validate_presence_of :title
42
- should_validate_uniqueness_of :title, :allow_blank => true
43
- end
44
-
45
- For those who likes more the Rspec way can simply do:
46
-
47
- describe Post do
48
- it { should belong_to(:user) }
49
- it { should have_many(:comments) }
50
- it { should have_and_belong_to_many(:tags) }
51
-
52
- it { should validate_presence_of(:body) }
53
- it { should validate_presence_of(:title) }
54
- it { should validate_uniqueness_of(:title, :allow_blank => true) }
55
- end
56
-
57
- == I18n
58
-
59
- All matchers come with I18n support. If you want to translate your matchers,
60
- grab make a copy of locale/en.yml and start to translate it.
61
-
62
- Then add your new locale file to Remarkable:
63
-
64
- Remarkable.add_locale 'path/to/my_locale.yml'
65
-
66
- And then:
67
-
68
- Remarkable.locale = :my_locale
69
-
70
- == Using it outside Rails
71
-
72
- If you want to use Remarkable ActiveRecord outside Rails, you have to remember
73
- a few things:
74
-
75
- 1. Internationalization is powered by the I18n gem. If you are using it with Rails,
76
- it will use the built in gem, otherwise you will have to install the gem by hand:
77
-
78
- gem sources -a http://gems.github.com
79
- sudo gem install svenfuchs-i18n
80
-
81
- 2. Include the matchers. Remarkable Rails gem is the responsable to add
82
- ActiveRecord matchers to rspec. If you are not using it, you have to do:
83
-
84
- Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Example::ExampleGroup)
85
-
86
- This will make ActiveRecord matchers available in all rspec example groups.
87
-
18
+ :select, :conditions, :include, :group, :having, :order, :limit, :offset
19
+
20
+ Besides in Remarkable 3.0 matchers became much smarter. Whenever :join_table
21
+ or :through is given as option, it checks if the given table exists. Whenever
22
+ :foreign_key or :counter_cache is given, it checks if the given column exists;
23
+
24
+ * Tests and more tests. We have a huge tests suite ready to run and tested in
25
+ ActiveRecord 2.1.2, 2.2.2 and 2.3.2;
26
+
27
+ * Great documentation;
28
+
29
+ * I18n.
30
+
31
+ == Examples
32
+
33
+ All Remarkable macros can be accessed in two different ways. For those who prefer the Shoulda style, let’s look at some model tests:
34
+
35
+ describe Post do
36
+ should_belong_to :user
37
+ should_have_many :comments
38
+ should_have_and_belong_to_many :tags
39
+
40
+ should_validate_presence_of :body
41
+ should_validate_presence_of :title
42
+ should_validate_uniqueness_of :title, :allow_blank => true
43
+ end
44
+
45
+ For those who likes more the Rspec way can simply do:
46
+
47
+ describe Post do
48
+ it { should belong_to(:user) }
49
+ it { should have_many(:comments) }
50
+ it { should have_and_belong_to_many(:tags) }
51
+
52
+ it { should validate_presence_of(:body) }
53
+ it { should validate_presence_of(:title) }
54
+ it { should validate_uniqueness_of(:title, :allow_blank => true) }
55
+ end
56
+
57
+ == I18n
58
+
59
+ All matchers come with I18n support. If you want to translate your matchers,
60
+ grab make a copy of locale/en.yml and start to translate it.
61
+
62
+ Then add your new locale file to Remarkable:
63
+
64
+ Remarkable.add_locale 'path/to/my_locale.yml'
65
+
66
+ And then:
67
+
68
+ Remarkable.locale = :my_locale
69
+
70
+ == Using it outside Rails
71
+
72
+ If you want to use Remarkable ActiveRecord outside Rails, you have to remember
73
+ a few things:
74
+
75
+ 1. Internationalization is powered by the I18n gem. If you are using it with Rails,
76
+ it will use the built in gem, otherwise you will have to install the gem by hand:
77
+
78
+ gem sources -a http://gems.github.com
79
+ sudo gem install svenfuchs-i18n
80
+
81
+ 2. Include the matchers. Remarkable Rails gem is the responsable to add
82
+ ActiveRecord matchers to rspec. If you are not using it, you have to do:
83
+
84
+ Remarkable.include_matchers!(Remarkable::ActiveRecord, Spec::Example::ExampleGroup)
85
+
86
+ This will make ActiveRecord matchers available in all rspec example groups.
87
+