carlosbrando-remarkable 0.0.99

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +124 -0
  3. data/PostInstall.txt +7 -0
  4. data/README.rdoc +48 -0
  5. data/Rakefile +29 -0
  6. data/init.rb +1 -0
  7. data/lib/remarkable.rb +13 -0
  8. data/lib/remarkable/active_record/active_record.rb +21 -0
  9. data/lib/remarkable/active_record/helpers.rb +16 -0
  10. data/lib/remarkable/active_record/macros/associations/belong_to.rb +81 -0
  11. data/lib/remarkable/active_record/macros/associations/have_and_belong_to_many.rb +77 -0
  12. data/lib/remarkable/active_record/macros/associations/have_many.rb +160 -0
  13. data/lib/remarkable/active_record/macros/associations/have_one.rb +133 -0
  14. data/lib/remarkable/active_record/macros/database/have_db_column.rb +81 -0
  15. data/lib/remarkable/active_record/macros/database/have_db_columns.rb +73 -0
  16. data/lib/remarkable/active_record/macros/database/have_indices.rb +75 -0
  17. data/lib/remarkable/active_record/macros/validations/allow_values_for.rb +103 -0
  18. data/lib/remarkable/active_record/macros/validations/ensure_length_at_least.rb +97 -0
  19. data/lib/remarkable/active_record/macros/validations/ensure_length_in_range.rb +134 -0
  20. data/lib/remarkable/active_record/macros/validations/ensure_length_is.rb +106 -0
  21. data/lib/remarkable/active_record/macros/validations/ensure_value_in_range.rb +117 -0
  22. data/lib/remarkable/active_record/macros/validations/have_class_methods.rb +74 -0
  23. data/lib/remarkable/active_record/macros/validations/have_instance_methods.rb +74 -0
  24. data/lib/remarkable/active_record/macros/validations/have_named_scope.rb +148 -0
  25. data/lib/remarkable/active_record/macros/validations/have_readonly_attributes.rb +81 -0
  26. data/lib/remarkable/active_record/macros/validations/only_allow_numeric_values_for.rb +89 -0
  27. data/lib/remarkable/active_record/macros/validations/protect_attributes.rb +89 -0
  28. data/lib/remarkable/active_record/macros/validations/require_acceptance_of.rb +94 -0
  29. data/lib/remarkable/active_record/macros/validations/require_attributes.rb +94 -0
  30. data/lib/remarkable/active_record/macros/validations/require_unique_attributes.rb +146 -0
  31. data/lib/remarkable/controller/controller.rb +15 -0
  32. data/lib/remarkable/controller/helpers.rb +48 -0
  33. data/lib/remarkable/controller/macros/assign_to.rb +110 -0
  34. data/lib/remarkable/controller/macros/filter_params.rb +52 -0
  35. data/lib/remarkable/controller/macros/redirect_to.rb +24 -0
  36. data/lib/remarkable/controller/macros/render_a_form.rb +23 -0
  37. data/lib/remarkable/controller/macros/render_template.rb +18 -0
  38. data/lib/remarkable/controller/macros/render_with_layout.rb +61 -0
  39. data/lib/remarkable/controller/macros/respond_with.rb +86 -0
  40. data/lib/remarkable/controller/macros/respond_with_content_type.rb +45 -0
  41. data/lib/remarkable/controller/macros/return_from_session.rb +45 -0
  42. data/lib/remarkable/controller/macros/route.rb +91 -0
  43. data/lib/remarkable/controller/macros/set_the_flash_to.rb +58 -0
  44. data/lib/remarkable/example/example_methods.rb +32 -0
  45. data/lib/remarkable/private_helpers.rb +123 -0
  46. data/rails/init.rb +1 -0
  47. data/script/console +10 -0
  48. data/script/destroy +14 -0
  49. data/script/generate +14 -0
  50. data/spec/controllers/posts_controller_spec.rb +166 -0
  51. data/spec/controllers/users_controller_spec.rb +14 -0
  52. data/spec/fixtures/addresses.yml +3 -0
  53. data/spec/fixtures/friendships.yml +0 -0
  54. data/spec/fixtures/posts.yml +5 -0
  55. data/spec/fixtures/products.yml +0 -0
  56. data/spec/fixtures/taggings.yml +0 -0
  57. data/spec/fixtures/tags.yml +9 -0
  58. data/spec/fixtures/users.yml +6 -0
  59. data/spec/models/address_spec.rb +21 -0
  60. data/spec/models/dog_spec.rb +17 -0
  61. data/spec/models/flea_spec.rb +9 -0
  62. data/spec/models/friendship_spec.rb +13 -0
  63. data/spec/models/post_spec.rb +35 -0
  64. data/spec/models/product_spec.rb +57 -0
  65. data/spec/models/tag_spec.rb +21 -0
  66. data/spec/models/tagging_spec.rb +13 -0
  67. data/spec/models/user_spec.rb +107 -0
  68. data/spec/rails_root/app/controllers/application.rb +25 -0
  69. data/spec/rails_root/app/controllers/posts_controller.rb +85 -0
  70. data/spec/rails_root/app/controllers/users_controller.rb +84 -0
  71. data/spec/rails_root/app/helpers/application_helper.rb +3 -0
  72. data/spec/rails_root/app/helpers/posts_helper.rb +2 -0
  73. data/spec/rails_root/app/helpers/users_helper.rb +2 -0
  74. data/spec/rails_root/app/models/address.rb +7 -0
  75. data/spec/rails_root/app/models/dog.rb +5 -0
  76. data/spec/rails_root/app/models/flea.rb +3 -0
  77. data/spec/rails_root/app/models/friendship.rb +4 -0
  78. data/spec/rails_root/app/models/post.rb +12 -0
  79. data/spec/rails_root/app/models/product.rb +12 -0
  80. data/spec/rails_root/app/models/tag.rb +8 -0
  81. data/spec/rails_root/app/models/tagging.rb +4 -0
  82. data/spec/rails_root/app/models/user.rb +28 -0
  83. data/spec/rails_root/app/views/layouts/posts.rhtml +17 -0
  84. data/spec/rails_root/app/views/layouts/users.rhtml +17 -0
  85. data/spec/rails_root/app/views/layouts/wide.html.erb +1 -0
  86. data/spec/rails_root/app/views/posts/edit.rhtml +27 -0
  87. data/spec/rails_root/app/views/posts/index.rhtml +25 -0
  88. data/spec/rails_root/app/views/posts/new.rhtml +26 -0
  89. data/spec/rails_root/app/views/posts/show.rhtml +18 -0
  90. data/spec/rails_root/app/views/users/edit.rhtml +22 -0
  91. data/spec/rails_root/app/views/users/index.rhtml +22 -0
  92. data/spec/rails_root/app/views/users/new.rhtml +21 -0
  93. data/spec/rails_root/app/views/users/show.rhtml +13 -0
  94. data/spec/rails_root/config/boot.rb +109 -0
  95. data/spec/rails_root/config/database.yml +4 -0
  96. data/spec/rails_root/config/environment.rb +14 -0
  97. data/spec/rails_root/config/environments/sqlite3.rb +0 -0
  98. data/spec/rails_root/config/initializers/new_rails_defaults.rb +15 -0
  99. data/spec/rails_root/config/initializers/shoulda.rb +8 -0
  100. data/spec/rails_root/config/routes.rb +6 -0
  101. data/spec/rails_root/db/migrate/001_create_users.rb +18 -0
  102. data/spec/rails_root/db/migrate/002_create_posts.rb +13 -0
  103. data/spec/rails_root/db/migrate/003_create_taggings.rb +12 -0
  104. data/spec/rails_root/db/migrate/004_create_tags.rb +11 -0
  105. data/spec/rails_root/db/migrate/005_create_dogs.rb +12 -0
  106. data/spec/rails_root/db/migrate/006_create_addresses.rb +14 -0
  107. data/spec/rails_root/db/migrate/007_create_fleas.rb +11 -0
  108. data/spec/rails_root/db/migrate/008_create_dogs_fleas.rb +12 -0
  109. data/spec/rails_root/db/migrate/009_create_products.rb +17 -0
  110. data/spec/rails_root/db/migrate/010_create_friendships.rb +14 -0
  111. data/spec/rails_root/db/schema.rb +0 -0
  112. data/spec/rails_root/log/.keep +0 -0
  113. data/spec/rails_root/public/.htaccess +40 -0
  114. data/spec/rails_root/public/404.html +30 -0
  115. data/spec/rails_root/public/422.html +30 -0
  116. data/spec/rails_root/public/500.html +30 -0
  117. data/spec/rails_root/script/console +3 -0
  118. data/spec/rails_root/script/generate +3 -0
  119. data/spec/rails_root/vendor/plugins/.keep +0 -0
  120. data/spec/rcov.opts +2 -0
  121. data/spec/spec.opts +4 -0
  122. data/spec/spec_helper.rb +58 -0
  123. data/tasks/rspec.rake +21 -0
  124. metadata +216 -0
@@ -0,0 +1,74 @@
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
@@ -0,0 +1,74 @@
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
@@ -0,0 +1,148 @@
1
+ module Remarkable
2
+ module Syntax
3
+
4
+ module RSpec
5
+ class HaveNamedScope
6
+ def initialize(scope_call, *args)
7
+ @scope_opts = args.extract_options!
8
+ @scope_call = scope_call.to_s
9
+ @args = args
10
+ end
11
+
12
+ def matches?(klass)
13
+ @klass = klass
14
+
15
+ begin
16
+ scope = eval("#{klass}.#{@scope_call}")
17
+
18
+ unless scope.class == ::ActiveRecord::NamedScope::Scope
19
+ fail "#{@scope_call} didn't return a scope object"
20
+ end
21
+
22
+ unless @scope_opts.empty?
23
+ unless scope.proxy_options == @scope_opts
24
+ fail "#{klass.name} didn't scope itself to #{@scope_opts.inspect}"
25
+ end
26
+ end
27
+
28
+ true
29
+ rescue Exception => e
30
+ false
31
+ end
32
+ end
33
+
34
+ def description
35
+ "have to scope itself to #{@scope_opts.inspect} when #{@scope_call} is called"
36
+ end
37
+
38
+ def failure_message
39
+ @failure_message || "expected that #{klass.name} has a method named #{@scope_call} that returns a NamedScope object with the proxy options set to the options you supply, but it didn't"
40
+ end
41
+
42
+ def negative_failure_message
43
+ "expected that #{klass.name} hasn't a method named #{@scope_call} that returns a NamedScope object with the proxy options set to the options you supply, but it did"
44
+ end
45
+ end
46
+
47
+ # Ensures that the model has a method named scope_name that returns a NamedScope object with the
48
+ # proxy options set to the options you supply. scope_name can be either a symbol, or a method
49
+ # call which will be evaled against the model. The eval'd method call has access to all the same
50
+ # instance variables that a should statement would.
51
+ #
52
+ # Options: Any of the options that the named scope would pass on to find.
53
+ #
54
+ # Example:
55
+ #
56
+ # it { User.should have_named_scope(:visible, :conditions => {:visible => true}) }
57
+ #
58
+ # Passes for
59
+ #
60
+ # named_scope :visible, :conditions => {:visible => true}
61
+ #
62
+ # Or for
63
+ #
64
+ # def self.visible
65
+ # scoped(:conditions => {:visible => true})
66
+ # end
67
+ #
68
+ # You can test lambdas or methods that return ActiveRecord#scoped calls:
69
+ #
70
+ # it { User.should have_named_scope('recent(5)', :limit => 5) }
71
+ # it { User.should have_named_scope('recent(1)', :limit => 1) }
72
+ #
73
+ # Passes for
74
+ # named_scope :recent, lambda {|c| {:limit => c}}
75
+ #
76
+ # Or for
77
+ #
78
+ # def self.recent(c)
79
+ # scoped(:limit => c)
80
+ # end
81
+ #
82
+ def have_named_scope(scope_call, *args)
83
+ Remarkable::Syntax::RSpec::HaveNamedScope.new(scope_call, *args)
84
+ end
85
+ end
86
+
87
+ module Shoulda
88
+ # Ensures that the model has a method named scope_name that returns a NamedScope object with the
89
+ # proxy options set to the options you supply. scope_name can be either a symbol, or a method
90
+ # call which will be evaled against the model. The eval'd method call has access to all the same
91
+ # instance variables that a should statement would.
92
+ #
93
+ # Options: Any of the options that the named scope would pass on to find.
94
+ #
95
+ # Example:
96
+ #
97
+ # should_have_named_scope :visible, :conditions => {:visible => true}
98
+ #
99
+ # Passes for
100
+ #
101
+ # named_scope :visible, :conditions => {:visible => true}
102
+ #
103
+ # Or for
104
+ #
105
+ # def self.visible
106
+ # scoped(:conditions => {:visible => true})
107
+ # end
108
+ #
109
+ # You can test lambdas or methods that return ActiveRecord#scoped calls:
110
+ #
111
+ # should_have_named_scope 'recent(5)', :limit => 5
112
+ # should_have_named_scope 'recent(1)', :limit => 1
113
+ #
114
+ # Passes for
115
+ # named_scope :recent, lambda {|c| {:limit => c}}
116
+ #
117
+ # Or for
118
+ #
119
+ # def self.recent(c)
120
+ # scoped(:limit => c)
121
+ # end
122
+ #
123
+ def should_have_named_scope(scope_call, *args)
124
+ klass = model_class
125
+ scope_opts = args.extract_options!
126
+ scope_call = scope_call.to_s
127
+
128
+ describe scope_call do
129
+ before(:each) do
130
+ @scope = eval("#{klass}.#{scope_call}")
131
+ end
132
+
133
+ it "should return a scope object" do
134
+ @scope.class.should == ::ActiveRecord::NamedScope::Scope
135
+ end
136
+
137
+ unless scope_opts.empty?
138
+ it "should scope itself to #{scope_opts.inspect}" do
139
+ @scope.proxy_options.should == scope_opts
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ end
146
+
147
+ end
148
+ end
@@ -0,0 +1,81 @@
1
+ module Remarkable
2
+ module Syntax
3
+
4
+ module RSpec
5
+ class HaveReadonlyAttributes
6
+ include Remarkable::Private
7
+
8
+ def initialize(*attributes)
9
+ get_options!(attributes)
10
+ @attributes = attributes
11
+ end
12
+
13
+ def matches?(klass)
14
+ @klass = klass
15
+
16
+ begin
17
+ @attributes.each do |attribute|
18
+ attribute = attribute.to_sym
19
+ readonly = klass.readonly_attributes || []
20
+
21
+ unless readonly.include?(attribute.to_s)
22
+ fail readonly.empty? ?
23
+ "#{klass} attribute #{attribute} is not read-only" :
24
+ "#{klass} is making #{readonly.to_a.to_sentence} read-only, but not #{attribute}"
25
+ end
26
+ end
27
+
28
+ true
29
+ rescue Exception => e
30
+ false
31
+ end
32
+ end
33
+
34
+ def description
35
+ "make #{@attributes.to_sentence} read-only"
36
+ end
37
+
38
+ def failure_message
39
+ @failure_message || "expected that #{@attributes.to_sentence} cannot be changed once the record has been created, but it did"
40
+ end
41
+
42
+ def negative_failure_message
43
+ "expected that #{@attributes.to_sentence} cann be changed once the record has been created, but it didn't"
44
+ end
45
+ end
46
+
47
+ # Ensures that the attribute cannot be changed once the record has been created.
48
+ #
49
+ # it { User.should have_readonly_attributes(:password, :admin_flag) }
50
+ #
51
+ def have_readonly_attributes(*attributes)
52
+ Remarkable::Syntax::RSpec::HaveReadonlyAttributes.new(*attributes)
53
+ end
54
+ end
55
+
56
+ module Shoulda
57
+ # Ensures that the attribute cannot be changed once the record has been created.
58
+ #
59
+ # should_have_readonly_attributes :password, :admin_flag
60
+ #
61
+ def should_have_readonly_attributes(*attributes)
62
+ get_options!(attributes)
63
+ klass = model_class
64
+
65
+ attributes.each do |attribute|
66
+ attribute = attribute.to_sym
67
+ it "should make #{attribute} read-only" do
68
+ readonly = klass.readonly_attributes || []
69
+
70
+ unless readonly.include?(attribute.to_s)
71
+ fail_with(readonly.empty? ?
72
+ "#{klass} attribute #{attribute} is not read-only" :
73
+ "#{klass} is making #{readonly.to_a.to_sentence} read-only, but not #{attribute}.")
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,89 @@
1
+ module Remarkable
2
+ module Syntax
3
+
4
+ module RSpec
5
+ class OnlyAllowNumericValuesFor
6
+ include Remarkable::Private
7
+
8
+ def initialize(*attributes)
9
+ @message = get_options!(attributes, :message)
10
+ @message ||= default_error_message(:not_a_number)
11
+
12
+ @attributes = attributes
13
+ end
14
+
15
+ def matches?(klass)
16
+ @klass = klass
17
+
18
+ begin
19
+ @attributes.each do |attribute|
20
+ attribute = attribute.to_sym
21
+ return false unless assert_bad_value(klass, attribute, "abcd", @message)
22
+ end
23
+
24
+ true
25
+ rescue Exception => e
26
+ false
27
+ end
28
+ end
29
+
30
+ def description
31
+ "only allow numeric values for #{@attributes.to_sentence}"
32
+ end
33
+
34
+ def failure_message
35
+ "expected only numeric values for #{@attributes.to_sentence}, but it didn't"
36
+ end
37
+
38
+ def negative_failure_message
39
+ "expected not only numeric values for #{@attributes.to_sentence}, but it did"
40
+ end
41
+ end
42
+
43
+ # Ensure that the attribute is numeric
44
+ #
45
+ # If an instance variable has been created in the setup named after the
46
+ # model being tested, then this method will use that. Otherwise, it will
47
+ # create a new instance to test against.
48
+ #
49
+ # Options:
50
+ # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
51
+ # Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.not_a_number')</tt>
52
+ #
53
+ # Example:
54
+ # it { User.should only_allow_numeric_values_for(:age) }
55
+ #
56
+ def only_allow_numeric_values_for(*attributes)
57
+ Remarkable::Syntax::RSpec::OnlyAllowNumericValuesFor.new(*attributes)
58
+ end
59
+ end
60
+
61
+ module Shoulda
62
+ # Ensure that the attribute is numeric
63
+ #
64
+ # If an instance variable has been created in the setup named after the
65
+ # model being tested, then this method will use that. Otherwise, it will
66
+ # create a new instance to test against.
67
+ #
68
+ # Options:
69
+ # * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
70
+ # Regexp or string. Default = <tt>I18n.translate('activerecord.errors.messages.not_a_number')</tt>
71
+ #
72
+ # Example:
73
+ # should_only_allow_numeric_values_for :age
74
+ #
75
+ def should_only_allow_numeric_values_for(*attributes)
76
+ message = get_options!(attributes, :message)
77
+ message ||= default_error_message(:not_a_number)
78
+ klass = model_class
79
+ attributes.each do |attribute|
80
+ attribute = attribute.to_sym
81
+ it "should only allow numeric values for #{attribute}" do
82
+ assert_bad_value(klass, attribute, "abcd", message).should be_true
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ end
89
+ end