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,146 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
class RequireUniqueAttributes
|
6
|
-
include Remarkable::Private
|
7
|
-
|
8
|
-
def initialize(*attributes)
|
9
|
-
@message, scope = get_options!(attributes, :message, :scoped_to)
|
10
|
-
@scope = [*scope].compact
|
11
|
-
@message ||= default_error_message(:taken)
|
12
|
-
|
13
|
-
@attributes = attributes
|
14
|
-
end
|
15
|
-
|
16
|
-
def matches?(klass)
|
17
|
-
@klass = klass
|
18
|
-
|
19
|
-
begin
|
20
|
-
@attributes.each do |attribute|
|
21
|
-
attribute = attribute.to_sym
|
22
|
-
|
23
|
-
existing = klass.find(:first)
|
24
|
-
fail("Can't find first #{klass}") unless existing
|
25
|
-
|
26
|
-
object = klass.new
|
27
|
-
existing_value = existing.send(attribute)
|
28
|
-
|
29
|
-
if !@scope.blank?
|
30
|
-
@scope.each do |s|
|
31
|
-
fail("#{klass.name} doesn't seem to have a #{s} attribute.") unless object.respond_to?(:"#{s}=")
|
32
|
-
object.send("#{s}=", existing.send(s))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
return false unless assert_bad_value(object, attribute, existing_value, @message)
|
36
|
-
|
37
|
-
# Now test that the object is valid when changing the scoped attribute
|
38
|
-
# TODO: There is a chance that we could change the scoped field
|
39
|
-
# to a value that's already taken. An alternative implementation
|
40
|
-
# could actually find all values for scope and create a unique
|
41
|
-
# one.
|
42
|
-
if !@scope.blank?
|
43
|
-
@scope.each do |s|
|
44
|
-
# Assume the scope is a foreign key if the field is nil
|
45
|
-
object.send("#{s}=", existing.send(s).nil? ? 1 : existing.send(s).next)
|
46
|
-
return false unless assert_good_value(object, attribute, existing_value, @message)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
true
|
52
|
-
rescue Exception => e
|
53
|
-
false
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def description
|
58
|
-
"require unique value for #{@attributes.to_sentence}#{" scoped to #{@scope.to_sentence}" unless @scope.blank?}"
|
59
|
-
end
|
60
|
-
|
61
|
-
def failure_message
|
62
|
-
@failure_message || "expected that the #{@klass.name} cannot be saved if #{@attributes.to_sentence}#{" scoped to #{@scope.to_sentence}" unless @scope.blank?} is not unique, but it did"
|
63
|
-
end
|
64
|
-
|
65
|
-
def negative_failure_message
|
66
|
-
"expected that the #{@klass.name} can be saved if #{@attributes.to_sentence}#{" scoped to #{@scope.to_sentence}" unless @scope.blank?} is not unique, but it didn't"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Ensures that the model cannot be saved if one of the attributes listed is not unique.
|
71
|
-
# Requires an existing record
|
72
|
-
#
|
73
|
-
# Options:
|
74
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
75
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.taken')</tt>
|
76
|
-
# * <tt>:scoped_to</tt> - field(s) to scope the uniqueness to.
|
77
|
-
#
|
78
|
-
# Examples:
|
79
|
-
# should_require_unique_attributes :keyword, :username
|
80
|
-
# should_require_unique_attributes :name, :message => "O NOES! SOMEONE STOELED YER NAME!"
|
81
|
-
# should_require_unique_attributes :email, :scoped_to => :name
|
82
|
-
# should_require_unique_attributes :address, :scoped_to => [:first_name, :last_name]
|
83
|
-
#
|
84
|
-
def require_unique_attributes(*attributes)
|
85
|
-
Remarkable::Syntax::RSpec::RequireUniqueAttributes.new(*attributes)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
module Shoulda
|
90
|
-
# Ensures that the model cannot be saved if one of the attributes listed is not unique.
|
91
|
-
# Requires an existing record
|
92
|
-
#
|
93
|
-
# Options:
|
94
|
-
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
|
95
|
-
# Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.taken')</tt>
|
96
|
-
# * <tt>:scoped_to</tt> - field(s) to scope the uniqueness to.
|
97
|
-
#
|
98
|
-
# Examples:
|
99
|
-
# should_require_unique_attributes :keyword, :username
|
100
|
-
# should_require_unique_attributes :name, :message => "O NOES! SOMEONE STOELED YER NAME!"
|
101
|
-
# should_require_unique_attributes :email, :scoped_to => :name
|
102
|
-
# should_require_unique_attributes :address, :scoped_to => [:first_name, :last_name]
|
103
|
-
#
|
104
|
-
def should_require_unique_attributes(*attributes)
|
105
|
-
message, scope = get_options!(attributes, :message, :scoped_to)
|
106
|
-
scope = [*scope].compact
|
107
|
-
message ||= default_error_message(:taken)
|
108
|
-
|
109
|
-
klass = model_class
|
110
|
-
attributes.each do |attribute|
|
111
|
-
attribute = attribute.to_sym
|
112
|
-
it "should require unique value for #{attribute}#{" scoped to #{scope.join(', ')}" unless scope.blank?}" do
|
113
|
-
existing = klass.find(:first)
|
114
|
-
fail_with("Can't find first #{klass}") unless existing
|
115
|
-
object = klass.new
|
116
|
-
existing_value = existing.send(attribute)
|
117
|
-
|
118
|
-
if !scope.blank?
|
119
|
-
scope.each do |s|
|
120
|
-
unless object.respond_to?(:"#{s}=")
|
121
|
-
fail_with "#{klass.name} doesn't seem to have a #{s} attribute."
|
122
|
-
end
|
123
|
-
object.send("#{s}=", existing.send(s))
|
124
|
-
end
|
125
|
-
end
|
126
|
-
assert_bad_value(object, attribute, existing_value, message).should be_true
|
127
|
-
|
128
|
-
# Now test that the object is valid when changing the scoped attribute
|
129
|
-
# TODO: There is a chance that we could change the scoped field
|
130
|
-
# to a value that's already taken. An alternative implementation
|
131
|
-
# could actually find all values for scope and create a unique
|
132
|
-
# one.
|
133
|
-
if !scope.blank?
|
134
|
-
scope.each do |s|
|
135
|
-
# Assume the scope is a foreign key if the field is nil
|
136
|
-
object.send("#{s}=", existing.send(s).nil? ? 1 : existing.send(s).next)
|
137
|
-
assert_good_value(object, attribute, existing_value, message).should be_true
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
146
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
# Macro that creates a test asserting that the controller assigned to
|
6
|
-
# each of the named instance variable(s).
|
7
|
-
#
|
8
|
-
# Options:
|
9
|
-
# * <tt>:class</tt> - The expected class of the instance variable being checked.
|
10
|
-
# * <tt>:equals</tt> - A string which is evaluated and compared for equality with
|
11
|
-
# the instance variable being checked.
|
12
|
-
#
|
13
|
-
# Example:
|
14
|
-
#
|
15
|
-
# it { should assign_to(:user, :posts) }
|
16
|
-
# it { should assign_to(:user, :class => User) }
|
17
|
-
# it { should assign_to(:user, :equals => '@user') }
|
18
|
-
#
|
19
|
-
def assign_to(*names)
|
20
|
-
opts = names.extract_options!
|
21
|
-
test_name = "assign @#{names.to_sentence}"
|
22
|
-
test_name << " as class #{opts[:class]}" if opts[:class]
|
23
|
-
test_name << " which is equal to #{opts[:equals]}" if opts[:equals]
|
24
|
-
|
25
|
-
simple_matcher test_name do |controller, matcher|
|
26
|
-
ret = true
|
27
|
-
names.each do |name|
|
28
|
-
assigned_value = assigns(name.to_sym)
|
29
|
-
|
30
|
-
unless assigned_value
|
31
|
-
ret = false
|
32
|
-
break
|
33
|
-
end
|
34
|
-
|
35
|
-
if opts[:class]
|
36
|
-
unless assigned_value.kind_of?(opts[:class])
|
37
|
-
ret = false
|
38
|
-
break
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
if opts[:equals]
|
43
|
-
instantiate_variables_from_assigns do
|
44
|
-
expected_value = eval(opts[:equals], self.send(:binding), __FILE__, __LINE__)
|
45
|
-
unless assigned_value == expected_value
|
46
|
-
ret = false
|
47
|
-
break
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
ret
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
module Shoulda
|
59
|
-
# Macro that creates a test asserting that the controller assigned to
|
60
|
-
# each of the named instance variable(s).
|
61
|
-
#
|
62
|
-
# Options:
|
63
|
-
# * <tt>:class</tt> - The expected class of the instance variable being checked.
|
64
|
-
# * <tt>:equals</tt> - A string which is evaluated and compared for equality with
|
65
|
-
# the instance variable being checked.
|
66
|
-
#
|
67
|
-
# Example:
|
68
|
-
#
|
69
|
-
# should_assign_to :user, :posts
|
70
|
-
# should_assign_to :user, :class => User
|
71
|
-
# should_assign_to :user, :equals => '@user'
|
72
|
-
#
|
73
|
-
def should_assign_to(*names)
|
74
|
-
opts = names.extract_options!
|
75
|
-
names.each do |name|
|
76
|
-
test_name = "should assign @#{name}"
|
77
|
-
test_name << " as class #{opts[:class]}" if opts[:class]
|
78
|
-
test_name << " which is equal to #{opts[:equals]}" if opts[:equals]
|
79
|
-
it test_name do
|
80
|
-
assigned_value = assigns(name.to_sym)
|
81
|
-
assigned_value.should_not be_nil
|
82
|
-
assigned_value.should be_a_kind_of(opts[:class]) if opts[:class]
|
83
|
-
if opts[:equals]
|
84
|
-
instantiate_variables_from_assigns do
|
85
|
-
expected_value = eval(opts[:equals], self.send(:binding), __FILE__, __LINE__)
|
86
|
-
assigned_value.should == expected_value
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# Macro that creates a test asserting that the controller did not assign to
|
94
|
-
# any of the named instance variable(s).
|
95
|
-
#
|
96
|
-
# Example:
|
97
|
-
#
|
98
|
-
# should_not_assign_to :user, :posts
|
99
|
-
#
|
100
|
-
def should_not_assign_to(*names)
|
101
|
-
names.each do |name|
|
102
|
-
it "should not assign to @#{name}" do
|
103
|
-
assigns(name.to_sym).should be_nil
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
# Macro that creates a test asserting that filter_parameter_logging
|
6
|
-
# is set for the specified keys
|
7
|
-
#
|
8
|
-
# Example:
|
9
|
-
#
|
10
|
-
# should_filter_params :password, :ssn
|
11
|
-
#
|
12
|
-
def filter_params(*keys)
|
13
|
-
simple_matcher "filter #{keys.to_sentence}" do
|
14
|
-
ret = true
|
15
|
-
keys.each do |key|
|
16
|
-
if controller.respond_to?(:filter_parameters)
|
17
|
-
filtered = controller.send(:filter_parameters, {key.to_s => key.to_s})
|
18
|
-
unless filtered[key.to_s] == '[FILTERED]'
|
19
|
-
ret = false
|
20
|
-
break
|
21
|
-
end
|
22
|
-
else
|
23
|
-
ret = false
|
24
|
-
break
|
25
|
-
end
|
26
|
-
end
|
27
|
-
ret
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
module Shoulda
|
33
|
-
# Macro that creates a test asserting that filter_parameter_logging
|
34
|
-
# is set for the specified keys
|
35
|
-
#
|
36
|
-
# Example:
|
37
|
-
#
|
38
|
-
# should_filter_params :password, :ssn
|
39
|
-
#
|
40
|
-
def should_filter_params(*keys)
|
41
|
-
keys.each do |key|
|
42
|
-
it "should filter #{key}" do
|
43
|
-
controller.should respond_to(:filter_parameters)
|
44
|
-
filtered = controller.send(:filter_parameters, {key.to_s => key.to_s})
|
45
|
-
filtered[key.to_s].should == '[FILTERED]'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module Shoulda
|
5
|
-
# Macro that creates a test asserting that the controller returned a redirect to the given path.
|
6
|
-
# The given string is evaled to produce the resulting redirect path. All of the instance variables
|
7
|
-
# set by the controller are available to the evaled string.
|
8
|
-
# Example:
|
9
|
-
#
|
10
|
-
# should_redirect_to '"/"'
|
11
|
-
# should_redirect_to "user_url(@user)"
|
12
|
-
# should_redirect_to "users_url"
|
13
|
-
#
|
14
|
-
def should_redirect_to(url)
|
15
|
-
it "should redirect to #{url.inspect}" do
|
16
|
-
instantiate_variables_from_assigns do
|
17
|
-
response.should redirect_to(eval(url, self.send(:binding), __FILE__, __LINE__))
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
# Macro that creates a test asserting that the rendered view contains a <form> element.
|
6
|
-
def render_a_form
|
7
|
-
simple_matcher "should display a form" do |controller|
|
8
|
-
controller.response.should have_tag("form")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module Shoulda
|
14
|
-
# Macro that creates a test asserting that the rendered view contains a <form> element.
|
15
|
-
def should_render_a_form
|
16
|
-
it "should display a form" do
|
17
|
-
response.should have_tag("form")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module Shoulda
|
5
|
-
# Macro that creates a test asserting that the controller rendered the given template.
|
6
|
-
# Example:
|
7
|
-
#
|
8
|
-
# should_render_template :new
|
9
|
-
#
|
10
|
-
def should_render_template(template)
|
11
|
-
it "should render template #{template.inspect}" do
|
12
|
-
response.should render_template(template.to_s)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
# Macro that creates a test asserting that the controller rendered with the given layout.
|
6
|
-
# Example:
|
7
|
-
#
|
8
|
-
# it { should render_with_layout('special') }
|
9
|
-
# it { should render_with_layout(:special) }
|
10
|
-
#
|
11
|
-
def render_with_layout(expected_layout = 'application')
|
12
|
-
if expected_layout
|
13
|
-
simple_matcher "render with #{expected_layout.inspect} layout" do |controller|
|
14
|
-
response_layout = response.layout.blank? ? "" : response.layout.split('/').last
|
15
|
-
response_layout.should == expected_layout.to_s
|
16
|
-
end
|
17
|
-
else
|
18
|
-
simple_matcher "render without layout" do
|
19
|
-
response.layout.should be_nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Macro that creates a test asserting that the controller rendered without a layout.
|
25
|
-
# Same as @it { should render_with_layout(false) }@
|
26
|
-
def render_without_layout
|
27
|
-
simple_matcher "render without layout" do |controller|
|
28
|
-
controller.should render_with_layout(nil)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
module Shoulda
|
34
|
-
# Macro that creates a test asserting that the controller rendered with the given layout.
|
35
|
-
# Example:
|
36
|
-
#
|
37
|
-
# should_render_with_layout 'special'
|
38
|
-
# should_render_with_layout :special
|
39
|
-
#
|
40
|
-
def should_render_with_layout(expected_layout = 'application')
|
41
|
-
if expected_layout
|
42
|
-
it "should render with #{expected_layout.inspect} layout" do
|
43
|
-
response_layout = response.layout.blank? ? "" : response.layout.split('/').last
|
44
|
-
response_layout.should == expected_layout.to_s
|
45
|
-
end
|
46
|
-
else
|
47
|
-
it "should render without layout" do
|
48
|
-
response.layout.should be_nil
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Macro that creates a test asserting that the controller rendered without a layout.
|
54
|
-
# Same as @should_render_with_layout false@
|
55
|
-
def should_render_without_layout
|
56
|
-
should_render_with_layout nil
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
class RespondWith
|
6
|
-
include Remarkable::Private
|
7
|
-
|
8
|
-
def initialize(response, type)
|
9
|
-
@response = response
|
10
|
-
@type = type
|
11
|
-
end
|
12
|
-
|
13
|
-
def matches?(controller)
|
14
|
-
@controller = controller
|
15
|
-
|
16
|
-
begin
|
17
|
-
if [ :success, :missing, :redirect, :error ].include?(@type) && @response.send("#{@type}?")
|
18
|
-
elsif @type.is_a?(Fixnum) && @response.response_code == @type
|
19
|
-
elsif @type.is_a?(Symbol) && @response.response_code == ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[@type]
|
20
|
-
else
|
21
|
-
if @response.error?
|
22
|
-
exception = @response.template.instance_variable_get(:@exception)
|
23
|
-
exception_message = exception && exception.message
|
24
|
-
fail "Expected response to be a #{@type}, but was #{@response.response_code}\n#{exception_message.to_s}"
|
25
|
-
else
|
26
|
-
fail "Expected response to be a #{@type}, but was #{@response.response_code}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
true
|
31
|
-
rescue Exception => e
|
32
|
-
false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def description
|
37
|
-
"respond with #{@type}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def failure_message
|
41
|
-
@failure_message || "expected respond with #{@type}, but it didn't"
|
42
|
-
end
|
43
|
-
|
44
|
-
def negative_failure_message
|
45
|
-
"expected not respond with #{@type}, but it did"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Macro that creates a test asserting that the controller responded with a 'response' status code.
|
50
|
-
# Example:
|
51
|
-
#
|
52
|
-
# it { should respond_with(:success) }
|
53
|
-
#
|
54
|
-
def respond_with(type)
|
55
|
-
Remarkable::Syntax::RSpec::RespondWith.new(response, type)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
module Shoulda
|
60
|
-
# Macro that creates a test asserting that the controller responded with a 'response' status code.
|
61
|
-
# Example:
|
62
|
-
#
|
63
|
-
# should_respond_with :success
|
64
|
-
#
|
65
|
-
def should_respond_with(type)
|
66
|
-
it "should respond with #{type}" do
|
67
|
-
clean_backtrace do
|
68
|
-
if [ :success, :missing, :redirect, :error ].include?(type) && response.send("#{type}?")
|
69
|
-
elsif type.is_a?(Fixnum) && response.response_code == type
|
70
|
-
elsif type.is_a?(Symbol) && response.response_code == ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[type]
|
71
|
-
else
|
72
|
-
if response.error?
|
73
|
-
exception = response.template.instance_variable_get(:@exception)
|
74
|
-
exception_message = exception && exception.message
|
75
|
-
Spec::Expectations.fail_with "Expected response to be a #{type}, but was #{response.response_code}\n#{exception_message.to_s}"
|
76
|
-
else
|
77
|
-
Spec::Expectations.fail_with "Expected response to be a #{type}, but was #{response.response_code}"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
# Macro that creates a test asserting that the response content type was 'content_type'.
|
6
|
-
# Example:
|
7
|
-
#
|
8
|
-
# should_respond_with_content_type 'application/rss+xml'
|
9
|
-
# should_respond_with_content_type :rss
|
10
|
-
# should_respond_with_content_type /rss/
|
11
|
-
#
|
12
|
-
def respond_with_content_type(content_type)
|
13
|
-
simple_matcher "respond with content type of #{content_type}" do
|
14
|
-
content_type = Mime::EXTENSION_LOOKUP[content_type.to_s].to_s if content_type.is_a? Symbol
|
15
|
-
if content_type.is_a? Regexp
|
16
|
-
response.content_type =~ content_type
|
17
|
-
else
|
18
|
-
response.content_type == content_type
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module Shoulda
|
25
|
-
# Macro that creates a test asserting that the response content type was 'content_type'.
|
26
|
-
# Example:
|
27
|
-
#
|
28
|
-
# should_respond_with_content_type 'application/rss+xml'
|
29
|
-
# should_respond_with_content_type :rss
|
30
|
-
# should_respond_with_content_type /rss/
|
31
|
-
#
|
32
|
-
def should_respond_with_content_type(content_type)
|
33
|
-
it "should respond with content type of #{content_type}" do
|
34
|
-
content_type = Mime::EXTENSION_LOOKUP[content_type.to_s].to_s if content_type.is_a? Symbol
|
35
|
-
if content_type.is_a? Regexp
|
36
|
-
response.content_type.should match(content_type)
|
37
|
-
else
|
38
|
-
response.content_type.should == content_type
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Remarkable
|
2
|
-
module Syntax
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
# Macro that creates a test asserting that a value returned from the session is correct.
|
6
|
-
# The given string is evaled to produce the resulting redirect path. All of the instance variables
|
7
|
-
# set by the controller are available to the evaled string.
|
8
|
-
# Example:
|
9
|
-
#
|
10
|
-
# should_return_from_session :user_id, '@user.id'
|
11
|
-
# should_return_from_session :message, '"Free stuff"'
|
12
|
-
#
|
13
|
-
def return_from_session(key, expected)
|
14
|
-
simple_matcher "return the correct value from the session for key #{key}" do
|
15
|
-
ret = true
|
16
|
-
instantiate_variables_from_assigns do
|
17
|
-
expected_value = eval(expected, self.send(:binding), __FILE__, __LINE__)
|
18
|
-
ret = (session[key] == expected_value)
|
19
|
-
end
|
20
|
-
ret
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module Shoulda
|
26
|
-
# Macro that creates a test asserting that a value returned from the session is correct.
|
27
|
-
# The given string is evaled to produce the resulting redirect path. All of the instance variables
|
28
|
-
# set by the controller are available to the evaled string.
|
29
|
-
# Example:
|
30
|
-
#
|
31
|
-
# should_return_from_session :user_id, '@user.id'
|
32
|
-
# should_return_from_session :message, '"Free stuff"'
|
33
|
-
#
|
34
|
-
def should_return_from_session(key, expected)
|
35
|
-
it "should return the correct value from the session for key #{key}" do
|
36
|
-
instantiate_variables_from_assigns do
|
37
|
-
expected_value = eval(expected, self.send(:binding), __FILE__, __LINE__)
|
38
|
-
session[key].should == expected_value
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|