eita-jrails 0.9.8 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20613f4c1876b587fc3793a6d04c8fb63130f3a8
4
- data.tar.gz: d04aab7ff8ee7c5be2c0a8b657253eb2e151e53e
3
+ metadata.gz: 5cf7c9e8c1a449a826bde01ea0688f5d44778646
4
+ data.tar.gz: b24f5cb2c44c3d8866e46e39479764305fb59fbf
5
5
  SHA512:
6
- metadata.gz: 762fa79c93475085c597f4e698d887ae867e33fbe991b26fd9413c39c47f9a5551f9071664aa5e080860c22d93c79ce07939b37a7cd7474bc3426ed3a800864e
7
- data.tar.gz: c1e55f831ec4c7779d3d0b6f40d08acb3f4979629bf5b56fd793c8a12deb413a5abefef2833a9a57cc015cf0924912f77feafa5b2a8035b89b627ef3f3bee633
6
+ metadata.gz: c2a218e5e17496de12a8be15af618e06aa82ad174be969800ae877fad993aa013bb3d63245889f55462f1828fb42ed3f1ce34fe2d840902dd6402a3074eedfcf
7
+ data.tar.gz: 0f4f470abce7f396bc89d58f6e0f699745785874d3bbaa255fe87bd51b79d6467bf64b8fbb478d30f66531771482abb5f48a08f993e46a83538d1c4213fd6b10
@@ -328,26 +328,26 @@ module ActionView
328
328
  # If you don't need to attach a form to a resource, then check out form_remote_tag.
329
329
  #
330
330
  # See FormHelper#form_for for additional semantics.
331
- def remote_form_for(record_or_name_or_array, *args, &proc)
332
- options = args.extract_options!
331
+ def remote_form_for record, options = {}, &block
332
+ as = options[:as]
333
333
 
334
- case record_or_name_or_array
334
+ case record
335
335
  when String, Symbol
336
- object_name = record_or_name_or_array
337
- when Array
338
- object = record_or_name_or_array.last
339
- object_name = ActiveModel::Naming.singular(object)
340
- apply_form_for_options!(record_or_name_or_array, options)
341
- args.unshift object
336
+ object_name = record
337
+ object = nil
342
338
  else
343
- object = record_or_name_or_array
344
- object_name = ActiveModel::Naming.singular(record_or_name_or_array)
345
- apply_form_for_options!(object, options)
346
- args.unshift object
339
+ object = if record.is_a? Array then record.last else record end
340
+ if Rails::VERSION::MAJOR >= 4
341
+ object_name = as || model_name_from_record_or_class(object).param_key
342
+ apply_form_for_options! record, object, options
343
+ else
344
+ object_name = as || ActiveModel::Naming.param_key(object)
345
+ apply_form_for_options! record, options
346
+ end
347
347
  end
348
348
 
349
349
  form_remote_tag options do
350
- fields_for object_name, *(args << options), &proc
350
+ fields_for object, options, &block
351
351
  end
352
352
  end
353
353
  alias_method :form_remote_for, :remote_form_for
@@ -1,8 +1,8 @@
1
- # FIXME: support rails 4.2
2
- if Rails::VERSION::STRING < "4.2.0"
3
1
 
4
2
  require 'active_support/core_ext/module/aliasing'
5
- if Rails::VERSION::STRING < "4.1.0"
3
+ if Rails::VERSION::STRING >= "4.2.0"
4
+ # uses nokogiri
5
+ elsif Rails::VERSION::STRING < "4.1.0"
6
6
  require 'action_controller/vendor/html-scanner'
7
7
  else
8
8
  require 'action_view/vendor/html-scanner'
@@ -15,7 +15,14 @@ require 'action_dispatch/testing/assertions/selector'
15
15
  # Under MIT and/or CC By license.
16
16
  #++
17
17
 
18
- ActionDispatch::Assertions::SelectorAssertions.module_eval do
18
+ module JRails::SelectorAssertions
19
+
20
+ if Rails::VERSION::STRING >= "4.2.0"
21
+ def response_from_page
22
+ html_document.root
23
+ end
24
+ end
25
+
19
26
  # Selects content from the RJS response.
20
27
  #
21
28
  # === Narrowing down
@@ -122,11 +129,20 @@ ActionDispatch::Assertions::SelectorAssertions.module_eval do
122
129
  when :remove, :show, :hide, :toggle
123
130
  matches = @response.body.match(pattern)
124
131
  else
125
- @response.body.gsub(pattern) do |match|
126
- html = unescape_rjs(match)
127
- matches ||= []
128
- matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? }
129
- ""
132
+ if Rails::VERSION::STRING >= "4.2.0"
133
+ @response.body.gsub pattern do |match|
134
+ html = unescape_rjs match
135
+ matches ||= Nokogiri::HTML.fragment ''
136
+ Nokogiri::HTML(html).root.children.each{ |n| matches.add_child n if n.element? }
137
+ ""
138
+ end
139
+ else
140
+ @response.body.gsub pattern do |match|
141
+ html = unescape_rjs match
142
+ matches ||= []
143
+ matches.concat HTML::Document.new(html).root.children.select{ |n| n.tag? }
144
+ ""
145
+ end
130
146
  end
131
147
  end
132
148
 
@@ -184,19 +200,34 @@ ActionDispatch::Assertions::SelectorAssertions.module_eval do
184
200
 
185
201
  if content_type && Mime::JS =~ content_type
186
202
  body = @response.body.dup
187
- root = HTML::Node.new(nil)
188
-
189
- while true
190
- next if body.sub!(RJS_STATEMENTS[:any]) do |match|
191
- html = unescape_rjs(match)
192
- matches = HTML::Document.new(html).root.children.select { |n| n.tag? }
193
- root.children.concat matches
194
- ""
203
+ if Rails::VERSION::STRING >= "4.2.0"
204
+ root = Nokogiri::HTML.fragment ''
205
+
206
+ while true
207
+ next if body.sub!(RJS_STATEMENTS[:any]) do |match|
208
+ html = unescape_rjs match
209
+ Nokogiri::HTML(html).root.children.each{ |n| root.add_child n if n.element? }
210
+ ""
211
+ end
212
+ break
195
213
  end
196
- break
197
- end
198
214
 
199
- root
215
+ root
216
+ else
217
+ root = HTML::Node.new(nil)
218
+
219
+ while true
220
+ next if body.sub!(RJS_STATEMENTS[:any]) do |match|
221
+ html = unescape_rjs(match)
222
+ matches = HTML::Document.new(html).root.children.select { |n| n.tag? }
223
+ root.children.concat matches
224
+ ""
225
+ end
226
+ break
227
+ end
228
+
229
+ root
230
+ end
200
231
  else
201
232
  response_from_page_without_rjs
202
233
  end
@@ -217,4 +248,6 @@ ActionDispatch::Assertions::SelectorAssertions.module_eval do
217
248
  end
218
249
  end
219
250
 
251
+ ActionDispatch::Assertions.module_eval do
252
+ include JRails::SelectorAssertions
220
253
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eita-jrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Eisenberger
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.4.6
114
+ rubygems_version: 2.4.5
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: RJS and JqueryHelper/JqueryUiHelper with the same API from prototype-rails