carlosbrando-remarkable 0.0.99 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -5
- data/Manifest.txt +53 -35
- data/PostInstall.txt +1 -6
- data/README.rdoc +109 -15
- data/Rakefile +29 -29
- data/lib/remarkable/active_record/README.markdown +378 -0
- data/lib/remarkable/active_record/active_record.rb +12 -11
- data/lib/remarkable/active_record/helpers.rb +215 -5
- data/lib/remarkable/active_record/macros/associations/association_matcher.rb +242 -0
- data/lib/remarkable/active_record/macros/callbacks/callback_matcher.rb +46 -0
- data/lib/remarkable/active_record/macros/database/column_matcher.rb +122 -0
- data/lib/remarkable/active_record/macros/database/index_matcher.rb +103 -0
- data/lib/remarkable/active_record/macros/validations/allow_mass_assignment_of_matcher.rb +52 -0
- data/lib/remarkable/active_record/macros/validations/ensure_value_in_list_matcher.rb +83 -0
- data/lib/remarkable/active_record/macros/validations/ensure_value_in_range_matcher.rb +172 -0
- data/lib/remarkable/active_record/macros/validations/have_class_methods_matcher.rb +54 -0
- data/lib/remarkable/active_record/macros/validations/have_instance_methods_matcher.rb +54 -0
- data/lib/remarkable/active_record/macros/validations/have_named_scope_matcher.rb +94 -0
- data/lib/remarkable/active_record/macros/validations/have_readonly_attributes_matcher.rb +48 -0
- data/lib/remarkable/active_record/macros/validations/protect_attributes_matcher.rb +51 -0
- data/lib/remarkable/active_record/macros/validations/validate_acceptance_of_matcher.rb +79 -0
- data/lib/remarkable/active_record/macros/validations/validate_associated_matcher.rb +177 -0
- data/lib/remarkable/active_record/macros/validations/validate_confirmation_of_matcher.rb +74 -0
- data/lib/remarkable/active_record/macros/validations/validate_exclusion_of_matcher.rb +38 -0
- data/lib/remarkable/active_record/macros/validations/validate_format_of_matcher.rb +33 -0
- data/lib/remarkable/active_record/macros/validations/validate_inclusion_of_matcher.rb +45 -0
- data/lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb +248 -0
- data/lib/remarkable/active_record/macros/validations/validate_numericality_of_matcher.rb +206 -0
- data/lib/remarkable/active_record/macros/validations/validate_presence_of_matcher.rb +72 -0
- data/lib/remarkable/active_record/macros/validations/validate_uniqueness_of_matcher.rb +222 -0
- data/lib/remarkable/active_record/macros.rb +52 -0
- data/lib/remarkable/assertions.rb +29 -0
- data/lib/remarkable/controller/README.markdown +147 -0
- data/lib/remarkable/controller/controller.rb +11 -6
- data/lib/remarkable/controller/helpers.rb +4 -38
- data/lib/remarkable/controller/macros/assign_matcher.rb +85 -0
- data/lib/remarkable/controller/macros/filter_params_matcher.rb +63 -0
- data/lib/remarkable/controller/macros/metadata_matcher.rb +63 -0
- data/lib/remarkable/controller/macros/render_with_layout_matcher.rb +75 -0
- data/lib/remarkable/controller/macros/respond_with_content_type_matcher.rb +60 -0
- data/lib/remarkable/controller/macros/respond_with_matcher.rb +62 -0
- data/lib/remarkable/controller/macros/return_from_session_matcher.rb +58 -0
- data/lib/remarkable/controller/macros/route_matcher.rb +75 -0
- data/lib/remarkable/controller/macros/set_the_flash_to_matcher.rb +60 -0
- data/lib/remarkable/controller/macros.rb +78 -0
- data/lib/remarkable/dsl.rb +239 -0
- data/lib/remarkable/example/example_methods.rb +27 -7
- data/lib/remarkable/helpers.rb +28 -0
- data/lib/remarkable/matcher_base.rb +64 -0
- data/lib/remarkable/private_helpers.rb +10 -115
- data/lib/remarkable/rails.rb +27 -0
- data/lib/remarkable.rb +13 -5
- data/remarkable.gemspec +43 -0
- data/spec/controllers/posts_controller_spec.rb +58 -4
- data/spec/controllers/users_controller_spec.rb +1 -0
- data/spec/fixtures/fleas.yml +10 -0
- data/spec/fixtures/users.yml +7 -0
- data/spec/models/address_spec.rb +44 -0
- data/spec/models/dog_spec.rb +64 -3
- data/spec/models/flea_spec.rb +30 -0
- data/spec/models/post_spec.rb +36 -2
- data/spec/models/product_spec.rb +73 -8
- data/spec/models/tag_spec.rb +2 -2
- data/spec/models/tagging_spec.rb +24 -0
- data/spec/models/user_spec.rb +206 -21
- data/spec/other/custom_macros_spec.rb +27 -0
- data/spec/other/my_own_matcher_spec.rb +11 -0
- data/spec/other/private_helpers_spec.rb +31 -0
- data/spec/rails_root/app/controllers/posts_controller.rb +2 -0
- data/spec/rails_root/app/models/address.rb +2 -2
- data/spec/rails_root/app/models/flea.rb +4 -0
- data/spec/rails_root/app/models/pets/dog.rb +12 -0
- data/spec/rails_root/app/models/product.rb +7 -5
- data/spec/rails_root/app/models/tagging.rb +2 -0
- data/spec/rails_root/app/models/user.rb +20 -5
- data/spec/rails_root/app/views/layouts/posts.rhtml +8 -6
- data/spec/rails_root/config/database.yml +1 -2
- data/spec/rails_root/config/environment.rb +3 -1
- data/spec/rails_root/config/environments/{sqlite3.rb → test.rb} +0 -0
- data/spec/rails_root/config/locales/en.yml +8 -0
- data/spec/rails_root/db/migrate/001_create_users.rb +2 -2
- data/spec/rails_root/db/migrate/005_create_dogs.rb +1 -0
- data/spec/rails_root/db/migrate/011_add_fleas_color.rb +10 -0
- data/spec/rails_root/db/migrate/012_add_fleas_address.rb +10 -0
- data/spec/rails_root/spec/remarkable_macros/.keep +0 -0
- data/spec/rails_root/vendor/plugins/my_plugin/remarkable_macros/.keep +0 -0
- data/spec/spec_helper.rb +0 -2
- metadata +63 -43
- data/lib/remarkable/active_record/macros/associations/belong_to.rb +0 -81
- data/lib/remarkable/active_record/macros/associations/have_and_belong_to_many.rb +0 -77
- data/lib/remarkable/active_record/macros/associations/have_many.rb +0 -160
- data/lib/remarkable/active_record/macros/associations/have_one.rb +0 -133
- data/lib/remarkable/active_record/macros/database/have_db_column.rb +0 -81
- data/lib/remarkable/active_record/macros/database/have_db_columns.rb +0 -73
- data/lib/remarkable/active_record/macros/database/have_indices.rb +0 -75
- data/lib/remarkable/active_record/macros/validations/allow_values_for.rb +0 -103
- data/lib/remarkable/active_record/macros/validations/ensure_length_at_least.rb +0 -97
- data/lib/remarkable/active_record/macros/validations/ensure_length_in_range.rb +0 -134
- data/lib/remarkable/active_record/macros/validations/ensure_length_is.rb +0 -106
- data/lib/remarkable/active_record/macros/validations/ensure_value_in_range.rb +0 -117
- data/lib/remarkable/active_record/macros/validations/have_class_methods.rb +0 -74
- data/lib/remarkable/active_record/macros/validations/have_instance_methods.rb +0 -74
- data/lib/remarkable/active_record/macros/validations/have_named_scope.rb +0 -148
- data/lib/remarkable/active_record/macros/validations/have_readonly_attributes.rb +0 -81
- data/lib/remarkable/active_record/macros/validations/only_allow_numeric_values_for.rb +0 -89
- data/lib/remarkable/active_record/macros/validations/protect_attributes.rb +0 -89
- data/lib/remarkable/active_record/macros/validations/require_acceptance_of.rb +0 -94
- data/lib/remarkable/active_record/macros/validations/require_attributes.rb +0 -94
- data/lib/remarkable/active_record/macros/validations/require_unique_attributes.rb +0 -146
- data/lib/remarkable/controller/macros/assign_to.rb +0 -110
- data/lib/remarkable/controller/macros/filter_params.rb +0 -52
- data/lib/remarkable/controller/macros/redirect_to.rb +0 -24
- data/lib/remarkable/controller/macros/render_a_form.rb +0 -23
- data/lib/remarkable/controller/macros/render_template.rb +0 -18
- data/lib/remarkable/controller/macros/render_with_layout.rb +0 -61
- data/lib/remarkable/controller/macros/respond_with.rb +0 -86
- data/lib/remarkable/controller/macros/respond_with_content_type.rb +0 -45
- data/lib/remarkable/controller/macros/return_from_session.rb +0 -45
- data/lib/remarkable/controller/macros/route.rb +0 -91
- data/lib/remarkable/controller/macros/set_the_flash_to.rb +0 -58
- data/spec/rails_root/app/models/dog.rb +0 -5
@@ -1,97 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
class EnsureLengthAtLeast
|
6
|
-
include Remarkable::Private
|
7
|
-
|
8
|
-
def initialize(attribute, min_length, opts)
|
9
|
-
@attribute = attribute
|
10
|
-
@min_length = min_length
|
11
|
-
@opts = opts
|
12
|
-
end
|
13
|
-
|
14
|
-
def matches?(klass)
|
15
|
-
@klass = klass
|
16
|
-
|
17
|
-
begin
|
18
|
-
valid_value = "x" * (@min_length)
|
19
|
-
fail("not allow #{@attribute} to be at least #{@min_length} chars long") unless assert_good_value(klass, @attribute, valid_value, /is too short/)
|
20
|
-
|
21
|
-
if @min_length > 0
|
22
|
-
min_value = "x" * (@min_length - 1)
|
23
|
-
fail("allow #{@attribute} to be less than #{@min_length} chars long") unless assert_bad_value(klass, @attribute, min_value, /is too short/)
|
24
|
-
end
|
25
|
-
|
26
|
-
true
|
27
|
-
rescue Exception => e
|
28
|
-
false
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def description
|
33
|
-
"allow #{@attribute} to be at least #{@min_length} chars long"
|
34
|
-
end
|
35
|
-
|
36
|
-
def failure_message
|
37
|
-
@failure_message || "expected allow #{@attribute} to be at least #{@min_length} chars long, but it didn't"
|
38
|
-
end
|
39
|
-
|
40
|
-
def negative_failure_message
|
41
|
-
"expected not allow #{@attribute} to be at least #{@min_length} chars long, but it did"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Ensures that the length of the attribute is at least a certain length
|
46
|
-
#
|
47
|
-
# If an instance variable has been created in the setup named after the
|
48
|
-
# model being tested, then this method will use that. Otherwise, it will
|
49
|
-
# create a new instance to test against.
|
50
|
-
#
|
51
|
-
# Options:
|
52
|
-
# * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
53
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.too_short') % min_length</tt>
|
54
|
-
#
|
55
|
-
# Example:
|
56
|
-
# it { Tag.should ensure_length_at_least(:name, 3) }
|
57
|
-
#
|
58
|
-
def ensure_length_at_least(attribute, min_length, opts = {})
|
59
|
-
Remarkable::Syntax::RSpec::EnsureLengthAtLeast.new(attribute, min_length, opts)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
module Shoulda
|
64
|
-
# Ensures that the length of the attribute is at least a certain length
|
65
|
-
#
|
66
|
-
# If an instance variable has been created in the setup named after the
|
67
|
-
# model being tested, then this method will use that. Otherwise, it will
|
68
|
-
# create a new instance to test against.
|
69
|
-
#
|
70
|
-
# Options:
|
71
|
-
# * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
72
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.too_short') % min_length</tt>
|
73
|
-
#
|
74
|
-
# Example:
|
75
|
-
# should_ensure_length_at_least :name, 3
|
76
|
-
#
|
77
|
-
def should_ensure_length_at_least(attribute, min_length, opts = {})
|
78
|
-
short_message = get_options!([opts], :short_message)
|
79
|
-
short_message ||= default_error_message(:too_short, :count => min_length)
|
80
|
-
|
81
|
-
klass = model_class
|
82
|
-
|
83
|
-
if min_length > 0
|
84
|
-
min_value = "x" * (min_length - 1)
|
85
|
-
it "should not allow #{attribute} to be less than #{min_length} chars long" do
|
86
|
-
assert_bad_value(klass, attribute, min_value, short_message).should be_true
|
87
|
-
end
|
88
|
-
end
|
89
|
-
it "should allow #{attribute} to be at least #{min_length} chars long" do
|
90
|
-
valid_value = "x" * (min_length)
|
91
|
-
assert_good_value(klass, attribute, valid_value, short_message).should be_true
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
class EnsureLengthInRange
|
6
|
-
include Remarkable::Private
|
7
|
-
|
8
|
-
def initialize(attribute, range, opts)
|
9
|
-
@min_length = range.first
|
10
|
-
@max_length = range.last
|
11
|
-
@same_length = (@min_length == @max_length)
|
12
|
-
|
13
|
-
@attribute = attribute
|
14
|
-
@range = range
|
15
|
-
@opts = opts
|
16
|
-
end
|
17
|
-
|
18
|
-
def matches?(klass)
|
19
|
-
@klass = klass
|
20
|
-
|
21
|
-
begin
|
22
|
-
if @min_length > 0
|
23
|
-
min_value = "x" * @min_length
|
24
|
-
fail("not allow #{@attribute} to be exactly #{@min_length} chars long") unless assert_good_value(klass, @attribute, min_value, /is too short/)
|
25
|
-
end
|
26
|
-
|
27
|
-
unless @same_length
|
28
|
-
max_value = "x" * @max_length
|
29
|
-
fail("not allow #{@attribute} to be exactly #{@max_length} chars long") unless assert_good_value(klass, @attribute, max_value, /is too long/)
|
30
|
-
end
|
31
|
-
|
32
|
-
if @min_length > 0
|
33
|
-
min_value = "x" * (@min_length - 1)
|
34
|
-
fail("allow #{@attribute} to be less than #{@min_length} chars long") unless assert_bad_value(klass, @attribute, min_value, /is too short/)
|
35
|
-
end
|
36
|
-
|
37
|
-
max_value = "x" * (@max_length + 1)
|
38
|
-
fail("allow #{@attribute} to be more than #{@max_length} chars long") unless assert_bad_value(klass, @attribute, max_value, /is too long/)
|
39
|
-
|
40
|
-
true
|
41
|
-
rescue Exception => e
|
42
|
-
false
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def description
|
47
|
-
"ensure that the length of the #{@attribute} is in #{@range}"
|
48
|
-
end
|
49
|
-
|
50
|
-
def failure_message
|
51
|
-
@failure_message || "expected that the length of the #{@attribute} is in #{@range}, but it didn't"
|
52
|
-
end
|
53
|
-
|
54
|
-
def negative_failure_message
|
55
|
-
"expected that the length of the #{@attribute} isn't in #{@range}, but it did"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Ensures that the length of the attribute is in the given range
|
60
|
-
#
|
61
|
-
# If an instance variable has been created in the setup named after the
|
62
|
-
# model being tested, then this method will use that. Otherwise, it will
|
63
|
-
# create a new instance to test against.
|
64
|
-
#
|
65
|
-
# Options:
|
66
|
-
# * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
67
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.too_short') % range.first</tt>
|
68
|
-
# * <tt>:long_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
69
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.too_long') % range.last</tt>
|
70
|
-
#
|
71
|
-
# Example:
|
72
|
-
# it { User.should ensure_length_in_range(:password, 6..20) }
|
73
|
-
#
|
74
|
-
def ensure_length_in_range(attribute, range, opts = {})
|
75
|
-
Remarkable::Syntax::RSpec::EnsureLengthInRange.new(attribute, range, opts)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
module Shoulda
|
80
|
-
# Ensures that the length of the attribute is in the given range
|
81
|
-
#
|
82
|
-
# If an instance variable has been created in the setup named after the
|
83
|
-
# model being tested, then this method will use that. Otherwise, it will
|
84
|
-
# create a new instance to test against.
|
85
|
-
#
|
86
|
-
# Options:
|
87
|
-
# * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
88
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.too_short') % range.first</tt>
|
89
|
-
# * <tt>:long_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
90
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.too_long') % range.last</tt>
|
91
|
-
#
|
92
|
-
# Example:
|
93
|
-
# should_ensure_length_in_range :password, (6..20)
|
94
|
-
#
|
95
|
-
def should_ensure_length_in_range(attribute, range, opts = {})
|
96
|
-
short_message, long_message = get_options!([opts], :short_message, :long_message)
|
97
|
-
short_message ||= default_error_message(:too_short, :count => range.first)
|
98
|
-
long_message ||= default_error_message(:too_long, :count => range.last)
|
99
|
-
|
100
|
-
klass = model_class
|
101
|
-
min_length = range.first
|
102
|
-
max_length = range.last
|
103
|
-
same_length = (min_length == max_length)
|
104
|
-
|
105
|
-
if min_length > 0
|
106
|
-
it "should not allow #{attribute} to be less than #{min_length} chars long" do
|
107
|
-
min_value = "x" * (min_length - 1)
|
108
|
-
assert_bad_value(klass, attribute, min_value, short_message).should be_true
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
if min_length > 0
|
113
|
-
it "should allow #{attribute} to be exactly #{min_length} chars long" do
|
114
|
-
min_value = "x" * min_length
|
115
|
-
assert_good_value(klass, attribute, min_value, short_message).should be_true
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should not allow #{attribute} to be more than #{max_length} chars long" do
|
120
|
-
max_value = "x" * (max_length + 1)
|
121
|
-
assert_bad_value(klass, attribute, max_value, long_message).should be_true
|
122
|
-
end
|
123
|
-
|
124
|
-
unless same_length
|
125
|
-
it "should allow #{attribute} to be exactly #{max_length} chars long" do
|
126
|
-
max_value = "x" * max_length
|
127
|
-
assert_good_value(klass, attribute, max_value, long_message).should be_true
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
class EnsureLengthIs
|
6
|
-
include Remarkable::Private
|
7
|
-
|
8
|
-
def initialize(attribute, length, opts)
|
9
|
-
@message = get_options!([opts], :message)
|
10
|
-
@message ||= default_error_message(:wrong_length, :count => length)
|
11
|
-
|
12
|
-
@attribute = attribute
|
13
|
-
@length = length
|
14
|
-
@opts = opts
|
15
|
-
end
|
16
|
-
|
17
|
-
def matches?(klass)
|
18
|
-
@klass = klass
|
19
|
-
|
20
|
-
begin
|
21
|
-
min_value = "x" * (@length - 1)
|
22
|
-
fail("allow #{@attribute} to be less than #{@length} chars long") unless assert_bad_value(klass, @attribute, min_value, @message)
|
23
|
-
|
24
|
-
max_value = "x" * (@length + 1)
|
25
|
-
fail("allow #{@attribute} to be greater than #{@length} chars long") unless assert_bad_value(klass, @attribute, max_value, @message)
|
26
|
-
|
27
|
-
valid_value = "x" * (@length)
|
28
|
-
fail("not allow #{@attribute} to be #{@length} chars long") unless assert_good_value(klass, @attribute, valid_value, @message)
|
29
|
-
|
30
|
-
true
|
31
|
-
rescue Exception => e
|
32
|
-
false
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def description
|
38
|
-
"ensure that the length of the #{@attribute} is exactly #{@length} chars long"
|
39
|
-
end
|
40
|
-
|
41
|
-
def failure_message
|
42
|
-
@failure_message || "expected that the length of the #{@attribute} is exactly #{@length} chars long, but it didn't"
|
43
|
-
end
|
44
|
-
|
45
|
-
def negative_failure_message
|
46
|
-
"expected that the length of the #{@attribute} isn't exactly #{@length} chars long, but it did"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Ensures that the length of the attribute is exactly a certain length
|
51
|
-
#
|
52
|
-
# If an instance variable has been created in the setup named after the
|
53
|
-
# model being tested, then this method will use that. Otherwise, it will
|
54
|
-
# create a new instance to test against.
|
55
|
-
#
|
56
|
-
# Options:
|
57
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
58
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.wrong_length') % length</tt>
|
59
|
-
#
|
60
|
-
# Example:
|
61
|
-
# it { User.should ensure_length_is(:ssn, 9) }
|
62
|
-
#
|
63
|
-
def ensure_length_is(attribute, length, opts = {})
|
64
|
-
Remarkable::Syntax::RSpec::EnsureLengthIs.new(attribute, length, opts)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
module Shoulda
|
69
|
-
# Ensures that the length of the attribute is exactly a certain length
|
70
|
-
#
|
71
|
-
# If an instance variable has been created in the setup named after the
|
72
|
-
# model being tested, then this method will use that. Otherwise, it will
|
73
|
-
# create a new instance to test against.
|
74
|
-
#
|
75
|
-
# Options:
|
76
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
77
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.wrong_length') % length</tt>
|
78
|
-
#
|
79
|
-
# Example:
|
80
|
-
# should_ensure_length_is :ssn, 9
|
81
|
-
#
|
82
|
-
def should_ensure_length_is(attribute, length, opts = {})
|
83
|
-
message = get_options!([opts], :message)
|
84
|
-
message ||= default_error_message(:wrong_length, :count => length)
|
85
|
-
|
86
|
-
klass = model_class
|
87
|
-
|
88
|
-
it "should not allow #{attribute} to be less than #{length} chars long" do
|
89
|
-
min_value = "x" * (length - 1)
|
90
|
-
assert_bad_value(klass, attribute, min_value, message).should be_true
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should not allow #{attribute} to be greater than #{length} chars long" do
|
94
|
-
max_value = "x" * (length + 1)
|
95
|
-
assert_bad_value(klass, attribute, max_value, message).should be_true
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should allow #{attribute} to be #{length} chars long" do
|
99
|
-
valid_value = "x" * (length)
|
100
|
-
assert_good_value(klass, attribute, valid_value, message).should be_true
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
class EnsureValueInRange
|
6
|
-
include Remarkable::Private
|
7
|
-
|
8
|
-
def initialize(attribute, range, opts = {})
|
9
|
-
@attribute = attribute
|
10
|
-
@range = range
|
11
|
-
@opts = opts
|
12
|
-
|
13
|
-
@min = range.first
|
14
|
-
@max = range.last
|
15
|
-
|
16
|
-
@low_message, @high_message = get_options!([@opts], :low_message, :high_message)
|
17
|
-
@low_message ||= default_error_message(:inclusion)
|
18
|
-
@high_message ||= default_error_message(:inclusion)
|
19
|
-
end
|
20
|
-
|
21
|
-
def matches?(klass)
|
22
|
-
@klass = klass
|
23
|
-
|
24
|
-
begin
|
25
|
-
fail("allow #{@attribute} to be less than #{@min}") unless assert_bad_value(klass, @attribute, @min - 1, @low_message)
|
26
|
-
fail("not allow #{@attribute} to be #{@min}") unless assert_good_value(klass, @attribute, @min, @low_message)
|
27
|
-
fail("allow #{@attribute} to be more than #{@max}") unless assert_bad_value(klass, @attribute, @max + 1, @high_message)
|
28
|
-
fail("not allow #{@attribute} to be #{@max}") unless assert_good_value(klass, @attribute, @max, @high_message)
|
29
|
-
|
30
|
-
true
|
31
|
-
rescue Exception => e
|
32
|
-
false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def description
|
37
|
-
"ensure that the #{@attribute} is in #{@range}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def failure_message
|
41
|
-
@failure_message || "expected that the #{@attribute} is in #{@range}, but it didn't"
|
42
|
-
end
|
43
|
-
|
44
|
-
def negative_failure_message
|
45
|
-
"expected that the #{@attribute} isn't in #{@range}, but it did"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Ensure that the attribute is in the range specified
|
50
|
-
#
|
51
|
-
# If an instance variable has been created in the setup named after the
|
52
|
-
# model being tested, then this method will use that. Otherwise, it will
|
53
|
-
# create a new instance to test against.
|
54
|
-
#
|
55
|
-
# Options:
|
56
|
-
# * <tt>:low_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
57
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.inclusion')</tt>
|
58
|
-
# * <tt>:high_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
59
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.inclusion')</tt>
|
60
|
-
#
|
61
|
-
# Example:
|
62
|
-
# it { User.should ensure_value_in_range(:age, 1..100) }
|
63
|
-
#
|
64
|
-
def ensure_value_in_range(attribute, range, opts = {})
|
65
|
-
Remarkable::Syntax::RSpec::EnsureValueInRange.new(attribute, range, opts)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
module Shoulda
|
70
|
-
# Ensure that the attribute is in the range specified
|
71
|
-
#
|
72
|
-
# If an instance variable has been created in the setup named after the
|
73
|
-
# model being tested, then this method will use that. Otherwise, it will
|
74
|
-
# create a new instance to test against.
|
75
|
-
#
|
76
|
-
# Options:
|
77
|
-
# * <tt>:low_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
78
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.inclusion')</tt>
|
79
|
-
# * <tt>:high_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
80
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.inclusion')</tt>
|
81
|
-
#
|
82
|
-
# Example:
|
83
|
-
# should_ensure_value_in_range :age, (0..100)
|
84
|
-
#
|
85
|
-
def should_ensure_value_in_range(attribute, range, opts = {})
|
86
|
-
low_message, high_message = get_options!([opts], :low_message, :high_message)
|
87
|
-
low_message ||= default_error_message(:inclusion)
|
88
|
-
high_message ||= default_error_message(:inclusion)
|
89
|
-
|
90
|
-
klass = model_class
|
91
|
-
min = range.first
|
92
|
-
max = range.last
|
93
|
-
|
94
|
-
it "should not allow #{attribute} to be less than #{min}" do
|
95
|
-
v = min - 1
|
96
|
-
assert_bad_value(klass, attribute, v, low_message).should be_true
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should allow #{attribute} to be #{min}" do
|
100
|
-
v = min
|
101
|
-
assert_good_value(klass, attribute, v, low_message).should be_true
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should not allow #{attribute} to be more than #{max}" do
|
105
|
-
v = max + 1
|
106
|
-
assert_bad_value(klass, attribute, v, high_message).should be_true
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should allow #{attribute} to be #{max}" do
|
110
|
-
v = max
|
111
|
-
assert_good_value(klass, attribute, v, high_message).should be_true
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
class HaveClassMethods
|
6
|
-
include Remarkable::Private
|
7
|
-
|
8
|
-
def initialize(*methods)
|
9
|
-
get_options!(methods)
|
10
|
-
@methods = methods
|
11
|
-
end
|
12
|
-
|
13
|
-
def matches?(klass)
|
14
|
-
@klass = klass
|
15
|
-
|
16
|
-
begin
|
17
|
-
@methods.each do |method|
|
18
|
-
unless klass.respond_to?(method)
|
19
|
-
fail "#{klass.name} does not have class method #{method}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
true
|
24
|
-
rescue Exception => e
|
25
|
-
false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def description
|
30
|
-
"respond to class method #{pretty_method_names}"
|
31
|
-
end
|
32
|
-
|
33
|
-
def failure_message
|
34
|
-
@failure_message || "expected that #{pretty_method_names} #{@methods.size > 1 ? "is" : "are"} defined on #{@klass.name}, but it didn't"
|
35
|
-
end
|
36
|
-
|
37
|
-
def negative_failure_message
|
38
|
-
"expected that #{pretty_method_names} #{@methods.size > 1 ? "aren't" : "isn't"} defined on #{@klass.name}, but it did"
|
39
|
-
end
|
40
|
-
|
41
|
-
def pretty_method_names
|
42
|
-
@methods.map { |m| "##{m}" }.to_sentence
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Ensure that the given class methods are defined on the model.
|
47
|
-
#
|
48
|
-
# it { User.should have_class_methods(:find, :destroy) }
|
49
|
-
#
|
50
|
-
def have_class_methods(*methods)
|
51
|
-
Remarkable::Syntax::RSpec::HaveClassMethods.new(*methods)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
module Shoulda
|
56
|
-
# Ensure that the given class methods are defined on the model.
|
57
|
-
#
|
58
|
-
# should_have_class_methods :find, :destroy
|
59
|
-
#
|
60
|
-
def should_have_class_methods(*methods)
|
61
|
-
get_options!(methods)
|
62
|
-
klass = model_class
|
63
|
-
methods.each do |method|
|
64
|
-
it "should respond to class method ##{method}" do
|
65
|
-
unless klass.respond_to?(method)
|
66
|
-
fail_with "#{klass.name} does not have class method #{method}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
class HaveInstanceMethods
|
6
|
-
include Remarkable::Private
|
7
|
-
|
8
|
-
def initialize(*methods)
|
9
|
-
get_options!(methods)
|
10
|
-
@methods = methods
|
11
|
-
end
|
12
|
-
|
13
|
-
def matches?(klass)
|
14
|
-
@klass = klass
|
15
|
-
|
16
|
-
begin
|
17
|
-
@methods.each do |method|
|
18
|
-
unless klass.new.respond_to?(method)
|
19
|
-
fail "#{klass.name} does not have instance method #{method}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
true
|
24
|
-
rescue Exception => e
|
25
|
-
false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def description
|
30
|
-
"respond to instance method #{pretty_method_names}"
|
31
|
-
end
|
32
|
-
|
33
|
-
def failure_message
|
34
|
-
@failure_message || "expected that #{pretty_method_names} #{@methods.size > 1 ? "is" : "are"} defined on #{@klass.name}, but it didn't"
|
35
|
-
end
|
36
|
-
|
37
|
-
def negative_failure_message
|
38
|
-
"expected that #{pretty_method_names} #{@methods.size > 1 ? "aren't" : "isn't"} defined on #{@klass.name}, but it did"
|
39
|
-
end
|
40
|
-
|
41
|
-
def pretty_method_names
|
42
|
-
@methods.map { |m| "##{m}" }.to_sentence
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Ensure that the given instance methods are defined on the model.
|
47
|
-
#
|
48
|
-
# it { User.should have_instance_methods(:email, :name, :name=) }
|
49
|
-
#
|
50
|
-
def have_instance_methods(*methods)
|
51
|
-
Remarkable::Syntax::RSpec::HaveInstanceMethods.new(*methods)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
module Shoulda
|
56
|
-
# Ensure that the given instance methods are defined on the model.
|
57
|
-
#
|
58
|
-
# should_have_instance_methods :email, :name, :name=
|
59
|
-
#
|
60
|
-
def should_have_instance_methods(*methods)
|
61
|
-
get_options!(methods)
|
62
|
-
klass = model_class
|
63
|
-
methods.each do |method|
|
64
|
-
it "should respond to instance method ##{method}" do
|
65
|
-
unless klass.new.respond_to?(method)
|
66
|
-
fail_with "#{klass.name} does not have instance method #{method}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|