jakewendt-rails_extension 2.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,67 @@
1
+ # Some code from jeremymcanally's "pending"
2
+ # http://github.com/jeremymcanally/pending/tree/master
3
+
4
+ module RailsExtension::ActiveSupportExtension::Pending
5
+ unless defined?(Spec)
6
+
7
+ @@pending_cases = []
8
+ @@at_exit = false
9
+
10
+ def pending(description = "", &block)
11
+ if description.is_a?(Symbol)
12
+ is_pending = $tags[description]
13
+ return block.call unless is_pending
14
+ end
15
+
16
+ if block_given?
17
+ failed = false
18
+
19
+ begin
20
+ block.call
21
+ rescue Exception
22
+ failed = true
23
+ end
24
+
25
+ flunk("<#{description}> did not fail.") unless failed
26
+ end
27
+
28
+ caller[0] =~ (/(.*):(.*):in `(.*)'/)
29
+ #puts caller.inspect
30
+
31
+ # looks like we lose the name of the 'method' in 1.9.1
32
+ #"/Users/jakewendt/github_repo/jakewendt/ucb_ccls_homex/test/unit/subject_test.rb:145:in `block in <class:SubjectTest>'",
33
+
34
+ # @@pending_cases << "#{$3} at #{$1}, line #{$2}"
35
+ # Gotta remember these as the next Regex will overwrite them.
36
+ filename = $1
37
+ linenumber = $2
38
+ # ruby 1.8.7
39
+ # Hx/Addresses Controller should NOT create new address with employee login and invalid address:
40
+ # ruby 1.9.1
41
+ #Hx/Addresses Controller block (2 levels) in <class:AddressesControllerTest>:
42
+ testmethod = $3
43
+
44
+ model = self.class.to_s.gsub(/Test$/,'').titleize
45
+ method = testmethod.gsub(/_/,' ').gsub(/^test /,'')
46
+ @@pending_cases << "#{model} #{method}:\n.\t#{filename} line #{linenumber}"
47
+ # @@pending_cases << "#{testmethod} at #{filename}, line #{linenumber}"
48
+ print "P"
49
+
50
+ @@at_exit ||= begin
51
+ at_exit do
52
+ # For some reason, special characters don't always
53
+ # print the way you would expect. Leading white space (tabs)
54
+ # and some carriage returns just weren't happening?
55
+ # Is this at_exit doing some parsing??
56
+ puts "\nPending Cases:"
57
+ @@pending_cases.each do |test_case|
58
+ puts test_case
59
+ end
60
+ puts " \n"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ ActiveSupport::TestCase.send(:include,
67
+ RailsExtension::ActiveSupportExtension::Pending)
@@ -0,0 +1,211 @@
1
+ module RailsExtension::ActiveSupportExtension::TestCase
2
+
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ base.send(:include, InstanceMethods)
6
+ base.alias_method_chain :method_missing, :create_object
7
+
8
+ # I can't seem to find out how to confirm that
9
+ # method_missing_without_create_object
10
+ # doesn't already exist! WTF
11
+ # We don't want to alias it if we already have.
12
+ # tried viewing methods, instance_methods, etc.
13
+ # seems to only work when "inherited" and since
14
+ # some thing are inherited from subclasses it
15
+ # might get a bit hairy. No problems now, just
16
+ # trying to avoid them in the future.
17
+
18
+ base.class_eval do
19
+ #alias_method(:method_missing_without_create_object,:method_missing)
20
+ #alias_method(:method_missing,:method_missing_with_create_object)
21
+ # class << self
22
+ # alias_method_chain :method_missing, :create_object #unless
23
+ # respond_to?(:method_missing_without_create_object)
24
+ # end
25
+ class << self
26
+ alias_method_chain( :test, :verbosity ) unless method_defined?(:test_without_verbosity)
27
+ end
28
+ end #unless base.respond_to?(:test_without_verbosity)
29
+ #puts base.respond_to?(:method_missing_without_create_object)
30
+ #puts base.method_defined?(:method_missing_without_create_object)
31
+ # apparently medding with method_missing is also a bit of an issue
32
+ end
33
+
34
+ module ClassMethods
35
+
36
+ # I don't like this quick and dirty name
37
+ def st_model_name
38
+ self.name.demodulize.sub(/Test$/,'')
39
+ end
40
+
41
+ def test_with_verbosity(name,&block)
42
+ test_without_verbosity(name,&block)
43
+
44
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
45
+ define_method("_#{test_name}_with_verbosity") do
46
+ print "\n#{self.class.name.gsub(/Test$/,'').titleize} #{name}: "
47
+ send("_#{test_name}_without_verbosity")
48
+ end
49
+ #
50
+ # can't do this.
51
+ # alias_method_chain test_name, :verbosity
52
+ # end up with 2 methods that begin
53
+ # with 'test_' so they both get run
54
+ #
55
+ alias_method "_#{test_name}_without_verbosity".to_sym,
56
+ test_name
57
+ alias_method test_name,
58
+ "_#{test_name}_with_verbosity".to_sym
59
+ end
60
+
61
+ def assert_should_act_as_list(*args)
62
+ options = args.extract_options!
63
+ scope = options[:scope]
64
+
65
+ test "#{brand}should act as list" do
66
+ model = create_object.class.name
67
+ model.constantize.destroy_all
68
+ object = create_object
69
+ assert_equal 1, object.position
70
+ attrs = {}
71
+ Array(scope).each do |attr|
72
+ attrs[attr.to_sym] = object.send(attr)
73
+ end if scope
74
+ object = create_object(attrs)
75
+ assert_equal 2, object.position
76
+
77
+ # gotta be a relative test as there may already
78
+ # by existing objects (unless I destroy them)
79
+ assert_difference("#{model}.last.position",1) do
80
+ create_object(attrs)
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ #
87
+ #
88
+ # What? No assert_requires_absence method???
89
+ # Its usually conditional so would be pretty pointless
90
+ #
91
+ #
92
+
93
+ def assert_requires_past_date(*attr_names)
94
+ attr_names.each do |attr_name|
95
+ test "should require #{attr_name} be in the past" do
96
+ # can't assert difference of 1 as may be other errors
97
+ object = create_object( attr_name => Chronic.parse('yesterday'))
98
+ assert !object.errors.on_attr_and_type(attr_name,:not_past_date)
99
+ assert_difference( "#{model_name}.count", 0 ) do
100
+ object = create_object( attr_name => Chronic.parse('tomorrow'))
101
+ assert object.errors.on_attr_and_type(attr_name,:not_past_date)
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ def assert_requires_complete_date(*attr_names)
108
+ attr_names.each do |attr_name|
109
+ test "should require a complete date for #{attr_name}" do
110
+ #
111
+ #
112
+ # What? No successful test?
113
+ #
114
+ #
115
+ assert_difference( "#{model_name}.count", 0 ) do
116
+ object = create_object( attr_name => "Sept 2010")
117
+ assert object.errors.on_attr_and_type(attr_name,:not_complete_date)
118
+ end
119
+ assert_difference( "#{model_name}.count", 0 ) do
120
+ object = create_object( attr_name => "9/2010")
121
+ assert object.errors.on_attr_and_type(attr_name,:not_complete_date)
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+ end
128
+
129
+ module InstanceMethods
130
+
131
+ at_exit {
132
+ puts Dir.pwd()
133
+ puts Time.now
134
+ }
135
+
136
+ def model_name
137
+ # self.class.name.sub(/Test$/,'')
138
+ # self.class.name.demodulize.sub(/Test$/,'')
139
+ self.class.st_model_name
140
+ end
141
+
142
+ def method_missing_with_create_object(symb,*args, &block)
143
+ method = symb.to_s
144
+ # if method =~ /^create_(.+)(\!?)$/
145
+ if method =~ /^create_([^!]+)(!?)$/
146
+ factory = if( $1 == 'object' )
147
+ # doesn't work for controllers yet. Need to consider
148
+ # singular and plural as well as "tests" method.
149
+ # Probably should just use the explicit factory
150
+ # name in the controller tests.
151
+ # self.class.name.sub(/Test$/,'').underscore
152
+ model_name.underscore
153
+ else
154
+ $1
155
+ end
156
+ bang = $2
157
+ options = args.extract_options!
158
+ if bang.blank?
159
+ record = Factory.build(factory,options)
160
+
161
+
162
+
163
+ # record.attributes = options # occassionally needed (study_subject_id)
164
+
165
+
166
+
167
+ record.save
168
+ record
169
+ else
170
+ Factory(factory,options)
171
+ end
172
+ else
173
+ # super(symb,*args, &block)
174
+ method_missing_without_create_object(symb,*args, &block)
175
+ end
176
+ end
177
+
178
+ # basically a copy of assert_difference, but
179
+ # without any explicit comparison as it is
180
+ # simply stating that something will change
181
+ # (designed for updated_at)
182
+ def assert_changes(expression, message = nil, &block)
183
+ b = block.send(:binding)
184
+ exps = Array.wrap(expression)
185
+ before = exps.map { |e| eval(e, b) }
186
+ yield
187
+ exps.each_with_index do |e, i|
188
+ error = "#{e.inspect} didn't change"
189
+ error = "#{message}.\n#{error}" if message
190
+ assert_not_equal(before[i], eval(e, b), error)
191
+ end
192
+ end
193
+
194
+ # Just a negation of assert_changes
195
+ def deny_changes(expression, message = nil, &block)
196
+ b = block.send(:binding)
197
+ exps = Array.wrap(expression)
198
+ before = exps.map { |e| eval(e, b) }
199
+ yield
200
+ exps.each_with_index do |e, i|
201
+ error = "#{e.inspect} changed"
202
+ error = "#{message}.\n#{error}" if message
203
+ assert_equal(before[i], eval(e, b), error)
204
+ end
205
+ end
206
+
207
+ end # InstanceMethods
208
+ end # RailsExtension::TestCase
209
+ ActiveSupport::TestCase.send(:include,
210
+ RailsExtension::ActiveSupportExtension::TestCase)
211
+
@@ -0,0 +1 @@
1
+ require 'jakewendt-rails_extension'
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jakewendt-rails_extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 35
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 22
10
+ version: 2.0.22
11
+ platform: ruby
12
+ authors:
13
+ - Jake
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-08 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 2
32
+ version: "2"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: ssl_requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 27
44
+ segments:
45
+ - 0
46
+ - 1
47
+ - 0
48
+ version: 0.1.0
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: jakewendt-html_test
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: chronic
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ description: Collection of validations and complex assertions
80
+ email: github@jakewendt.com
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files:
86
+ - LICENSE
87
+ - README.rdoc
88
+ files:
89
+ - generators/rails_extension/USAGE
90
+ - generators/rails_extension/rails_extension_generator.rb
91
+ - lib/jakewendt-rails_extension.rb
92
+ - lib/rails_extension.rb
93
+ - lib/rails_extension/action_controller_extension.rb
94
+ - lib/rails_extension/action_controller_extension/accessible_via_format.rb
95
+ - lib/rails_extension/action_controller_extension/accessible_via_protocol.rb
96
+ - lib/rails_extension/action_controller_extension/accessible_via_user.rb
97
+ - lib/rails_extension/action_controller_extension/routing.rb
98
+ - lib/rails_extension/action_controller_extension/test_case.rb
99
+ - lib/rails_extension/active_record_extension.rb
100
+ - lib/rails_extension/active_record_extension/base.rb
101
+ - lib/rails_extension/active_record_extension/error.rb
102
+ - lib/rails_extension/active_record_extension/errors.rb
103
+ - lib/rails_extension/active_support_extension.rb
104
+ - lib/rails_extension/active_support_extension/associations.rb
105
+ - lib/rails_extension/active_support_extension/attributes.rb
106
+ - lib/rails_extension/active_support_extension/pending.rb
107
+ - lib/rails_extension/active_support_extension/test_case.rb
108
+ - rails/init.rb
109
+ - LICENSE
110
+ - README.rdoc
111
+ has_rdoc: true
112
+ homepage: http://github.com/jakewendt/rails_extension
113
+ licenses: []
114
+
115
+ post_install_message:
116
+ rdoc_options: []
117
+
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ requirements: []
139
+
140
+ rubyforge_project:
141
+ rubygems_version: 1.6.2
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Validations and assertions
145
+ test_files: []
146
+