filter_form 0.8.2 → 0.8.3

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
  !binary "U0hBMQ==":
3
- metadata.gz: 46c6a58b11f78f33bf95db4070aeebdc01d1461e
4
- data.tar.gz: 098c3ec61496b73b4a54bf41b4d34182ceda52ec
3
+ metadata.gz: 61f48ddb9a951f24ca2c7f1c637f8c46387ebb63
4
+ data.tar.gz: a44a6a392a2f1714c06ce37d3eb83f20d8c89e3c
5
5
  SHA512:
6
- metadata.gz: 9d941db09900aaa526c33d9e63f71e38351551c13ab457fc8e4190da3995224690069ad5d28f612049f1eef5a3c6c368067e4895f804434f7ccf86f73c6f7e3d
7
- data.tar.gz: b033d09304ba27afe144216b3d46d1d4bb54320dace72c929e0196e1646e603c7730fb2f61e7cccbe44923bc4c5b7a6fd51126b570075ac7fdc9fc0c03123260
6
+ metadata.gz: 912056cb716eabd7eb85bb4182cfbffb18819cc202c396f62b8001c2b3b637b0a124ba7acb788f8c26c49f1499e0696d95a1c3d268551f97359e9291b2e8dc6a
7
+ data.tar.gz: 612c03cae32f18acf25a6543bc03c33597a442387582b435f08638437a28f092c808b612639e8fe212db3b3dba9e166ae038a3566fcdee9d0a1f42e1a0948a2f
@@ -7,6 +7,12 @@ module FilterForm
7
7
  html: { class: 'filter_form', novalidate: true }
8
8
  })
9
9
 
10
+ record.instance_eval do
11
+ def model_name
12
+ klass.model_name
13
+ end
14
+ end
15
+
10
16
  simple_form_for(record, options, &block)
11
17
  end
12
18
  end
@@ -101,10 +101,10 @@ module FilterForm
101
101
 
102
102
  def object_condition
103
103
  if options[:predicate_selector]
104
- object.base.conditions.select { |condition| condition.a.first.name == input_attribute_name.to_s }.first
104
+ object.base.conditions.select { |condition| condition.a.first.name == input_attribute_name }.first
105
105
  else
106
106
  object.base.conditions.select do |condition|
107
- condition.a.first.name == input_attribute_name.to_s && condition.predicate.name == predicate.to_s
107
+ condition.a.first.name == input_attribute_name && condition.predicate.name == predicate.to_s
108
108
  end.first
109
109
  end
110
110
  end
@@ -12,13 +12,14 @@ require 'filter_form/input_options/datetime/base'
12
12
 
13
13
  module FilterForm
14
14
  class InputOptionsBuilder
15
- attr_accessor :attribute_name, :object, :custom_predicate, :custom_type
15
+ attr_accessor :object, :custom_predicate, :custom_type
16
+ attr_reader :attribute_name
16
17
 
17
18
  def initialize(options)
18
- @attribute_name = options[:attribute_name]
19
19
  @object = options[:object]
20
20
  @custom_predicate = options[:custom_predicate]
21
21
  @custom_type = options[:custom_type]
22
+ self.attribute_name = options[:attribute_name]
22
23
  end
23
24
 
24
25
 
@@ -26,6 +27,10 @@ module FilterForm
26
27
  input_options_class.new(attribute_name: attribute_name, object: object, custom_predicate: custom_predicate, options: options).simple_form_options
27
28
  end
28
29
 
30
+ def attribute_name=(new_attribute_name)
31
+ @attribute_name = new_attribute_name.to_s
32
+ end
33
+
29
34
  private
30
35
 
31
36
  def input_options_class
@@ -77,7 +82,7 @@ module FilterForm
77
82
  elsif money?
78
83
  :money
79
84
  else
80
- object.klass.columns_hash[attribute_name.to_s].type
85
+ object.klass.columns_hash[attribute_name].type
81
86
  end
82
87
  end
83
88
  end
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.8.2'
2
+ VERSION = '0.8.3'
3
3
  end
@@ -8,15 +8,14 @@ describe FilterForm::InputOptionsBuilder do
8
8
  let(:builder) { FilterForm::InputOptionsBuilder.new(object: search) }
9
9
 
10
10
  context 'boolean' do
11
- before do
12
- builder.attribute_name = :married
13
- end
14
-
15
11
  context 'default predicate' do
16
12
  it 'returns correct options with predicate "true"' do
17
- result = builder.build
18
- options = { as: :boolean, required: false, label: 'MARRIED IS TRUE', input_html: { name: 'q[married_true]', checked: false } }
19
- expect(result).to eq(options)
13
+ builder.attribute_name = :married
14
+
15
+ result = builder.build
16
+
17
+ expected_result = { as: :boolean, required: false, label: 'MARRIED IS TRUE', input_html: { name: 'q[married_true]', checked: false } }
18
+ expect(result).to eq(expected_result)
20
19
  end
21
20
  end
22
21
  end
@@ -41,29 +40,27 @@ describe FilterForm::InputOptionsBuilder do
41
40
  end
42
41
 
43
42
  context 'text' do
44
- before do
45
- builder.attribute_name = :about
46
- end
47
-
48
43
  context 'default predicate' do
49
44
  it 'returns correct options with predicate "cont"' do
50
- result = builder.build
51
- options = { as: :string, required: false, label: 'ABOUT CONTAINS', input_html: { name: 'q[about_cont]' } }
52
- expect(result).to eq(options)
45
+ builder.attribute_name = :about
46
+
47
+ result = builder.build
48
+
49
+ expected_result = { as: :string, required: false, label: 'ABOUT CONTAINS', input_html: { name: 'q[about_cont]' } }
50
+ expect(result).to eq(expected_result)
53
51
  end
54
52
  end
55
53
  end
56
54
 
57
55
  context 'money' do
58
- before do
59
- builder.attribute_name = :amount
60
- end
61
-
62
56
  context 'default predicate' do
63
57
  it 'returns correct options with predicate "eq"' do
64
- result = builder.build
65
- options = { as: :integer, required: false, label: 'AMOUNT EQUALS', input_html: { name: 'q[amount_eq]', step: 'any' } }
66
- expect(result).to eq(options)
58
+ builder.attribute_name = :amount
59
+
60
+ result = builder.build
61
+
62
+ expected_result = { as: :integer, required: false, label: 'AMOUNT EQUALS', input_html: { name: 'q[amount_eq]', step: 'any' } }
63
+ expect(result).to eq(expected_result)
67
64
  end
68
65
  end
69
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filter_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_form