jakewendt-rails_extension 2.0.22
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +42 -0
- data/generators/rails_extension/USAGE +0 -0
- data/generators/rails_extension/rails_extension_generator.rb +72 -0
- data/lib/jakewendt-rails_extension.rb +1 -0
- data/lib/rails_extension.rb +18 -0
- data/lib/rails_extension/action_controller_extension.rb +8 -0
- data/lib/rails_extension/action_controller_extension/accessible_via_format.rb +2 -0
- data/lib/rails_extension/action_controller_extension/accessible_via_protocol.rb +403 -0
- data/lib/rails_extension/action_controller_extension/accessible_via_user.rb +606 -0
- data/lib/rails_extension/action_controller_extension/routing.rb +23 -0
- data/lib/rails_extension/action_controller_extension/test_case.rb +19 -0
- data/lib/rails_extension/active_record_extension.rb +5 -0
- data/lib/rails_extension/active_record_extension/base.rb +82 -0
- data/lib/rails_extension/active_record_extension/error.rb +18 -0
- data/lib/rails_extension/active_record_extension/errors.rb +20 -0
- data/lib/rails_extension/active_support_extension.rb +29 -0
- data/lib/rails_extension/active_support_extension/associations.rb +209 -0
- data/lib/rails_extension/active_support_extension/attributes.rb +235 -0
- data/lib/rails_extension/active_support_extension/pending.rb +67 -0
- data/lib/rails_extension/active_support_extension/test_case.rb +211 -0
- data/rails/init.rb +1 -0
- metadata +146 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jake
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= Rails Extension (RubyGem)
|
2
|
+
|
3
|
+
Contains a collection of validations and complex assertions.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
config.gem 'jakewendt-rails_extension',
|
8
|
+
:source => 'http://rubygems.org'
|
9
|
+
|
10
|
+
script/generate rails_extension
|
11
|
+
|
12
|
+
== ToDo
|
13
|
+
|
14
|
+
* add assert_should_protect_attributes(*attributes)
|
15
|
+
* add assert_should_allow_attributes(*attributes)
|
16
|
+
* include assert_only_difference
|
17
|
+
* add legitimate text to Rakefile
|
18
|
+
* options to polymorphic associations
|
19
|
+
|
20
|
+
== Gemified with Jeweler
|
21
|
+
|
22
|
+
vi Rakefile
|
23
|
+
rake version:write
|
24
|
+
|
25
|
+
rake version:bump:patch
|
26
|
+
rake version:bump:minor
|
27
|
+
rake version:bump:major
|
28
|
+
|
29
|
+
rake gemspec
|
30
|
+
|
31
|
+
rake install
|
32
|
+
rake release
|
33
|
+
|
34
|
+
|
35
|
+
== Thanks
|
36
|
+
|
37
|
+
* http://github.com/rails/rails
|
38
|
+
* http://github.com/technicalpickles/jeweler
|
39
|
+
|
40
|
+
== Copyright
|
41
|
+
|
42
|
+
Copyright (c) 2010 Jake. See LICENSE for details.
|
File without changes
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class RailsExtensionGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
# See Rails::Generator::Commands::Create
|
5
|
+
# rails-2.3.10/lib/rails_generator/commands.rb
|
6
|
+
# for code methods for record (Manifest)
|
7
|
+
record do |m|
|
8
|
+
File.open('.autotest','a'){|f|
|
9
|
+
f.puts <<-EOF
|
10
|
+
# From `script/generate simply_testable` ...
|
11
|
+
Dir["\#{File.dirname(__FILE__)}/config/autotest/**/*rb"].sort.each { |ext| load ext }
|
12
|
+
EOF
|
13
|
+
}
|
14
|
+
|
15
|
+
# %w( create_pages ).each do |migration|
|
16
|
+
# m.migration_template "migrations/#{migration}.rb",
|
17
|
+
# 'db/migrate', :migration_file_name => migration
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# m.directory('public/javascripts')
|
21
|
+
# Dir["#{File.dirname(__FILE__)}/templates/javascripts/*js"].each{|file|
|
22
|
+
# f = file.split('/').slice(-2,2).join('/')
|
23
|
+
# m.file(f, "public/javascripts/#{File.basename(file)}")
|
24
|
+
# }
|
25
|
+
# m.directory('public/stylesheets')
|
26
|
+
# Dir["#{File.dirname(__FILE__)}/templates/stylesheets/*css"].each{|file|
|
27
|
+
# f = file.split('/').slice(-2,2).join('/')
|
28
|
+
# m.file(f, "public/stylesheets/#{File.basename(file)}")
|
29
|
+
# }
|
30
|
+
# m.directory('test/functional/pages')
|
31
|
+
# Dir["#{File.dirname(__FILE__)}/templates/functional/*rb"].each{|file|
|
32
|
+
# f = file.split('/').slice(-2,2).join('/')
|
33
|
+
# m.file(f, "test/functional/pages/#{File.basename(file)}")
|
34
|
+
# }
|
35
|
+
# m.directory('test/unit/pages')
|
36
|
+
# Dir["#{File.dirname(__FILE__)}/templates/unit/*rb"].each{|file|
|
37
|
+
# f = file.split('/').slice(-2,2).join('/')
|
38
|
+
# m.file(f, "test/unit/pages/#{File.basename(file)}")
|
39
|
+
# }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
module Rails::Generator::Commands
|
45
|
+
class Create
|
46
|
+
def migration_template(relative_source,
|
47
|
+
relative_destination, template_options = {})
|
48
|
+
migration_directory relative_destination
|
49
|
+
migration_file_name = template_options[
|
50
|
+
:migration_file_name] || file_name
|
51
|
+
if migration_exists?(migration_file_name)
|
52
|
+
puts "Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}: Skipping"
|
53
|
+
else
|
54
|
+
template(relative_source, "#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb", template_options)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end # Create
|
58
|
+
class Base
|
59
|
+
protected
|
60
|
+
# the loop through migrations happens so fast
|
61
|
+
# that they all have the same timestamp which
|
62
|
+
# won't work when you actually try to migrate.
|
63
|
+
# All the timestamps MUST be unique.
|
64
|
+
def next_migration_string(padding = 3)
|
65
|
+
@s = (!@s.nil?)? @s.to_i + 1 : if ActiveRecord::Base.timestamped_migrations
|
66
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
67
|
+
else
|
68
|
+
"%.#{padding}d" % next_migration_number
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end # Base
|
72
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails_extension'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
def brand
|
2
|
+
"@@ "
|
3
|
+
end
|
4
|
+
module RailsExtension
|
5
|
+
# predefine namespaces
|
6
|
+
module ActiveSupportExtension
|
7
|
+
end
|
8
|
+
module ActiveRecordExtension
|
9
|
+
end
|
10
|
+
module ActionControllerExtension
|
11
|
+
end
|
12
|
+
end
|
13
|
+
#
|
14
|
+
# This may require the addition of other gem requirements
|
15
|
+
#
|
16
|
+
require 'rails_extension/active_support_extension'
|
17
|
+
require 'rails_extension/active_record_extension'
|
18
|
+
require 'rails_extension/action_controller_extension'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
require 'action_controller/test_case'
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
require 'action_controller_extension/test_case'
|
5
|
+
require 'action_controller_extension/accessible_via_protocol'
|
6
|
+
require 'action_controller_extension/accessible_via_format'
|
7
|
+
require 'action_controller_extension/accessible_via_user'
|
8
|
+
require 'action_controller_extension/routing'
|
@@ -0,0 +1,403 @@
|
|
1
|
+
module RailsExtension::ActionControllerExtension::AccessibleViaProtocol
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def awihttp_title(options={})
|
10
|
+
"with #{options[:login]} login#{options[:suffix]}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def assert_access_with_http(*actions)
|
14
|
+
user_options = actions.extract_options!
|
15
|
+
|
16
|
+
options = {
|
17
|
+
:login => :admin
|
18
|
+
}
|
19
|
+
if ( self.constants.include?('ASSERT_ACCESS_OPTIONS') )
|
20
|
+
options.merge!(self::ASSERT_ACCESS_OPTIONS)
|
21
|
+
end
|
22
|
+
options.merge!(user_options)
|
23
|
+
actions += options[:actions]||[]
|
24
|
+
|
25
|
+
m_key = options[:model].try(:underscore).try(:to_sym)
|
26
|
+
|
27
|
+
test "#{brand}AWiHTTP should get new #{awihttp_title(options)}" do
|
28
|
+
turn_https_off
|
29
|
+
login_as send(options[:login])
|
30
|
+
args = options[:new] || {}
|
31
|
+
send(:get,:new,args)
|
32
|
+
assert_response :success
|
33
|
+
assert_template 'new'
|
34
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
35
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
36
|
+
end if actions.include?(:new) || options.keys.include?(:new)
|
37
|
+
|
38
|
+
test "#{brand}AWiHTTP should post create #{awihttp_title(options)}" do
|
39
|
+
turn_https_off
|
40
|
+
login_as send(options[:login])
|
41
|
+
args = if options[:create]
|
42
|
+
options[:create]
|
43
|
+
elsif options[:attributes_for_create]
|
44
|
+
{m_key => send(options[:attributes_for_create])}
|
45
|
+
else
|
46
|
+
{}
|
47
|
+
end
|
48
|
+
assert_difference("#{options[:model]}.count",1) do
|
49
|
+
send(:post,:create,args)
|
50
|
+
end
|
51
|
+
assert_response :redirect
|
52
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
53
|
+
end if actions.include?(:create) || options.keys.include?(:create)
|
54
|
+
|
55
|
+
test "#{brand}AWiHTTP should get edit #{awihttp_title(options)}" do
|
56
|
+
turn_https_off
|
57
|
+
login_as send(options[:login])
|
58
|
+
args={}
|
59
|
+
if options[:method_for_create]
|
60
|
+
obj = send(options[:method_for_create])
|
61
|
+
args[:id] = obj.id
|
62
|
+
end
|
63
|
+
send(:get,:edit, args)
|
64
|
+
assert_response :success
|
65
|
+
assert_template 'edit'
|
66
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
67
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
68
|
+
end if actions.include?(:edit) || options.keys.include?(:edit)
|
69
|
+
|
70
|
+
test "#{brand}AWiHTTP should put update #{awihttp_title(options)}" do
|
71
|
+
turn_https_off
|
72
|
+
login_as send(options[:login])
|
73
|
+
args={}
|
74
|
+
if options[:method_for_create] && options[:attributes_for_create]
|
75
|
+
obj = send(options[:method_for_create])
|
76
|
+
args[:id] = obj.id
|
77
|
+
args[m_key] = send(options[:attributes_for_create])
|
78
|
+
end
|
79
|
+
before = obj.updated_at if obj
|
80
|
+
sleep 1 if obj # if updated too quickly, updated_at won't change
|
81
|
+
send(:put,:update, args)
|
82
|
+
after = obj.reload.updated_at if obj
|
83
|
+
assert_not_equal( before.to_i,after.to_i, "updated_at did not change" ) if obj
|
84
|
+
assert_response :redirect
|
85
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
86
|
+
end if actions.include?(:update) || options.keys.include?(:update)
|
87
|
+
|
88
|
+
test "#{brand}AWiHTTP should get show #{awihttp_title(options)}" do
|
89
|
+
turn_https_off
|
90
|
+
login_as send(options[:login])
|
91
|
+
args={}
|
92
|
+
if options[:method_for_create]
|
93
|
+
obj = send(options[:method_for_create])
|
94
|
+
args[:id] = obj.id
|
95
|
+
end
|
96
|
+
send(:get,:show, args)
|
97
|
+
assert_response :success
|
98
|
+
assert_template 'show'
|
99
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
100
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
101
|
+
end if actions.include?(:show) || options.keys.include?(:show)
|
102
|
+
|
103
|
+
test "#{brand}AWiHTTP should delete destroy #{awihttp_title(options)}" do
|
104
|
+
turn_https_off
|
105
|
+
login_as send(options[:login])
|
106
|
+
args={}
|
107
|
+
if options[:method_for_create]
|
108
|
+
obj = send(options[:method_for_create])
|
109
|
+
args[:id] = obj.id
|
110
|
+
end
|
111
|
+
assert_difference("#{options[:model]}.count",-1) do
|
112
|
+
send(:delete,:destroy,args)
|
113
|
+
end
|
114
|
+
assert_response :redirect
|
115
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
116
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
117
|
+
end if actions.include?(:destroy) || options.keys.include?(:destroy)
|
118
|
+
|
119
|
+
test "#{brand}AWiHTTP should get index #{awihttp_title(options)}" do
|
120
|
+
turn_https_off
|
121
|
+
login_as send(options[:login])
|
122
|
+
get :index
|
123
|
+
assert_response :success
|
124
|
+
assert_template 'index'
|
125
|
+
assert assigns(m_key.try(:to_s).try(:pluralize).try(:to_sym)),
|
126
|
+
"#{m_key.try(:to_s).try(:pluralize).try(:to_sym)} was not assigned"
|
127
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
128
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
129
|
+
|
130
|
+
test "#{brand}AWiHTTP should get index #{awihttp_title(options)} and items" do
|
131
|
+
turn_https_off
|
132
|
+
send(options[:before]) if !options[:before].blank?
|
133
|
+
login_as send(options[:login])
|
134
|
+
3.times{ send(options[:method_for_create]) } if !options[:method_for_create].blank?
|
135
|
+
get :index
|
136
|
+
assert_response :success
|
137
|
+
assert_template 'index'
|
138
|
+
assert assigns(m_key.try(:to_s).try(:pluralize).try(:to_sym)),
|
139
|
+
"#{m_key.try(:to_s).try(:pluralize).try(:to_sym)} was not assigned"
|
140
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
141
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
def awihttps_title(options={})
|
146
|
+
"with #{options[:login]} login#{options[:suffix]}"
|
147
|
+
end
|
148
|
+
|
149
|
+
def assert_access_with_https(*actions)
|
150
|
+
user_options = actions.extract_options!
|
151
|
+
|
152
|
+
options = {
|
153
|
+
:login => :admin
|
154
|
+
}
|
155
|
+
if ( self.constants.include?('ASSERT_ACCESS_OPTIONS') )
|
156
|
+
options.merge!(self::ASSERT_ACCESS_OPTIONS)
|
157
|
+
end
|
158
|
+
options.merge!(user_options)
|
159
|
+
actions += options[:actions]||[]
|
160
|
+
|
161
|
+
m_key = options[:model].try(:underscore).try(:to_sym)
|
162
|
+
|
163
|
+
test "#{brand}AWiHTTPS should get new #{awihttps_title(options)}" do
|
164
|
+
login_as send(options[:login])
|
165
|
+
args = options[:new] || {}
|
166
|
+
turn_https_on
|
167
|
+
send(:get,:new,args)
|
168
|
+
assert_response :success
|
169
|
+
assert_template 'new'
|
170
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
171
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
172
|
+
end if actions.include?(:new) || options.keys.include?(:new)
|
173
|
+
|
174
|
+
test "#{brand}AWiHTTPS should post create #{awihttps_title(options)}" do
|
175
|
+
login_as send(options[:login])
|
176
|
+
args = if options[:create]
|
177
|
+
options[:create]
|
178
|
+
elsif options[:attributes_for_create]
|
179
|
+
{m_key => send(options[:attributes_for_create])}
|
180
|
+
else
|
181
|
+
{}
|
182
|
+
end
|
183
|
+
turn_https_on
|
184
|
+
assert_difference("#{options[:model]}.count",1) do
|
185
|
+
send(:post,:create,args)
|
186
|
+
end
|
187
|
+
assert_response :redirect
|
188
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
189
|
+
end if actions.include?(:create) || options.keys.include?(:create)
|
190
|
+
|
191
|
+
test "#{brand}AWiHTTPS should get edit #{awihttps_title(options)}" do
|
192
|
+
login_as send(options[:login])
|
193
|
+
args={}
|
194
|
+
if options[:method_for_create]
|
195
|
+
obj = send(options[:method_for_create])
|
196
|
+
args[:id] = obj.id
|
197
|
+
end
|
198
|
+
turn_https_on
|
199
|
+
send(:get,:edit, args)
|
200
|
+
assert_response :success
|
201
|
+
assert_template 'edit'
|
202
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
203
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
204
|
+
end if actions.include?(:edit) || options.keys.include?(:edit)
|
205
|
+
|
206
|
+
test "#{brand}AWiHTTPS should put update #{awihttps_title(options)}" do
|
207
|
+
login_as send(options[:login])
|
208
|
+
args={}
|
209
|
+
if options[:method_for_create] && options[:attributes_for_create]
|
210
|
+
obj = send(options[:method_for_create])
|
211
|
+
args[:id] = obj.id
|
212
|
+
args[m_key] = send(options[:attributes_for_create])
|
213
|
+
end
|
214
|
+
before = obj.updated_at if obj
|
215
|
+
sleep 1 if obj # if updated too quickly, updated_at won't change
|
216
|
+
turn_https_on
|
217
|
+
send(:put,:update, args)
|
218
|
+
after = obj.reload.updated_at if obj
|
219
|
+
assert_not_equal( before.to_i,after.to_i, "updated_at did not change" ) if obj
|
220
|
+
assert_response :redirect
|
221
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
222
|
+
end if actions.include?(:update) || options.keys.include?(:update)
|
223
|
+
|
224
|
+
test "#{brand}AWiHTTPS should get show #{awihttps_title(options)}" do
|
225
|
+
login_as send(options[:login])
|
226
|
+
args={}
|
227
|
+
if options[:method_for_create]
|
228
|
+
obj = send(options[:method_for_create])
|
229
|
+
args[:id] = obj.id
|
230
|
+
end
|
231
|
+
turn_https_on
|
232
|
+
send(:get,:show, args)
|
233
|
+
assert_response :success
|
234
|
+
assert_template 'show'
|
235
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
236
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
237
|
+
end if actions.include?(:show) || options.keys.include?(:show)
|
238
|
+
|
239
|
+
test "#{brand}AWiHTTPS should delete destroy #{awihttps_title(options)}" do
|
240
|
+
login_as send(options[:login])
|
241
|
+
args={}
|
242
|
+
if options[:method_for_create]
|
243
|
+
obj = send(options[:method_for_create])
|
244
|
+
args[:id] = obj.id
|
245
|
+
end
|
246
|
+
turn_https_on
|
247
|
+
assert_difference("#{options[:model]}.count",-1) do
|
248
|
+
send(:delete,:destroy,args)
|
249
|
+
end
|
250
|
+
assert_response :redirect
|
251
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
252
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
253
|
+
end if actions.include?(:destroy) || options.keys.include?(:destroy)
|
254
|
+
|
255
|
+
test "#{brand}AWiHTTPS should get index #{awihttps_title(options)}" do
|
256
|
+
login_as send(options[:login])
|
257
|
+
turn_https_on
|
258
|
+
get :index
|
259
|
+
assert_response :success
|
260
|
+
assert_template 'index'
|
261
|
+
assert assigns(m_key.try(:to_s).try(:pluralize).try(:to_sym)),
|
262
|
+
"#{m_key.try(:to_s).try(:pluralize).try(:to_sym)} was not assigned"
|
263
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
264
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
265
|
+
|
266
|
+
test "#{brand}AWiHTTPS should get index #{awihttps_title(options)} and items" do
|
267
|
+
send(options[:before]) if !options[:before].blank?
|
268
|
+
login_as send(options[:login])
|
269
|
+
3.times{ send(options[:method_for_create]) } if !options[:method_for_create].blank?
|
270
|
+
turn_https_on
|
271
|
+
get :index
|
272
|
+
assert_response :success
|
273
|
+
assert_template 'index'
|
274
|
+
assert assigns(m_key.try(:to_s).try(:pluralize).try(:to_sym)),
|
275
|
+
"#{m_key.try(:to_s).try(:pluralize).try(:to_sym)} was not assigned"
|
276
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
277
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
def nawihttp_title(options={})
|
282
|
+
"with #{options[:login]} login#{options[:suffix]}"
|
283
|
+
end
|
284
|
+
|
285
|
+
def assert_no_access_with_http(*actions)
|
286
|
+
user_options = actions.extract_options!
|
287
|
+
|
288
|
+
options = {
|
289
|
+
:login => :admin
|
290
|
+
}
|
291
|
+
if ( self.constants.include?('ASSERT_ACCESS_OPTIONS') )
|
292
|
+
options.merge!(self::ASSERT_ACCESS_OPTIONS)
|
293
|
+
end
|
294
|
+
options.merge!(user_options)
|
295
|
+
actions += options[:actions]||[]
|
296
|
+
|
297
|
+
m_key = options[:model].try(:underscore).try(:to_sym)
|
298
|
+
|
299
|
+
test "#{brand}NAWiHTTP should NOT get new #{nawihttp_title(options)}" do
|
300
|
+
turn_https_off
|
301
|
+
login_as send(options[:login])
|
302
|
+
args = options[:new]||{}
|
303
|
+
send(:get,:new,args)
|
304
|
+
assert_redirected_to @controller.url_for(
|
305
|
+
:controller => @controller.controller_name,
|
306
|
+
:action => 'new', :protocol => "https://")
|
307
|
+
end if actions.include?(:new) || options.keys.include?(:new)
|
308
|
+
|
309
|
+
test "#{brand}NAWiHTTP should NOT post create #{nawihttp_title(options)}" do
|
310
|
+
turn_https_off
|
311
|
+
login_as send(options[:login])
|
312
|
+
args = if options[:create]
|
313
|
+
options[:create]
|
314
|
+
elsif options[:attributes_for_create]
|
315
|
+
{m_key => send(options[:attributes_for_create])}
|
316
|
+
else
|
317
|
+
{}
|
318
|
+
end
|
319
|
+
assert_no_difference("#{options[:model]}.count") do
|
320
|
+
send(:post,:create,args)
|
321
|
+
end
|
322
|
+
assert_match @controller.url_for(
|
323
|
+
:controller => @controller.controller_name,
|
324
|
+
:action => 'create', :protocol => "https://"),@response.redirected_to
|
325
|
+
end if actions.include?(:create) || options.keys.include?(:create)
|
326
|
+
|
327
|
+
test "#{brand}NAWiHTTP should NOT get edit #{nawihttp_title(options)}" do
|
328
|
+
turn_https_off
|
329
|
+
login_as send(options[:login])
|
330
|
+
args=options[:edit]||{}
|
331
|
+
if options[:method_for_create]
|
332
|
+
obj = send(options[:method_for_create])
|
333
|
+
args[:id] = obj.id
|
334
|
+
end
|
335
|
+
send(:get,:edit, args)
|
336
|
+
assert_redirected_to @controller.url_for(
|
337
|
+
:controller => @controller.controller_name,
|
338
|
+
:action => 'edit', :id => args[:id], :protocol => "https://")
|
339
|
+
end if actions.include?(:edit) || options.keys.include?(:edit)
|
340
|
+
|
341
|
+
test "#{brand}NAWiHTTP should NOT put update #{nawihttp_title(options)}" do
|
342
|
+
turn_https_off
|
343
|
+
login_as send(options[:login])
|
344
|
+
args={}
|
345
|
+
if options[:method_for_create] && options[:attributes_for_create]
|
346
|
+
obj = send(options[:method_for_create])
|
347
|
+
args[:id] = obj.id
|
348
|
+
args[m_key] = send(options[:attributes_for_create])
|
349
|
+
end
|
350
|
+
before = obj.updated_at if obj
|
351
|
+
send(:put,:update, args)
|
352
|
+
after = obj.reload.updated_at if obj
|
353
|
+
assert_equal( before.to_s(:db), after.to_s(:db), "updated_at changed" ) if obj
|
354
|
+
assert_match @controller.url_for(
|
355
|
+
:controller => @controller.controller_name,
|
356
|
+
:action => 'update', :id => args[:id], :protocol => "https://"), @response.redirected_to
|
357
|
+
end if actions.include?(:update) || options.keys.include?(:update)
|
358
|
+
|
359
|
+
test "#{brand}NAWiHTTP should NOT get show #{nawihttp_title(options)}" do
|
360
|
+
turn_https_off
|
361
|
+
login_as send(options[:login])
|
362
|
+
args=options[:show]||{}
|
363
|
+
if options[:method_for_create]
|
364
|
+
obj = send(options[:method_for_create])
|
365
|
+
args[:id] = obj.id
|
366
|
+
end
|
367
|
+
send(:get,:show, args)
|
368
|
+
assert_redirected_to @controller.url_for(
|
369
|
+
:controller => @controller.controller_name,
|
370
|
+
:action => 'show', :id => args[:id], :protocol => "https://")
|
371
|
+
end if actions.include?(:show) || options.keys.include?(:show)
|
372
|
+
|
373
|
+
test "#{brand}NAWiHTTP should NOT delete destroy #{nawihttp_title(options)}" do
|
374
|
+
turn_https_off
|
375
|
+
login_as send(options[:login])
|
376
|
+
args=options[:destroy]||{}
|
377
|
+
if options[:method_for_create]
|
378
|
+
obj = send(options[:method_for_create])
|
379
|
+
args[:id] = obj.id
|
380
|
+
end
|
381
|
+
assert_no_difference("#{options[:model]}.count") do
|
382
|
+
send(:delete,:destroy,args)
|
383
|
+
end
|
384
|
+
assert_redirected_to @controller.url_for(
|
385
|
+
:controller => @controller.controller_name,
|
386
|
+
:action => 'destroy', :id => args[:id], :protocol => "https://")
|
387
|
+
end if actions.include?(:destroy) || options.keys.include?(:destroy)
|
388
|
+
|
389
|
+
test "#{brand}NAWiHTTP should NOT get index #{nawihttp_title(options)}" do
|
390
|
+
turn_https_off
|
391
|
+
login_as send(options[:login])
|
392
|
+
get :index
|
393
|
+
assert_redirected_to @controller.url_for(
|
394
|
+
:controller => @controller.controller_name,
|
395
|
+
:action => 'index', :protocol => "https://")
|
396
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
397
|
+
|
398
|
+
end
|
399
|
+
|
400
|
+
end # module ClassMethods
|
401
|
+
end # module RailsExtension::ActionControllerExtension::AccessibleViaProtocol
|
402
|
+
ActionController::TestCase.send(:include,
|
403
|
+
RailsExtension::ActionControllerExtension::AccessibleViaProtocol)
|