filter_form 0.8.0 → 0.8.1

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: b926b0a351c9f2123caa31f855bd694e1d576cf5
4
- data.tar.gz: 9df2378898485ab118798cdb0ada280ae3cb801e
3
+ metadata.gz: 0bdd28148acf26ef60072eae5ad45e275b4c2299
4
+ data.tar.gz: 3ba9fe6625752961a0dfd497c9e3d70474d44e34
5
5
  SHA512:
6
- metadata.gz: c0cc369611f6e9eb2e402381e982218d3aac29d647edf7bb9fc3630aa87931d874bd944dd89ec95c090f9fec91278c2b4e28d4aefbb5f67ffae3d11a69b69491
7
- data.tar.gz: 75d3adf19bb9f28bd17c77c217a73a22a210ccb4fb43c9a60f2a54318519164b27c6075378cd7afe9bb77e0d310663cdfb6dba99920f9776b103460301675919
6
+ metadata.gz: be205121e2fb7611e75a85bedfdfb216870fd7c733cb42621a8a9d624d5be7c1a818a529f371c04aeb6c02cc5640fbda692c59841920024d747e47ee8c304b48
7
+ data.tar.gz: 451d19c190406e4f9ef48ede4ed448ca8b41e6caea2795d05195cc8857e8432199438cf8fd389701a2303a2b7ecbbb4dcaffdd460efec6c0f83a70eeaa11e88e
@@ -2,6 +2,7 @@ module FilterForm
2
2
  module InputOptions
3
3
  class Base
4
4
  DEFAULT_PREDICATE = nil
5
+ PREDICATE_IN = :in
5
6
 
6
7
  attr_accessor :attribute_name, :object, :custom_predicate, :options
7
8
 
@@ -84,8 +85,14 @@ module FilterForm
84
85
  nil
85
86
  end
86
87
 
88
+ def multiple?
89
+ options[:input_html].try(:[], :multiple)
90
+ end
91
+
87
92
  def input_name
88
- "q[#{ input_attribute_name }_#{ predicate }]"
93
+ result = "q[#{ input_attribute_name }_#{ predicate }]"
94
+ result << "[]" if multiple?
95
+ result
89
96
  end
90
97
 
91
98
  def input_value
@@ -106,8 +113,12 @@ module FilterForm
106
113
  attribute_name
107
114
  end
108
115
 
116
+ def default_predicate
117
+ multiple? ? PREDICATE_IN : self.class::DEFAULT_PREDICATE
118
+ end
119
+
109
120
  def predicate
110
- custom_predicate || self.class::DEFAULT_PREDICATE
121
+ custom_predicate || default_predicate
111
122
  end
112
123
  end
113
124
  end
@@ -4,10 +4,12 @@ module FilterForm
4
4
  class Base < FilterForm::InputOptions::Base
5
5
  include FilterForm::InputOptions::Shared::WithAssociations
6
6
 
7
- DEFAULT_PREDICATE = :in
8
-
9
7
  private
10
8
 
9
+ def default_predicate
10
+ PREDICATE_IN
11
+ end
12
+
11
13
  def additional_options
12
14
  {
13
15
  as: :check_boxes,
@@ -11,7 +11,9 @@ module FilterForm
11
11
  end
12
12
 
13
13
  def input_name
14
- "q[#{ attribute_name }_#{ predicate }]"
14
+ result = "q[#{ attribute_name }_#{ predicate }]"
15
+ result << "[]" if multiple?
16
+ result
15
17
  end
16
18
 
17
19
  def input_attribute_name
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.8.0'
2
+ VERSION = '0.8.1'
3
3
  end
@@ -10,3 +10,4 @@ ransack:
10
10
  'true': "IS TRUE"
11
11
  cont: "CONTAINS"
12
12
  eq: "EQUALS"
13
+ in: "IN"
@@ -22,15 +22,20 @@ describe FilterForm::InputOptionsBuilder do
22
22
  end
23
23
 
24
24
  context 'string' do
25
- before do
26
- builder.attribute_name = :name
27
- end
28
-
29
25
  context 'default predicate' do
30
26
  it 'returns correct options with predicate "cont"' do
31
- result = builder.build
32
- options = { as: :string, required: false, label: 'NAME CONTAINS', input_html: { name: 'q[name_cont]' } }
33
- expect(result).to eq(options)
27
+ builder.attribute_name = :name
28
+
29
+ expect(builder.build).to eq({ as: :string, required: false, label: 'NAME CONTAINS', input_html: { name: 'q[name_cont]' } })
30
+ end
31
+ end
32
+
33
+ context "multiple" do
34
+ it "returns attribute name as array with default predicate 'in'" do
35
+ builder.attribute_name = :name
36
+ result = builder.build(input_html: { multiple: true })
37
+
38
+ expect(result).to eq({ as: :string, required: false, label: "NAME IN", input_html: { name: "q[name_in][]", multiple: true } })
34
39
  end
35
40
  end
36
41
  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.0
4
+ version: 0.8.1
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-07-02 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_form