adva-core 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module AdvaCore
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -2,9 +2,12 @@ require 'action_view/helpers/form_helper'
2
2
 
3
3
  ActionView::Helpers::FormBuilder.send :include do
4
4
  def has_many_through_collection_check_boxes(attribute, collection, label_attribute)
5
+ return if collection.empty?
5
6
  through_class = object.class.reflect_on_association(attribute).class_name.constantize
6
7
  foreign_key = through_class.reflect_on_all_associations(:belongs_to).detect { |r| r.class_name != object.class.name }.primary_key_name
7
8
 
9
+ item_class = collection.first.class.name.underscore.gsub('/', '_')
10
+ # TODO: wouldn't it be better to render the checkboxes as a list(iw)
8
11
  html = ''
9
12
  collection.each_with_index do |item, ix|
10
13
  param = "#{object_name}[#{attribute}_attributes][#{ix}]"
@@ -13,11 +16,11 @@ ActionView::Helpers::FormBuilder.send :include do
13
16
  if through
14
17
  html << @template.hidden_field_tag("#{param}[id]", through.id, :id => '')
15
18
  html << @template.hidden_field_tag("#{param}[_destroy]", '1', :id => '')
16
- html << @template.label_tag("#{param}[_destroy]", :class => 'checkbox') do
19
+ html << @template.label_tag("#{param}[_destroy]", :class => "checkbox #{item_class}") do
17
20
  @template.check_box_tag("#{param}[_destroy]", '0', true) + item.send(label_attribute)
18
21
  end
19
22
  else
20
- html << @template.label_tag("#{param}[#{foreign_key}]", :class => 'checkbox') do
23
+ html << @template.label_tag("#{param}[#{foreign_key}]", :class => "checkbox #{item_class}") do
21
24
  @template.check_box_tag("#{param}[#{foreign_key}]", item.id) + item.send(label_attribute)
22
25
  end
23
26
  end
@@ -0,0 +1,44 @@
1
+ # https://gist.github.com/730257
2
+ # bars.where(bars[:id].in(foos.project(:bar_id).where(...)))
3
+
4
+ Gem.patching('arel', '2.0.6') do
5
+ Arel::Predications.module_eval do
6
+ def in_with_select_fix(other)
7
+ case other
8
+ when Arel::SelectManager
9
+ Arel::Nodes::In.new(self, other)
10
+ else
11
+ in_without_select_fix(other)
12
+ end
13
+ end
14
+ alias_method_chain :in, :select_fix
15
+
16
+ def not_in_with_select_fix(other)
17
+ case other
18
+ when Arel::SelectManager
19
+ Arel::Nodes::NotIn.new(self, other)
20
+ else
21
+ in_without_select_fix(other)
22
+ end
23
+ end
24
+ alias_method_chain :not_in, :select_fix
25
+ end
26
+
27
+ Arel::Visitors::ToSql.class_eval do
28
+ def visit_Arel_SelectManager o
29
+ o.to_sql
30
+ end
31
+
32
+ def visit_Arel_Nodes_In o
33
+ "#{visit o.left} IN (#{visit o.right})"
34
+ end
35
+
36
+ def visit_Arel_Nodes_NotIn o
37
+ "#{visit o.left} NOT IN (#{visit o.right})"
38
+ end
39
+
40
+ def visit_Array o
41
+ o.empty? ? 'NULL' : o.map { |x| visit x }.join(', ')
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,13 @@
1
+ # see https://webrat.lighthouseapp.com/projects/10503/tickets/153-within-should-support-xpath
2
+
3
+ Gem.patching('webrat', '0.7.2') do
4
+ Webrat::Scope.class_eval do
5
+ def scoped_dom
6
+ if @selector =~ /^\.?\/\/?/
7
+ @scope.dom.xpath(@selector).first
8
+ else
9
+ @scope.dom.css(@selector).first
10
+ end
11
+ end
12
+ end
13
+ end if defined?(Webrat)
@@ -285,3 +285,14 @@ Then /^I should see "([^"]*)" formatted as a "([^"]*)" tag$/ do |value, tag|
285
285
  assert_select(tag, value)
286
286
  end
287
287
 
288
+ Then /^I should see (\d+|no|one|two|three) ([a-z ]+)$/ do |amount, item_class|
289
+ amount = case amount
290
+ when 'no' then 0
291
+ when 'one' then 1
292
+ when 'two' then 2
293
+ when 'three' then 3
294
+ else amount.to_i
295
+ end
296
+ assert_select ".#{item_class.gsub(' ', '_').singularize}", :count => amount
297
+ end
298
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adva-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ingo Weiss
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-03 00:00:00 +01:00
19
+ date: 2010-12-18 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -203,12 +203,12 @@ dependencies:
203
203
  requirements:
204
204
  - - "="
205
205
  - !ruby/object:Gem::Version
206
- hash: 41
206
+ hash: 39
207
207
  segments:
208
208
  - 0
209
209
  - 0
210
- - 27
211
- version: 0.0.27
210
+ - 28
211
+ version: 0.0.28
212
212
  type: :runtime
213
213
  version_requirements: *id012
214
214
  - !ruby/object:Gem::Dependency
@@ -323,6 +323,7 @@ files:
323
323
  - lib/core_ext/ruby/array/flatten_once.rb
324
324
  - lib/patches/webrat/logger.rb
325
325
  - lib/patches/webrat/upload_file.rb
326
+ - lib/patches/webrat/within_xpath.rb
326
327
  - lib/patches/webrat/links-data-method.rb
327
328
  - lib/patches/rails/asset_expansion_multiple_registrations.rb
328
329
  - lib/patches/rails/recognize_path_env.rb
@@ -336,6 +337,7 @@ files:
336
337
  - lib/patches/inherited_resources.rb
337
338
  - lib/patches/responders/flash_responder.rb
338
339
  - lib/patches/simple_form.rb
340
+ - lib/patches/arel_in_subquery.rb
339
341
  - lib/patches/thor/group/symbolized_options.rb
340
342
  - lib/patches/thor/core_ext/hash.rb
341
343
  - lib/adva-core.rb