filter_form 0.7.7 → 0.7.9

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: a5c8473bff6527d8fa6c754e72b47cf579fa7847
4
- data.tar.gz: 66261f34afff3cab2d578d78bc7faa5e1756a314
3
+ metadata.gz: af64eb081604349e69bcd198177df4bd0173d6d4
4
+ data.tar.gz: 1e74b0a772eddb4c921d1d4e0d1dd27faec6fc66
5
5
  SHA512:
6
- metadata.gz: 41288ef851b55cbccdc2a8a93c42dd2c31a8fd31db2fe6a7d74b76e34bb427ff98deeb0ba2ca172bef60dc05bf4f6927e396ad80118edad685f182d5d9a779e4
7
- data.tar.gz: 4a306b75abd009189ad08ea18ca673ff5f8b9f65a0ab8cc69dac6bef6ed22a2b0061b2563099e348acf84b75d3d86fcdea9e7c0ceead13bce5d3e090fc4cffcd
6
+ metadata.gz: 58e81f2668303be389ed6923b6df01beb1876f76beacb4954c53eefaf66a51a36fae40ca9752b2939bfacb725112a795f255df09fb341c3536eb6172ad112fa9
7
+ data.tar.gz: c1f82f684619547ff036bbe173193d9485e0ac3045c7bc82de5727664cd6ebcf510aa60b8a1f8002e60ff3351aa6f5c6e0b49a93ae68a3757a0864541d9bb9f6
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ install: "bundle install"
6
+ script: "bundle exec rspec"
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # FilterForm
1
+ # FilterForm [![Build Status](https://travis-ci.org/exAspArk/filter_form.png)](https://travis-ci.org/exAspArk/filter_form)
2
2
 
3
3
  Build filter forms easily by using `ransack` and `simple_form`.
4
4
 
data/filter_form.gemspec CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.3'
26
26
  spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
28
+ spec.add_development_dependency 'sqlite3'
27
29
  end
@@ -1,12 +1,17 @@
1
1
  module FilterForm
2
2
  module InputOptions
3
3
  class Base
4
- include ActiveModel::Model
5
-
6
4
  DEFAULT_PREDICATE = nil
7
5
 
8
6
  attr_accessor :attribute_name, :object, :custom_predicate, :options
9
7
 
8
+ def initialize(options)
9
+ @attribute_name = options[:attribute_name]
10
+ @object = options[:object]
11
+ @custom_predicate = options[:custom_predicate]
12
+ @options = options[:options]
13
+ end
14
+
10
15
  def simple_form_options
11
16
  default_options.merge(additional_options).merge(options)
12
17
  end
@@ -26,7 +31,7 @@ module FilterForm
26
31
  end
27
32
 
28
33
  def additional_input_options
29
- result = { name: input_name, data: {} }
34
+ result = { name: input_name }
30
35
 
31
36
  if input_class
32
37
  if options[:input_html]
@@ -36,8 +41,13 @@ module FilterForm
36
41
  end
37
42
  end
38
43
 
39
- result[:data][:predicate_selector] = options[:predicate_selector] if options[:predicate_selector]
40
- result[:data][:current_predicate] = current_predicate if current_predicate
44
+ if options[:predicate_selector]
45
+ result.merge!(data: { predicate_selector: options[:predicate_selector] })
46
+ end
47
+
48
+ if current_predicate
49
+ result.merge!(data: { current_predicate: current_predicate })
50
+ end
41
51
 
42
52
  result
43
53
  end
@@ -11,7 +11,11 @@ module FilterForm
11
11
  end
12
12
 
13
13
  def additional_input_options
14
- super.merge(value: input_value, step: 'any')
14
+ if input_value
15
+ super.merge(value: input_value, step: 'any')
16
+ else
17
+ super.merge(step: 'any')
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -11,7 +11,11 @@ module FilterForm
11
11
  end
12
12
 
13
13
  def additional_input_options
14
- super.merge(value: input_value)
14
+ if input_value
15
+ super.merge(value: input_value)
16
+ else
17
+ super
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -15,11 +15,17 @@ require 'filter_form/input_options/checkbox/base'
15
15
 
16
16
  module FilterForm
17
17
  class InputOptionsBuilder
18
- include ActiveModel::Model
19
-
20
18
  attr_accessor :attribute_name, :object, :custom_predicate, :custom_type
21
19
 
22
- def build(options)
20
+ def initialize(options)
21
+ @attribute_name = options[:attribute_name]
22
+ @object = options[:object]
23
+ @custom_predicate = options[:custom_predicate]
24
+ @custom_type = options[:custom_type]
25
+ end
26
+
27
+
28
+ def build(options = {})
23
29
  input_options_class.new(attribute_name: attribute_name, object: object, custom_predicate: custom_predicate, options: options).simple_form_options
24
30
  end
25
31
 
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.7.7'
2
+ VERSION = '0.7.9'
3
3
  end
@@ -0,0 +1,12 @@
1
+ activerecord:
2
+ attributes:
3
+ user:
4
+ married: "MARRIED"
5
+ name: "NAME"
6
+ about: "ABOUT"
7
+ amount: "AMOUNT"
8
+ ransack:
9
+ predicates:
10
+ 'true': "IS TRUE"
11
+ cont: "CONTAINS"
12
+ eq: "EQUALS"
@@ -0,0 +1,11 @@
1
+ ActiveRecord::Migration.create_table :users do |t|
2
+ t.boolean :married
3
+ t.string :name
4
+ t.text :about
5
+ t.integer :amount_cents, default: 0
6
+ t.string :amount_currency, default: 'USD'
7
+ t.integer :age
8
+ t.date :birthday
9
+ t.integer :city_id
10
+ t.string :gender
11
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ class User < ActiveRecord::Base
4
+ end
5
+
6
+ describe FilterForm::InputOptionsBuilder do
7
+ let(:search) { User.search }
8
+ let(:builder) { FilterForm::InputOptionsBuilder.new(object: search) }
9
+
10
+ context 'boolean' do
11
+ before do
12
+ builder.attribute_name = :married
13
+ end
14
+
15
+ context 'default predicate' do
16
+ 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)
20
+ end
21
+ end
22
+ end
23
+
24
+ context 'string' do
25
+ before do
26
+ builder.attribute_name = :name
27
+ end
28
+
29
+ context 'default predicate' do
30
+ 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)
34
+ end
35
+ end
36
+ end
37
+
38
+ context 'text' do
39
+ before do
40
+ builder.attribute_name = :about
41
+ end
42
+
43
+ context 'default predicate' do
44
+ it 'returns correct options with predicate "cont"' do
45
+ result = builder.build
46
+ options = { as: :string, required: false, label: 'ABOUT CONTAINS', input_html: { name: 'q[about_cont]' } }
47
+ expect(result).to eq(options)
48
+ end
49
+ end
50
+ end
51
+
52
+ context 'money' do
53
+ before do
54
+ builder.attribute_name = :amount
55
+ end
56
+
57
+ context 'default predicate' do
58
+ it 'returns correct options with predicate "eq"' do
59
+ result = builder.build
60
+ options = { as: :integer, required: false, label: 'AMOUNT EQUALS', input_html: { name: 'q[amount_eq]', step: 'any' } }
61
+ expect(result).to eq(options)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails'
2
+ require 'action_view'
3
+ require 'active_model'
4
+
5
+ require 'support/active_record'
6
+
7
+ require 'filter_form'
8
+
9
+ RSpec.configure do |config|
10
+ config.color = true
11
+ config.tty = true
12
+ config.order = :random
13
+ end
14
+
15
+ I18n.backend.store_translations(:test, YAML::load_file('spec/fixtures/locale.yml'))
16
+ I18n.enforce_available_locales = false
17
+ I18n.default_locale = :test
@@ -0,0 +1,14 @@
1
+ require 'active_record'
2
+
3
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
4
+
5
+ require 'fixtures/migration'
6
+
7
+ RSpec.configure do |config|
8
+ config.around do |example|
9
+ ActiveRecord::Base.transaction do
10
+ example.run
11
+ raise ActiveRecord::Rollback
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,97 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filter_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-17 00:00:00.000000000 Z
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_form
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ransack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jquery-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: select2-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
125
  description: Build filter forms easily
@@ -101,6 +129,7 @@ executables: []
101
129
  extensions: []
102
130
  extra_rdoc_files: []
103
131
  files:
132
+ - ".travis.yml"
104
133
  - Gemfile
105
134
  - LICENSE.txt
106
135
  - README.md
@@ -123,6 +152,11 @@ files:
123
152
  - lib/filter_form/money_converter.rb
124
153
  - lib/filter_form/simple_form/form_builder.rb
125
154
  - lib/filter_form/version.rb
155
+ - spec/fixtures/locale.yml
156
+ - spec/fixtures/migration.rb
157
+ - spec/models/input_options_builder_spec.rb
158
+ - spec/spec_helper.rb
159
+ - spec/support/active_record.rb
126
160
  homepage: https://github.com/exAspArk/filter_form
127
161
  licenses:
128
162
  - MIT
@@ -133,18 +167,24 @@ require_paths:
133
167
  - lib
134
168
  required_ruby_version: !ruby/object:Gem::Requirement
135
169
  requirements:
136
- - - '>='
170
+ - - ">="
137
171
  - !ruby/object:Gem::Version
138
172
  version: '0'
139
173
  required_rubygems_version: !ruby/object:Gem::Requirement
140
174
  requirements:
141
- - - '>='
175
+ - - ">="
142
176
  - !ruby/object:Gem::Version
143
177
  version: '0'
144
178
  requirements: []
145
179
  rubyforge_project:
146
- rubygems_version: 2.0.3
180
+ rubygems_version: 2.2.2
147
181
  signing_key:
148
182
  specification_version: 4
149
183
  summary: Build your filter forms automatically
150
- test_files: []
184
+ test_files:
185
+ - spec/fixtures/locale.yml
186
+ - spec/fixtures/migration.rb
187
+ - spec/models/input_options_builder_spec.rb
188
+ - spec/spec_helper.rb
189
+ - spec/support/active_record.rb
190
+ has_rdoc: