simple_token_authentication 1.0.0.beta.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +674 -0
- data/README.md +134 -0
- data/Rakefile +32 -0
- data/lib/simple_token_authentication.rb +5 -0
- data/lib/simple_token_authentication/acts_as_token_authenticatable.rb +33 -0
- data/lib/simple_token_authentication/acts_as_token_authentication_handler.rb +68 -0
- data/lib/simple_token_authentication/version.rb +3 -0
- data/lib/tasks/simple_token_authentication_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/javascripts/posts.js +2 -0
- data/test/dummy/app/assets/javascripts/private_posts.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/posts.css +4 -0
- data/test/dummy/app/assets/stylesheets/private_posts.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +21 -0
- data/test/dummy/app/controllers/posts_controller.rb +62 -0
- data/test/dummy/app/controllers/private_posts_controller.rb +63 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/posts_helper.rb +2 -0
- data/test/dummy/app/helpers/private_posts_helper.rb +2 -0
- data/test/dummy/app/models/post.rb +3 -0
- data/test/dummy/app/models/private_post.rb +3 -0
- data/test/dummy/app/models/user.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/posts/_form.html.erb +29 -0
- data/test/dummy/app/views/posts/edit.html.erb +6 -0
- data/test/dummy/app/views/posts/index.html.erb +31 -0
- data/test/dummy/app/views/posts/new.html.erb +5 -0
- data/test/dummy/app/views/posts/show.html.erb +19 -0
- data/test/dummy/app/views/private_posts/_form.html.erb +29 -0
- data/test/dummy/app/views/private_posts/edit.html.erb +6 -0
- data/test/dummy/app/views/private_posts/index.html.erb +31 -0
- data/test/dummy/app/views/private_posts/new.html.erb +5 -0
- data/test/dummy/app/views/private_posts/show.html.erb +19 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/indefinite_articlerize.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +60 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20140107041016_create_posts.rb +11 -0
- data/test/dummy/db/migrate/20140107053025_create_users.rb +6 -0
- data/test/dummy/db/migrate/20140107064508_create_private_posts.rb +11 -0
- data/test/dummy/db/schema.rb +35 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/generators/rspec/controller/controller_generator.rb +33 -0
- data/test/dummy/lib/generators/rspec/helper/helper_generator.rb +15 -0
- data/test/dummy/lib/generators/rspec/model/model_generator.rb +22 -0
- data/test/dummy/lib/generators/rspec/scaffold/scaffold_generator.rb +192 -0
- data/test/dummy/lib/templates/rspec/controller/controller_spec.rb +16 -0
- data/test/dummy/lib/templates/rspec/controller/view_spec.rb +5 -0
- data/test/dummy/lib/templates/rspec/helper/helper_spec.rb +0 -0
- data/test/dummy/lib/templates/rspec/model/model_spec.rb +65 -0
- data/test/dummy/lib/templates/rspec/model/model_spec_backup.rb +19 -0
- data/test/dummy/lib/templates/rspec/scaffold/controller_spec.rb +168 -0
- data/test/dummy/lib/templates/rspec/scaffold/edit_spec.rb +31 -0
- data/test/dummy/lib/templates/rspec/scaffold/index_spec.rb +32 -0
- data/test/dummy/lib/templates/rspec/scaffold/new_spec.rb +30 -0
- data/test/dummy/lib/templates/rspec/scaffold/routing_spec.rb +39 -0
- data/test/dummy/lib/templates/rspec/scaffold/show_spec.rb +28 -0
- data/test/dummy/log/development.log +3437 -0
- data/test/dummy/log/test.log +22013 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/spec/controllers/posts_controller_spec.rb +161 -0
- data/test/dummy/spec/controllers/private_posts_controller_spec.rb +41 -0
- data/test/dummy/spec/factories/posts.rb +11 -0
- data/test/dummy/spec/factories/private_posts.rb +11 -0
- data/test/dummy/spec/helpers/posts_helper_spec.rb +0 -0
- data/test/dummy/spec/helpers/private_posts_helper_spec.rb +0 -0
- data/test/dummy/spec/models/post_spec.rb +65 -0
- data/test/dummy/spec/models/private_post_spec.rb +65 -0
- data/test/dummy/spec/models/user_spec.rb +61 -0
- data/test/dummy/spec/requests/posts_spec.rb +16 -0
- data/test/dummy/spec/requests/private_posts_spec.rb +17 -0
- data/test/dummy/spec/routing/posts_routing_spec.rb +35 -0
- data/test/dummy/spec/routing/private_posts_routing_spec.rb +35 -0
- data/test/dummy/spec/spec_helper.rb +42 -0
- data/test/dummy/spec/support/factory_girl.rb +6 -0
- data/test/dummy/spec/views/posts/edit.html.erb_spec.rb +22 -0
- data/test/dummy/spec/views/posts/index.html.erb_spec.rb +26 -0
- data/test/dummy/spec/views/posts/new.html.erb_spec.rb +22 -0
- data/test/dummy/spec/views/posts/show.html.erb_spec.rb +19 -0
- data/test/dummy/spec/views/private_posts/edit.html.erb_spec.rb +22 -0
- data/test/dummy/spec/views/private_posts/index.html.erb_spec.rb +26 -0
- data/test/dummy/spec/views/private_posts/new.html.erb_spec.rb +22 -0
- data/test/dummy/spec/views/private_posts/show.html.erb_spec.rb +19 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/simple_token_authentication_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +384 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
class_option :fixture, :type => :boolean
|
8
|
+
|
9
|
+
def create_model_spec
|
10
|
+
template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
hook_for :fixture_replacement
|
14
|
+
|
15
|
+
def create_fixture_file
|
16
|
+
if options[:fixture] && options[:fixture_replacement].nil?
|
17
|
+
template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
require 'rails/generators/resource_helpers'
|
3
|
+
|
4
|
+
module Rspec
|
5
|
+
module Generators
|
6
|
+
class ScaffoldGenerator < Base
|
7
|
+
include ::Rails::Generators::ResourceHelpers
|
8
|
+
source_paths << File.expand_path("../../helper/templates", __FILE__)
|
9
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
10
|
+
|
11
|
+
class_option :orm, :desc => "ORM used to generate the controller"
|
12
|
+
class_option :template_engine, :desc => "Template engine to generate view files"
|
13
|
+
class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
|
14
|
+
|
15
|
+
class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs"
|
16
|
+
class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
|
17
|
+
class_option :webrat, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers"
|
18
|
+
class_option :webrat_matchers, :type => :boolean, :default => false, :desc => "Use webrat methods/matchers (deprecated - use --webrat)"
|
19
|
+
class_option :helper_specs, :type => :boolean, :default => true, :desc => "Generate helper specs"
|
20
|
+
class_option :routing_specs, :type => :boolean, :default => true, :desc => "Generate routing specs"
|
21
|
+
|
22
|
+
def generate_controller_spec
|
23
|
+
return unless options[:controller_specs]
|
24
|
+
|
25
|
+
template 'controller_spec.rb',
|
26
|
+
File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate_view_specs
|
30
|
+
return unless options[:view_specs] && options[:template_engine]
|
31
|
+
|
32
|
+
copy_view :edit
|
33
|
+
copy_view :index unless options[:singleton]
|
34
|
+
copy_view :new
|
35
|
+
copy_view :show
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_routing_spec
|
39
|
+
return unless options[:routing_specs]
|
40
|
+
|
41
|
+
template 'routing_spec.rb',
|
42
|
+
File.join('spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb")
|
43
|
+
end
|
44
|
+
|
45
|
+
hook_for :integration_tool, :as => :integration
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
# @deprecated Use `--webrat` instead.
|
50
|
+
def webrat?
|
51
|
+
RSpec.deprecate("--webrat-matchers", :replacement => "--webrat") if options[:webrat_matchers]
|
52
|
+
options[:webrat] || options[:webrat_matchers]
|
53
|
+
end
|
54
|
+
|
55
|
+
def copy_view(view)
|
56
|
+
template "#{view}_spec.rb",
|
57
|
+
File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
|
58
|
+
end
|
59
|
+
|
60
|
+
def example_valid_attributes
|
61
|
+
# Only take the first attribute so this hash does not become unweildy and large in the
|
62
|
+
# generated controller spec. It is the responsibility of the user to keep the the valid
|
63
|
+
# attributes method up-to-date as they add validations.
|
64
|
+
@example_valid_attributes ||=
|
65
|
+
if attributes.any?
|
66
|
+
{ attributes.first.name => attributes.first.default.to_s }
|
67
|
+
else
|
68
|
+
{ }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def example_invalid_attributes
|
73
|
+
@example_invalid_attributes ||=
|
74
|
+
if attributes.any?
|
75
|
+
{ attributes.first.name => "invalid value" }
|
76
|
+
else
|
77
|
+
{ }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def example_params_for_update
|
82
|
+
@example_params_for_update ||=
|
83
|
+
if example_valid_attributes.any?
|
84
|
+
example_valid_attributes
|
85
|
+
else
|
86
|
+
{ "these" => "params" }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def formatted_hash(hash)
|
91
|
+
formatted = hash.inspect
|
92
|
+
formatted.gsub!("{", "{ ")
|
93
|
+
formatted.gsub!("}", " }")
|
94
|
+
formatted.gsub!("=>", " => ")
|
95
|
+
formatted
|
96
|
+
end
|
97
|
+
|
98
|
+
# support for namespaced-resources
|
99
|
+
def ns_file_name
|
100
|
+
ns_parts.empty? ? file_name : "#{ns_parts[0].underscore}_#{ns_parts[1].singularize.underscore}"
|
101
|
+
end
|
102
|
+
|
103
|
+
# support for namespaced-resources
|
104
|
+
def ns_table_name
|
105
|
+
ns_parts.empty? ? table_name : "#{ns_parts[0].underscore}/#{ns_parts[1].tableize}"
|
106
|
+
end
|
107
|
+
|
108
|
+
def ns_parts
|
109
|
+
@ns_parts ||= begin
|
110
|
+
matches = ARGV[0].to_s.match(/\A(\w+)(?:\/|::)(\w+)/)
|
111
|
+
matches ? [matches[1], matches[2]] : []
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Returns the name of the mock. For example, if the file name is user,
|
116
|
+
# it returns mock_user.
|
117
|
+
#
|
118
|
+
# If a hash is given, it uses the hash key as the ORM method and the
|
119
|
+
# value as response. So, for ActiveRecord and file name "User":
|
120
|
+
#
|
121
|
+
# mock_file_name(:save => true)
|
122
|
+
# #=> mock_user(:save => true)
|
123
|
+
#
|
124
|
+
# If another ORM is being used and another method instead of save is
|
125
|
+
# called, it will be the one used.
|
126
|
+
#
|
127
|
+
def mock_file_name(hash=nil)
|
128
|
+
if hash
|
129
|
+
method, and_return = hash.to_a.first
|
130
|
+
method = orm_instance.send(method).split('.').last.gsub(/\(.*?\)/, '')
|
131
|
+
"mock_#{ns_file_name}(:#{method} => #{and_return})"
|
132
|
+
else
|
133
|
+
"mock_#{ns_file_name}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Receives the ORM chain and convert to expects. For ActiveRecord:
|
138
|
+
#
|
139
|
+
# should! orm_class.find(User, "37")
|
140
|
+
# #=> User.should_receive(:find).with(37)
|
141
|
+
#
|
142
|
+
# For Datamapper:
|
143
|
+
#
|
144
|
+
# should! orm_class.find(User, "37")
|
145
|
+
# #=> User.should_receive(:get).with(37)
|
146
|
+
#
|
147
|
+
def should_receive(chain)
|
148
|
+
stub_or_should_chain(:should_receive, chain)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Receives the ORM chain and convert to stub. For ActiveRecord:
|
152
|
+
#
|
153
|
+
# stub orm_class.find(User, "37")
|
154
|
+
# #=> User.stub(:find).with(37)
|
155
|
+
#
|
156
|
+
# For Datamapper:
|
157
|
+
#
|
158
|
+
# stub orm_class.find(User, "37")
|
159
|
+
# #=> User.stub(:get).with(37)
|
160
|
+
#
|
161
|
+
def stub(chain)
|
162
|
+
stub_or_should_chain(:stub, chain)
|
163
|
+
end
|
164
|
+
|
165
|
+
def stub_or_should_chain(mode, chain)
|
166
|
+
receiver, method = chain.split(".")
|
167
|
+
method.gsub!(/\((.*?)\)/, '')
|
168
|
+
|
169
|
+
response = "#{receiver}.#{mode}(:#{method})"
|
170
|
+
response << ".with(#{$1})" unless $1.blank?
|
171
|
+
response
|
172
|
+
end
|
173
|
+
|
174
|
+
def value_for(attribute)
|
175
|
+
case attribute.type
|
176
|
+
when :string
|
177
|
+
"#{attribute.name.titleize}".inspect
|
178
|
+
when :integer
|
179
|
+
@attribute_id_map ||= {}
|
180
|
+
@attribute_id_map[attribute] ||= @attribute_id_map.keys.size.next.to_s
|
181
|
+
else
|
182
|
+
attribute.default.inspect
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def banner
|
187
|
+
self.class.banner
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
describe <%= class_name %>Controller do
|
5
|
+
|
6
|
+
<% for action in actions -%>
|
7
|
+
describe "GET '<%= action %>'" do
|
8
|
+
it "returns http success" do
|
9
|
+
get '<%= action %>'
|
10
|
+
response.should be_success
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
<% end -%>
|
15
|
+
end
|
16
|
+
<% end -%>
|
File without changes
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
describe <%= class_name %> do
|
5
|
+
|
6
|
+
# attributes
|
7
|
+
<% for attribute in attributes -%>
|
8
|
+
|
9
|
+
it "has <%= indefinite_articlerize(attribute.name) %>" do
|
10
|
+
should respond_to :<%= attribute.name %>
|
11
|
+
end
|
12
|
+
<% end -%>
|
13
|
+
|
14
|
+
# associations
|
15
|
+
|
16
|
+
# Uncomment if your model has associations.
|
17
|
+
# See https://github.com/thoughtbot/shoulda
|
18
|
+
#
|
19
|
+
# it "belongs to a 'model'" do
|
20
|
+
# should belong_to :model
|
21
|
+
# end
|
22
|
+
|
23
|
+
# validations
|
24
|
+
|
25
|
+
<% if options[:fixture_replacement] == :factory_girl -%>
|
26
|
+
# See https://github.com/thoughtbot/factory_girl
|
27
|
+
# This factory should only set the REQUIRED attributes.
|
28
|
+
it "has a valid factory" do
|
29
|
+
FactoryGirl.build(:<%= class_name.underscore %>).should be_valid
|
30
|
+
end
|
31
|
+
#
|
32
|
+
# Uncomment if your model has required attributes.
|
33
|
+
# This factory should set no attributes and is useful when invalid
|
34
|
+
# attributes or objects are required.
|
35
|
+
# See FactoryGirl.attributes_for() documentation
|
36
|
+
#
|
37
|
+
# it "has an invalid factory" do
|
38
|
+
# FactoryGirl.build(:invalid_<%= class_name.underscore %>).should be_valid
|
39
|
+
# end
|
40
|
+
|
41
|
+
<% end -%>
|
42
|
+
# Uncomment if your model has required attributes
|
43
|
+
#
|
44
|
+
# This is the BDD way of testing attributes presence validation
|
45
|
+
# See https://www.relishapp.com/rspec/rspec-rails/docs/model-specs/errors-on
|
46
|
+
#
|
47
|
+
# it "fails validation with no 'attribute'" do
|
48
|
+
# expect(<%= class_name %>.new).to have(1).error_on(:attribute)
|
49
|
+
# end
|
50
|
+
<% if options[:fixture_replacement] == :factory_girl -%>
|
51
|
+
#
|
52
|
+
# And this is an alternative way, which takes advantage of factories,
|
53
|
+
# it's up to you to chose one, the other, or use both together.
|
54
|
+
#
|
55
|
+
# it "requires a 'attribute'" do
|
56
|
+
# FactoryGirl.build(:<%= class_name.underscore %>, attribute: "").should_not be_valid
|
57
|
+
# end
|
58
|
+
|
59
|
+
<% end -%>
|
60
|
+
# methods
|
61
|
+
|
62
|
+
# Describe here you model methods behaviour.
|
63
|
+
|
64
|
+
end
|
65
|
+
<% end -%>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: attributes
|
2
|
+
|
3
|
+
Scenario: listing attributes
|
4
|
+
#Given I run `cd example`
|
5
|
+
#Given I run `rails g model widget name:string priority:integer`
|
6
|
+
#Given I run `/bin/bash --login -c "rvm use ruby-1.9.3-head@custom-rails-generators-example && rvm current && bundle install --gemfile=example/Gemfile"`
|
7
|
+
# And I run `rvm current`
|
8
|
+
# And I run `bundle install`
|
9
|
+
When I run `rspec`
|
10
|
+
#When I run `/bin/bash --login -c "rvm use ruby-1.9.3-head@custom-rails-generators-example && rvm current && bundle exec rspec"`
|
11
|
+
|
12
|
+
# Given I run `rvm use ruby-1.9.3-head@custom-rails-generators-example`
|
13
|
+
# And I run `bundle install`
|
14
|
+
#Given I run `rails g model widget name:string priority:integer`
|
15
|
+
#When I run `/bin/bash --login -c "rvm use 1.9.3-head@custom-rails-generators-example && rvm current && bundle install"`
|
16
|
+
#And I run `rvm current`
|
17
|
+
Then the examples should all pass
|
18
|
+
# And the output contains 'responds to name'
|
19
|
+
# And the ouput contains 'responds to priority'
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
|
+
# It demonstrates how one might use RSpec to specify the controller code that
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
#
|
15
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
16
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
17
|
+
# is no simpler way to get a handle on the object needed for the example.
|
18
|
+
# Message expectations are only used when there is no simpler way to specify
|
19
|
+
# that an instance is receiving a specific message.
|
20
|
+
|
21
|
+
<% module_namespacing do -%>
|
22
|
+
describe <%= controller_class_name %>Controller do
|
23
|
+
|
24
|
+
# This should return the minimal set of attributes required to create a valid
|
25
|
+
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
|
26
|
+
# adjust the attributes here as well.
|
27
|
+
let(:valid_attributes) { <%= formatted_hash(example_valid_attributes) %> }
|
28
|
+
|
29
|
+
# This should return the minimal set of values that should be in the session
|
30
|
+
# in order to pass any filters (e.g. authentication) defined in
|
31
|
+
# <%= controller_class_name %>Controller. Be sure to keep this updated too.
|
32
|
+
let(:valid_session) { {} }
|
33
|
+
|
34
|
+
<% unless options[:singleton] -%>
|
35
|
+
describe "GET index" do
|
36
|
+
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
37
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
38
|
+
get :index, {}, valid_session
|
39
|
+
assigns(:<%= table_name %>).should eq([<%= file_name %>])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
<% end -%>
|
44
|
+
describe "GET show" do
|
45
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
46
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
47
|
+
get :show, {:id => <%= file_name %>.to_param}, valid_session
|
48
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "GET new" do
|
53
|
+
it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
|
54
|
+
get :new, {}, valid_session
|
55
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "GET edit" do
|
60
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
61
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
62
|
+
get :edit, {:id => <%= file_name %>.to_param}, valid_session
|
63
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "POST create" do
|
68
|
+
describe "with valid params" do
|
69
|
+
it "creates a new <%= class_name %>" do
|
70
|
+
expect {
|
71
|
+
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
72
|
+
}.to change(<%= class_name %>, :count).by(1)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
|
76
|
+
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
77
|
+
assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
|
78
|
+
assigns(:<%= ns_file_name %>).should be_persisted
|
79
|
+
end
|
80
|
+
|
81
|
+
it "redirects to the created <%= ns_file_name %>" do
|
82
|
+
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
83
|
+
response.should redirect_to(<%= class_name %>.last)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "with invalid params" do
|
88
|
+
it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
|
89
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
90
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
91
|
+
post :create, {:<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
92
|
+
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "re-renders the 'new' template" do
|
96
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
97
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
98
|
+
post :create, {:<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
99
|
+
response.should render_template("new")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "PUT update" do
|
105
|
+
describe "with valid params" do
|
106
|
+
it "updates the requested <%= ns_file_name %>" do
|
107
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
108
|
+
# Assuming there are no other <%= table_name %> in the database, this
|
109
|
+
# specifies that the <%= class_name %> created on the previous line
|
110
|
+
# receives the :update_attributes message with whatever params are
|
111
|
+
# submitted in the request.
|
112
|
+
<%- if ::Rails::VERSION::STRING >= '4' -%>
|
113
|
+
<%= class_name %>.any_instance.should_receive(:update).with(<%= formatted_hash(example_params_for_update) %>)
|
114
|
+
<%- else -%>
|
115
|
+
<%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= formatted_hash(example_params_for_update) %>)
|
116
|
+
<%- end -%>
|
117
|
+
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_params_for_update) %>}, valid_session
|
118
|
+
end
|
119
|
+
|
120
|
+
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
|
121
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
122
|
+
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
123
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "redirects to the <%= ns_file_name %>" do
|
127
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
128
|
+
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
129
|
+
response.should redirect_to(<%= file_name %>)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "with invalid params" do
|
134
|
+
it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
|
135
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
136
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
137
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
138
|
+
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
139
|
+
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "re-renders the 'edit' template" do
|
143
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
144
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
145
|
+
<%= class_name %>.any_instance.stub(:save).and_return(false)
|
146
|
+
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
|
147
|
+
response.should render_template("edit")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "DELETE destroy" do
|
153
|
+
it "destroys the requested <%= ns_file_name %>" do
|
154
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
155
|
+
expect {
|
156
|
+
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
|
157
|
+
}.to change(<%= class_name %>, :count).by(-1)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "redirects to the <%= table_name %> list" do
|
161
|
+
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
162
|
+
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
|
163
|
+
response.should redirect_to(<%= index_helper %>_url)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
<% end -%>
|