ccls-common_lib 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +116 -0
- data/lib/ccls-common_lib.rb +1 -0
- data/lib/common_lib.rb +37 -0
- data/lib/common_lib/action_controller_extension.rb +8 -0
- data/lib/common_lib/action_controller_extension/accessible_via_protocol.rb +405 -0
- data/lib/common_lib/action_controller_extension/accessible_via_user.rb +605 -0
- data/lib/common_lib/action_controller_extension/routing.rb +20 -0
- data/lib/common_lib/action_controller_extension/test_case.rb +22 -0
- data/lib/common_lib/action_view_extension.rb +3 -0
- data/lib/common_lib/action_view_extension/base.rb +310 -0
- data/lib/common_lib/action_view_extension/form_builder.rb +197 -0
- data/lib/common_lib/active_model.rb +4 -0
- data/lib/common_lib/active_model/errors.rb +16 -0
- data/lib/common_lib/active_model/validations/absence.rb +78 -0
- data/lib/common_lib/active_model/validations/complete_date.rb +138 -0
- data/lib/common_lib/active_model/validations/past_date.rb +121 -0
- data/lib/common_lib/active_record.rb +1 -0
- data/lib/common_lib/active_record/base.rb +129 -0
- data/lib/common_lib/active_support_extension.rb +12 -0
- data/lib/common_lib/active_support_extension/assertions.rb +108 -0
- data/lib/common_lib/active_support_extension/associations.rb +154 -0
- data/lib/common_lib/active_support_extension/attributes.rb +296 -0
- data/lib/common_lib/active_support_extension/pending.rb +115 -0
- data/lib/common_lib/active_support_extension/test_case.rb +203 -0
- data/lib/common_lib/railtie.rb +48 -0
- data/lib/common_lib/ruby.rb +8 -0
- data/lib/common_lib/ruby/array.rb +128 -0
- data/lib/common_lib/ruby/fixnum.rb +5 -0
- data/lib/common_lib/ruby/hash.rb +51 -0
- data/lib/common_lib/ruby/integer.rb +11 -0
- data/lib/common_lib/ruby/nil_class.rb +13 -0
- data/lib/common_lib/ruby/numeric.rb +0 -0
- data/lib/common_lib/ruby/object.rb +53 -0
- data/lib/common_lib/ruby/string.rb +20 -0
- data/lib/common_lib/translation_table.rb +129 -0
- data/lib/tasks/common_lib.rake +10 -0
- data/lib/tasks/csv.rake +0 -0
- data/lib/tasks/database.rake +229 -0
- data/lib/tasks/rcov.rake +52 -0
- data/vendor/assets/javascripts/common_lib.js +77 -0
- data/vendor/assets/stylesheets/common_lib.css +71 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d8c50afcfe26dbc472a15bc46ddd629a621affcf
|
4
|
+
data.tar.gz: 25823f20452eb8cc8fe48810145b5b39bb87f87a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 301a729ed0c807e32fe0b8be0dbb5fe46a892ae46be1052df6f2fdf0bba8392494631b134568dc7f81731b9512eb8dfc8025455ee1b80c528d98ea4433eb258e
|
7
|
+
data.tar.gz: 332d0f121b509fa9b39ef8657c0ffae321b9746abd33b2bd49c1daf1b0cb5ebfa66694f78113a0df991f4bb393d1630b43017035dfeb347d9fc2d140b0ec92a5
|
data/README.rdoc
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
= CCLS Common Lib
|
2
|
+
|
3
|
+
After further pondering, I think that I'm just going to fork all of the jakewendt repo/gems into ccls and then to use the ccls-* gem instead.
|
4
|
+
|
5
|
+
I've included ruby_extension and rails_extension. Working on simply_helpful. Next up will be simply_authorized.
|
6
|
+
|
7
|
+
Some of these extensions and additions are not actually used on any of the CCLS sites, but were part of my original gems.
|
8
|
+
There existance should not cause any problems.
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
This ruby gem ( ccls-common_lib ) is meant to include all of the current functionality provided by ...
|
13
|
+
|
14
|
+
* {ccls-ruby_extension}[http://github.com/ccls/ruby_extension] - modifications, updates and patches for ruby.
|
15
|
+
* {ccls-simply_helpful}[http://github.com/ccls/simply_helpful]
|
16
|
+
* {ccls-simply_authorized}[http://github.com/ccls/simply_authorized]
|
17
|
+
* {ccls-rails_extension}[http://github.com/ccls/rails_extension]
|
18
|
+
|
19
|
+
This gem would then be used by ALL of the ccls apps and the engine and the aforementioned gems can and should be removed from the machines to avoid accidental usage. The following would be kept separate and used only for testing only by this gem. SimplySessions might actually be includable within just the test environment of CommonLib.
|
20
|
+
|
21
|
+
* {ccls-simply_sessions}[http://github.com/ccls/simply_sessions]
|
22
|
+
|
23
|
+
|
24
|
+
And the following would be used by ALL ccls apps and gems and probably included in the config/environments/test.rb as "config.gem 'ccls-html_test'"
|
25
|
+
|
26
|
+
* {ccls-html_test}[http://github.com/ccls/html_test]
|
27
|
+
|
28
|
+
|
29
|
+
Unfortunately, this has all gotten kinda muddled, making it a bit confusing. This would take at least a day of importing and merging and testing and installing and testing and ...
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
---
|
34
|
+
== Date.today
|
35
|
+
|
36
|
+
DO NOT USE Date.today, unless the following is what you want.
|
37
|
+
|
38
|
+
It will compute a Date and disregard the time zone.
|
39
|
+
|
40
|
+
In rails, this means that occassionally Date.today == Date.tomorrow
|
41
|
+
or Date.today == Date.yesterday, depending on what time it is.
|
42
|
+
|
43
|
+
The Rails methods of Date.tomorrow and Date.yesterday reference
|
44
|
+
Date.current, which uses the Time.zone, making them more accurate.
|
45
|
+
|
46
|
+
|
47
|
+
I think that DateTime.now and Time.now also ignore the timezone.
|
48
|
+
|
49
|
+
Use DateTime.current or Time.zone.now
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
---
|
55
|
+
== validations_from_yaml_file
|
56
|
+
|
57
|
+
This ActiveRecord::Base method takes no arguments and is straight forward but deserves a few notes.
|
58
|
+
|
59
|
+
Firstly, it will look for a '.yml' file in config/validations/ with the class name underscored.
|
60
|
+
|
61
|
+
Each entry is read in as a hash and passed to 'validates'.
|
62
|
+
|
63
|
+
Most validations are straight forward, with 2 current exceptions. I tried many ways. Searched online
|
64
|
+
for some time. Got a lot of negative feedback. Mostly "why do it", "don't do it", "not standard", blah, blah.
|
65
|
+
So. Of course I did it anyway. The 2 objects that cause the most confusion are ranges, useful in length limitations,
|
66
|
+
and regexps, useful in formatting emails, ssns, zip codes, phone numbers, ... The solution is rather simple
|
67
|
+
and built in to ruby. These things simply need a bit to declare what object they are.
|
68
|
+
|
69
|
+
* Ranges
|
70
|
+
* :in: !ruby/range 4..250
|
71
|
+
|
72
|
+
* Regular Expressions
|
73
|
+
* :with: !ruby/regexp '/^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i'
|
74
|
+
* note that the single quotes around the regexp are unneccessary and problematic if the regex contains one.
|
75
|
+
|
76
|
+
For other references, see ...
|
77
|
+
|
78
|
+
http://codereview.stackexchange.com/questions/159/use-of-a-regex-stored-inside-yaml-file
|
79
|
+
|
80
|
+
http://stackoverflow.com/questions/3337020/how-to-specify-ranges-in-yaml
|
81
|
+
|
82
|
+
http://www.opensource.apple.com/source/ruby/ruby-14/ruby/lib/yaml/rubytypes.rb
|
83
|
+
|
84
|
+
http://yaml4r.sourceforge.net/doc/page/objects_in_yaml.htm
|
85
|
+
|
86
|
+
Or ...
|
87
|
+
|
88
|
+
/opt/local/lib/ruby1.9/1.9.1/syck/rubytypes.rb
|
89
|
+
/opt/local/lib/ruby1.9/1.9.1/psych/visitors/to_ruby.rb
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
== Testing
|
94
|
+
---
|
95
|
+
|
96
|
+
sudo /opt/local/share/mariadb/support-files/mysql.server start &
|
97
|
+
|
98
|
+
c ; /bin/rm -rf coverage* ; bundle exec rake ; mv coverage coverage-one-run ; open coverage-one-run/index.html ; nice +20 bundle exec autotest
|
99
|
+
|
100
|
+
|
101
|
+
---
|
102
|
+
== Gemified with Jeweler
|
103
|
+
|
104
|
+
vi Rakefile
|
105
|
+
rake version:write
|
106
|
+
|
107
|
+
rake version:bump:patch
|
108
|
+
rake version:bump:minor
|
109
|
+
rake version:bump:major
|
110
|
+
|
111
|
+
rake gemspec
|
112
|
+
|
113
|
+
rake install
|
114
|
+
rake release
|
115
|
+
|
116
|
+
Copyright (c) 2010 [Jake Wendt], released under the MIT license
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'common_lib'
|
data/lib/common_lib.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# because HashWithIndifferentAccess is just too long a name
|
2
|
+
HWIA = HashWithIndifferentAccess
|
3
|
+
|
4
|
+
module CommonLib; end
|
5
|
+
|
6
|
+
require "common_lib/ruby"
|
7
|
+
require "common_lib/translation_table"
|
8
|
+
|
9
|
+
def brand # for auto-generated tests
|
10
|
+
"@@ "
|
11
|
+
end
|
12
|
+
require 'common_lib/active_support_extension'
|
13
|
+
#require 'common_lib/active_record_extension'
|
14
|
+
require 'common_lib/active_model'
|
15
|
+
require 'common_lib/active_record'
|
16
|
+
require 'common_lib/action_controller_extension'
|
17
|
+
require 'common_lib/action_view_extension'
|
18
|
+
|
19
|
+
|
20
|
+
# pretty much always as don't expect this to be used outside of a rails app
|
21
|
+
require 'common_lib/railtie' if defined?(Rails)
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
require 'hpricot'
|
29
|
+
ActionView::Base.field_error_proc = Proc.new { |html_tag, instance|
|
30
|
+
error_class = 'field_error'
|
31
|
+
nodes = Hpricot(html_tag)
|
32
|
+
nodes.each_child { |node|
|
33
|
+
node[:class] = node.classes.push(error_class).join(' ') unless !node.elem? || node[:type] == 'hidden' || node.classes.include?(error_class)
|
34
|
+
}
|
35
|
+
nodes.to_html.html_safe
|
36
|
+
}
|
37
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module CommonLib::ActionControllerExtension; end
|
2
|
+
if defined?(Rails) and Rails.env == 'test'
|
3
|
+
require 'common_lib/action_controller_extension/test_case'
|
4
|
+
# I don't bother testing http versus https in rails 3
|
5
|
+
#require 'common_lib/action_controller_extension/accessible_via_protocol'
|
6
|
+
require 'common_lib/action_controller_extension/accessible_via_user'
|
7
|
+
require 'common_lib/action_controller_extension/routing'
|
8
|
+
end
|
@@ -0,0 +1,405 @@
|
|
1
|
+
module CommonLib::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
|
+
:updated_at => ( Time.now - 2.days ) )
|
77
|
+
args[:id] = obj.id
|
78
|
+
args[m_key] = send(options[:attributes_for_create])
|
79
|
+
end
|
80
|
+
before = obj.updated_at if obj
|
81
|
+
# sleep 1 if obj # if updated too quickly, updated_at won't change
|
82
|
+
send(:put,:update, args)
|
83
|
+
after = obj.reload.updated_at if obj
|
84
|
+
assert_not_equal( before.to_i,after.to_i, "updated_at did not change" ) if obj
|
85
|
+
assert_response :redirect
|
86
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
87
|
+
end if actions.include?(:update) || options.keys.include?(:update)
|
88
|
+
|
89
|
+
test "#{brand}AWiHTTP should get show #{awihttp_title(options)}" do
|
90
|
+
turn_https_off
|
91
|
+
login_as send(options[:login])
|
92
|
+
args={}
|
93
|
+
if options[:method_for_create]
|
94
|
+
obj = send(options[:method_for_create])
|
95
|
+
args[:id] = obj.id
|
96
|
+
end
|
97
|
+
send(:get,:show, args)
|
98
|
+
assert_response :success
|
99
|
+
assert_template 'show'
|
100
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
101
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
102
|
+
end if actions.include?(:show) || options.keys.include?(:show)
|
103
|
+
|
104
|
+
test "#{brand}AWiHTTP should delete destroy #{awihttp_title(options)}" do
|
105
|
+
turn_https_off
|
106
|
+
login_as send(options[:login])
|
107
|
+
args={}
|
108
|
+
if options[:method_for_create]
|
109
|
+
obj = send(options[:method_for_create])
|
110
|
+
args[:id] = obj.id
|
111
|
+
end
|
112
|
+
assert_difference("#{options[:model]}.count",-1) do
|
113
|
+
send(:delete,:destroy,args)
|
114
|
+
end
|
115
|
+
assert_response :redirect
|
116
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
117
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
118
|
+
end if actions.include?(:destroy) || options.keys.include?(:destroy)
|
119
|
+
|
120
|
+
test "#{brand}AWiHTTP should get index #{awihttp_title(options)}" do
|
121
|
+
turn_https_off
|
122
|
+
login_as send(options[:login])
|
123
|
+
get :index
|
124
|
+
assert_response :success
|
125
|
+
assert_template 'index'
|
126
|
+
assert assigns(m_key.try(:to_s).try(:pluralize).try(:to_sym)),
|
127
|
+
"#{m_key.try(:to_s).try(:pluralize).try(:to_sym)} was not assigned"
|
128
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
129
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
130
|
+
|
131
|
+
test "#{brand}AWiHTTP should get index #{awihttp_title(options)} and items" do
|
132
|
+
turn_https_off
|
133
|
+
send(options[:before]) if !options[:before].blank?
|
134
|
+
login_as send(options[:login])
|
135
|
+
3.times{ send(options[:method_for_create]) } if !options[:method_for_create].blank?
|
136
|
+
get :index
|
137
|
+
assert_response :success
|
138
|
+
assert_template 'index'
|
139
|
+
assert assigns(m_key.try(:to_s).try(:pluralize).try(:to_sym)),
|
140
|
+
"#{m_key.try(:to_s).try(:pluralize).try(:to_sym)} was not assigned"
|
141
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
142
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
def awihttps_title(options={})
|
147
|
+
"with #{options[:login]} login#{options[:suffix]}"
|
148
|
+
end
|
149
|
+
|
150
|
+
def assert_access_with_https(*actions)
|
151
|
+
user_options = actions.extract_options!
|
152
|
+
|
153
|
+
options = {
|
154
|
+
:login => :admin
|
155
|
+
}
|
156
|
+
if ( self.constants.include?('ASSERT_ACCESS_OPTIONS') )
|
157
|
+
options.merge!(self::ASSERT_ACCESS_OPTIONS)
|
158
|
+
end
|
159
|
+
options.merge!(user_options)
|
160
|
+
actions += options[:actions]||[]
|
161
|
+
|
162
|
+
m_key = options[:model].try(:underscore).try(:to_sym)
|
163
|
+
|
164
|
+
test "#{brand}AWiHTTPS should get new #{awihttps_title(options)}" do
|
165
|
+
login_as send(options[:login])
|
166
|
+
args = options[:new] || {}
|
167
|
+
turn_https_on
|
168
|
+
send(:get,:new,args)
|
169
|
+
assert_response :success
|
170
|
+
assert_template 'new'
|
171
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
172
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
173
|
+
end if actions.include?(:new) || options.keys.include?(:new)
|
174
|
+
|
175
|
+
test "#{brand}AWiHTTPS should post create #{awihttps_title(options)}" do
|
176
|
+
login_as send(options[:login])
|
177
|
+
args = if options[:create]
|
178
|
+
options[:create]
|
179
|
+
elsif options[:attributes_for_create]
|
180
|
+
{m_key => send(options[:attributes_for_create])}
|
181
|
+
else
|
182
|
+
{}
|
183
|
+
end
|
184
|
+
turn_https_on
|
185
|
+
assert_difference("#{options[:model]}.count",1) do
|
186
|
+
send(:post,:create,args)
|
187
|
+
end
|
188
|
+
assert_response :redirect
|
189
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
190
|
+
end if actions.include?(:create) || options.keys.include?(:create)
|
191
|
+
|
192
|
+
test "#{brand}AWiHTTPS should get edit #{awihttps_title(options)}" do
|
193
|
+
login_as send(options[:login])
|
194
|
+
args={}
|
195
|
+
if options[:method_for_create]
|
196
|
+
obj = send(options[:method_for_create])
|
197
|
+
args[:id] = obj.id
|
198
|
+
end
|
199
|
+
turn_https_on
|
200
|
+
send(:get,:edit, args)
|
201
|
+
assert_response :success
|
202
|
+
assert_template 'edit'
|
203
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
204
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
205
|
+
end if actions.include?(:edit) || options.keys.include?(:edit)
|
206
|
+
|
207
|
+
test "#{brand}AWiHTTPS should put update #{awihttps_title(options)}" do
|
208
|
+
login_as send(options[:login])
|
209
|
+
args={}
|
210
|
+
if options[:method_for_create] && options[:attributes_for_create]
|
211
|
+
obj = send(options[:method_for_create],
|
212
|
+
:updated_at => ( Time.now - 2.days ) )
|
213
|
+
args[:id] = obj.id
|
214
|
+
args[m_key] = send(options[:attributes_for_create])
|
215
|
+
end
|
216
|
+
before = obj.updated_at if obj
|
217
|
+
# sleep 1 if obj # if updated too quickly, updated_at won't change
|
218
|
+
turn_https_on
|
219
|
+
send(:put,:update, args)
|
220
|
+
after = obj.reload.updated_at if obj
|
221
|
+
assert_not_equal( before.to_i,after.to_i, "updated_at did not change" ) if obj
|
222
|
+
assert_response :redirect
|
223
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
224
|
+
end if actions.include?(:update) || options.keys.include?(:update)
|
225
|
+
|
226
|
+
test "#{brand}AWiHTTPS should get show #{awihttps_title(options)}" do
|
227
|
+
login_as send(options[:login])
|
228
|
+
args={}
|
229
|
+
if options[:method_for_create]
|
230
|
+
obj = send(options[:method_for_create])
|
231
|
+
args[:id] = obj.id
|
232
|
+
end
|
233
|
+
turn_https_on
|
234
|
+
send(:get,:show, args)
|
235
|
+
assert_response :success
|
236
|
+
assert_template 'show'
|
237
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
238
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
239
|
+
end if actions.include?(:show) || options.keys.include?(:show)
|
240
|
+
|
241
|
+
test "#{brand}AWiHTTPS should delete destroy #{awihttps_title(options)}" do
|
242
|
+
login_as send(options[:login])
|
243
|
+
args={}
|
244
|
+
if options[:method_for_create]
|
245
|
+
obj = send(options[:method_for_create])
|
246
|
+
args[:id] = obj.id
|
247
|
+
end
|
248
|
+
turn_https_on
|
249
|
+
assert_difference("#{options[:model]}.count",-1) do
|
250
|
+
send(:delete,:destroy,args)
|
251
|
+
end
|
252
|
+
assert_response :redirect
|
253
|
+
assert assigns(m_key), "#{m_key} was not assigned"
|
254
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
255
|
+
end if actions.include?(:destroy) || options.keys.include?(:destroy)
|
256
|
+
|
257
|
+
test "#{brand}AWiHTTPS should get index #{awihttps_title(options)}" do
|
258
|
+
login_as send(options[:login])
|
259
|
+
turn_https_on
|
260
|
+
get :index
|
261
|
+
assert_response :success
|
262
|
+
assert_template 'index'
|
263
|
+
assert assigns(m_key.try(:to_s).try(:pluralize).try(:to_sym)),
|
264
|
+
"#{m_key.try(:to_s).try(:pluralize).try(:to_sym)} was not assigned"
|
265
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
266
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
267
|
+
|
268
|
+
test "#{brand}AWiHTTPS should get index #{awihttps_title(options)} and items" do
|
269
|
+
send(options[:before]) if !options[:before].blank?
|
270
|
+
login_as send(options[:login])
|
271
|
+
3.times{ send(options[:method_for_create]) } if !options[:method_for_create].blank?
|
272
|
+
turn_https_on
|
273
|
+
get :index
|
274
|
+
assert_response :success
|
275
|
+
assert_template 'index'
|
276
|
+
assert assigns(m_key.try(:to_s).try(:pluralize).try(:to_sym)),
|
277
|
+
"#{m_key.try(:to_s).try(:pluralize).try(:to_sym)} was not assigned"
|
278
|
+
assert_nil flash[:error], "flash[:error] was not nil"
|
279
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
def nawihttp_title(options={})
|
284
|
+
"with #{options[:login]} login#{options[:suffix]}"
|
285
|
+
end
|
286
|
+
|
287
|
+
def assert_no_access_with_http(*actions)
|
288
|
+
user_options = actions.extract_options!
|
289
|
+
|
290
|
+
options = {
|
291
|
+
:login => :admin
|
292
|
+
}
|
293
|
+
if ( self.constants.include?('ASSERT_ACCESS_OPTIONS') )
|
294
|
+
options.merge!(self::ASSERT_ACCESS_OPTIONS)
|
295
|
+
end
|
296
|
+
options.merge!(user_options)
|
297
|
+
actions += options[:actions]||[]
|
298
|
+
|
299
|
+
m_key = options[:model].try(:underscore).try(:to_sym)
|
300
|
+
|
301
|
+
test "#{brand}NAWiHTTP should NOT get new #{nawihttp_title(options)}" do
|
302
|
+
turn_https_off
|
303
|
+
login_as send(options[:login])
|
304
|
+
args = options[:new]||{}
|
305
|
+
send(:get,:new,args)
|
306
|
+
assert_redirected_to @controller.url_for(
|
307
|
+
:controller => @controller.controller_name,
|
308
|
+
:action => 'new', :protocol => "https://")
|
309
|
+
end if actions.include?(:new) || options.keys.include?(:new)
|
310
|
+
|
311
|
+
test "#{brand}NAWiHTTP should NOT post create #{nawihttp_title(options)}" do
|
312
|
+
turn_https_off
|
313
|
+
login_as send(options[:login])
|
314
|
+
args = if options[:create]
|
315
|
+
options[:create]
|
316
|
+
elsif options[:attributes_for_create]
|
317
|
+
{m_key => send(options[:attributes_for_create])}
|
318
|
+
else
|
319
|
+
{}
|
320
|
+
end
|
321
|
+
assert_no_difference("#{options[:model]}.count") do
|
322
|
+
send(:post,:create,args)
|
323
|
+
end
|
324
|
+
assert_match @controller.url_for(
|
325
|
+
:controller => @controller.controller_name,
|
326
|
+
:action => 'create', :protocol => "https://"),@response.redirected_to
|
327
|
+
end if actions.include?(:create) || options.keys.include?(:create)
|
328
|
+
|
329
|
+
test "#{brand}NAWiHTTP should NOT get edit #{nawihttp_title(options)}" do
|
330
|
+
turn_https_off
|
331
|
+
login_as send(options[:login])
|
332
|
+
args=options[:edit]||{}
|
333
|
+
if options[:method_for_create]
|
334
|
+
obj = send(options[:method_for_create])
|
335
|
+
args[:id] = obj.id
|
336
|
+
end
|
337
|
+
send(:get,:edit, args)
|
338
|
+
assert_redirected_to @controller.url_for(
|
339
|
+
:controller => @controller.controller_name,
|
340
|
+
:action => 'edit', :id => args[:id], :protocol => "https://")
|
341
|
+
end if actions.include?(:edit) || options.keys.include?(:edit)
|
342
|
+
|
343
|
+
test "#{brand}NAWiHTTP should NOT put update #{nawihttp_title(options)}" do
|
344
|
+
turn_https_off
|
345
|
+
login_as send(options[:login])
|
346
|
+
args={}
|
347
|
+
if options[:method_for_create] && options[:attributes_for_create]
|
348
|
+
obj = send(options[:method_for_create])
|
349
|
+
args[:id] = obj.id
|
350
|
+
args[m_key] = send(options[:attributes_for_create])
|
351
|
+
end
|
352
|
+
before = obj.updated_at if obj
|
353
|
+
send(:put,:update, args)
|
354
|
+
after = obj.reload.updated_at if obj
|
355
|
+
assert_equal( before.to_s(:db), after.to_s(:db), "updated_at changed" ) if obj
|
356
|
+
assert_match @controller.url_for(
|
357
|
+
:controller => @controller.controller_name,
|
358
|
+
:action => 'update', :id => args[:id], :protocol => "https://"), @response.redirected_to
|
359
|
+
end if actions.include?(:update) || options.keys.include?(:update)
|
360
|
+
|
361
|
+
test "#{brand}NAWiHTTP should NOT get show #{nawihttp_title(options)}" do
|
362
|
+
turn_https_off
|
363
|
+
login_as send(options[:login])
|
364
|
+
args=options[:show]||{}
|
365
|
+
if options[:method_for_create]
|
366
|
+
obj = send(options[:method_for_create])
|
367
|
+
args[:id] = obj.id
|
368
|
+
end
|
369
|
+
send(:get,:show, args)
|
370
|
+
assert_redirected_to @controller.url_for(
|
371
|
+
:controller => @controller.controller_name,
|
372
|
+
:action => 'show', :id => args[:id], :protocol => "https://")
|
373
|
+
end if actions.include?(:show) || options.keys.include?(:show)
|
374
|
+
|
375
|
+
test "#{brand}NAWiHTTP should NOT delete destroy #{nawihttp_title(options)}" do
|
376
|
+
turn_https_off
|
377
|
+
login_as send(options[:login])
|
378
|
+
args=options[:destroy]||{}
|
379
|
+
if options[:method_for_create]
|
380
|
+
obj = send(options[:method_for_create])
|
381
|
+
args[:id] = obj.id
|
382
|
+
end
|
383
|
+
assert_no_difference("#{options[:model]}.count") do
|
384
|
+
send(:delete,:destroy,args)
|
385
|
+
end
|
386
|
+
assert_redirected_to @controller.url_for(
|
387
|
+
:controller => @controller.controller_name,
|
388
|
+
:action => 'destroy', :id => args[:id], :protocol => "https://")
|
389
|
+
end if actions.include?(:destroy) || options.keys.include?(:destroy)
|
390
|
+
|
391
|
+
test "#{brand}NAWiHTTP should NOT get index #{nawihttp_title(options)}" do
|
392
|
+
turn_https_off
|
393
|
+
login_as send(options[:login])
|
394
|
+
get :index
|
395
|
+
assert_redirected_to @controller.url_for(
|
396
|
+
:controller => @controller.controller_name,
|
397
|
+
:action => 'index', :protocol => "https://")
|
398
|
+
end if actions.include?(:index) || options.keys.include?(:index)
|
399
|
+
|
400
|
+
end
|
401
|
+
|
402
|
+
end # module ClassMethods
|
403
|
+
end # module CommonLib::ActionControllerExtension::AccessibleViaProtocol
|
404
|
+
ActionController::TestCase.send(:include,
|
405
|
+
CommonLib::ActionControllerExtension::AccessibleViaProtocol)
|