acts_as_select 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +7 -0
- data/acts_as_select.gemspec +5 -2
- data/lib/active_record/acts/select.rb +3 -3
- data/test/select_test.rb +39 -24
- metadata +7 -7
data/README.md
CHANGED
@@ -51,6 +51,13 @@ This specifies which columns are excluded from having the _select and _list meth
|
|
51
51
|
When both options are supplied, the exclusion happens after the inclusion. That is, if there are overlapping column
|
52
52
|
names in both lists, these columns are excluded, regardless of the order of the options.
|
53
53
|
|
54
|
+
If you only want a single column type to be included (or excluded), these can be passed as a symbol or string
|
55
|
+
|
56
|
+
:include => :column_1
|
57
|
+
or
|
58
|
+
|
59
|
+
:include => 'column_1'
|
60
|
+
|
54
61
|
### Example
|
55
62
|
|
56
63
|
With this database table
|
data/acts_as_select.gemspec
CHANGED
@@ -22,11 +22,14 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
23
|
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'sqlite3'
|
25
|
-
if RUBY_VERSION >= '
|
25
|
+
if RUBY_VERSION >= '2.2.2'
|
26
26
|
spec.add_development_dependency 'minitest'
|
27
27
|
spec.add_development_dependency 'activerecord'
|
28
|
+
elsif RUBY_VERSION >= '1.9'
|
29
|
+
spec.add_development_dependency 'minitest'
|
30
|
+
spec.add_development_dependency 'activerecord', '~> 3.0'
|
28
31
|
else
|
29
32
|
spec.add_development_dependency 'test-unit'
|
30
|
-
spec.add_development_dependency 'activerecord'
|
33
|
+
spec.add_development_dependency 'activerecord', '~> 2.3'
|
31
34
|
end
|
32
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module Acts
|
3
3
|
module Select
|
4
|
-
VERSION="0.1.
|
4
|
+
VERSION="0.1.7"
|
5
5
|
class << self
|
6
6
|
def included(base)
|
7
7
|
base.instance_eval do
|
@@ -26,8 +26,8 @@ module ActiveRecord
|
|
26
26
|
|
27
27
|
def allowed_columns(*opts)
|
28
28
|
opts=!opts.empty? && opts.first.is_a?(Hash) ? default_opts.merge(opts.first) : default_opts
|
29
|
-
opts[:include]=[opts[:include]]
|
30
|
-
opts[:exclude]=[opts[:exclude]]
|
29
|
+
opts[:include]=[opts[:include]].flatten.map(&:to_s)
|
30
|
+
opts[:exclude]=[opts[:exclude]].flatten.map(&:to_s)
|
31
31
|
column_names & (opts[:include]-opts[:exclude])
|
32
32
|
end
|
33
33
|
|
data/test/select_test.rb
CHANGED
@@ -36,7 +36,9 @@ class Selection < ActiveRecord::Base
|
|
36
36
|
end
|
37
37
|
class SelectAll < Selection
|
38
38
|
end
|
39
|
-
class
|
39
|
+
class SelectIncludeSingleString < Selection
|
40
|
+
end
|
41
|
+
class SelectIncludeSingleSymbol < Selection
|
40
42
|
end
|
41
43
|
class SelectIncludeMulti < Selection
|
42
44
|
end
|
@@ -52,7 +54,7 @@ end
|
|
52
54
|
class SelectTest < (begin MiniTest::Test rescue Test::Unit::TestCase end)
|
53
55
|
def setup
|
54
56
|
setup_db
|
55
|
-
[SelectAll,
|
57
|
+
[SelectAll, SelectIncludeSingleString, SelectIncludeSingleSymbol, SelectIncludeMulti, SelectExcludeSingle, SelectExcludeMulti, SelectedIncludeExclude, SelectCollectionSingle].each do |klass|
|
56
58
|
klass.create! :name => 'first', :description => 'First field', :excluded_string => 'not allowed'
|
57
59
|
klass.create! :name => 'second', :description => 'Second field', :excluded_string => 'not allowed'
|
58
60
|
klass.create! :name => 'third', :description => 'Third field', :excluded_string => 'not allowed'
|
@@ -139,25 +141,38 @@ class SelectTest < (begin MiniTest::Test rescue Test::Unit::TestCase end)
|
|
139
141
|
assert_raises(NoMethodError) { Selection.wibble_select }
|
140
142
|
end
|
141
143
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
assert_raises(NoMethodError) {
|
146
|
-
|
147
|
-
assert_equal(selection_names.map
|
148
|
-
|
149
|
-
assert_raises(NoMethodError) {
|
150
|
-
assert_raises(NoMethodError) {
|
151
|
-
assert_raises(NoMethodError) {
|
144
|
+
#TODO: Get round to changing the +6 multiple to allow me to add things into the middle without having to change the following tests.
|
145
|
+
def test_single_field_selection_with_string
|
146
|
+
SelectIncludeSingleString.acts_as_select :include => 'name'
|
147
|
+
assert_raises(NoMethodError) { SelectIncludeSingleString.id_select }
|
148
|
+
assert_raises(NoMethodError) { SelectIncludeSingleString.id_list }
|
149
|
+
assert_equal(selection_names.map { |x| [x[0], x[1]+6] }, SelectIncludeSingleString.name_select)
|
150
|
+
assert_equal(selection_names.map(&:first), SelectIncludeSingleString.name_list)
|
151
|
+
assert_raises(NoMethodError) { SelectIncludeSingleString.description_select }
|
152
|
+
assert_raises(NoMethodError) { SelectIncludeSingleString.description_list }
|
153
|
+
assert_raises(NoMethodError) { SelectIncludeSingleString.excluded_string_select }
|
154
|
+
assert_raises(NoMethodError) { SelectIncludeSingleString.excluded_string_list }
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_single_field_selection_with_symbol
|
158
|
+
SelectIncludeSingleSymbol.acts_as_select :include => :name
|
159
|
+
assert_raises(NoMethodError) { SelectIncludeSingleSymbol.id_select }
|
160
|
+
assert_raises(NoMethodError) { SelectIncludeSingleSymbol.id_list }
|
161
|
+
assert_equal(selection_names.map { |x| [x[0], x[1]+12] }, SelectIncludeSingleSymbol.name_select)
|
162
|
+
assert_equal(selection_names.map(&:first), SelectIncludeSingleSymbol.name_list)
|
163
|
+
assert_raises(NoMethodError) { SelectIncludeSingleSymbol.description_select }
|
164
|
+
assert_raises(NoMethodError) { SelectIncludeSingleSymbol.description_list }
|
165
|
+
assert_raises(NoMethodError) { SelectIncludeSingleSymbol.excluded_string_select }
|
166
|
+
assert_raises(NoMethodError) { SelectIncludeSingleSymbol.excluded_string_list }
|
152
167
|
end
|
153
168
|
|
154
169
|
def test_multi_field_selection
|
155
170
|
SelectIncludeMulti.acts_as_select :include => %w(name description)
|
156
171
|
assert_raises(NoMethodError) { SelectIncludeMulti.id_select }
|
157
172
|
assert_raises(NoMethodError) { SelectIncludeMulti.id_list }
|
158
|
-
assert_equal(selection_names.map { |x| [x[0], x[1]+
|
173
|
+
assert_equal(selection_names.map { |x| [x[0], x[1]+18] },SelectIncludeMulti.name_select)
|
159
174
|
assert_equal(selection_names.map(&:first), SelectIncludeMulti.name_list)
|
160
|
-
assert_equal(selection_descriptions.map { |x| [x[0], x[1]+
|
175
|
+
assert_equal(selection_descriptions.map { |x| [x[0], x[1]+18] },SelectIncludeMulti.description_select)
|
161
176
|
assert_equal(selection_descriptions.map(&:first),SelectIncludeMulti.description_list)
|
162
177
|
assert_raises(NoMethodError) { SelectIncludeMulti.excluded_string_select }
|
163
178
|
assert_raises(NoMethodError) { SelectIncludeMulti.excluded_string_list }
|
@@ -165,11 +180,11 @@ class SelectTest < (begin MiniTest::Test rescue Test::Unit::TestCase end)
|
|
165
180
|
|
166
181
|
def test_single_field_exclusion
|
167
182
|
SelectExcludeSingle.acts_as_select :exclude => 'excluded_string'
|
168
|
-
assert_equal(selection_ids.map { |x| [x[0]+
|
169
|
-
assert_equal(selection_ids.map { |x| x[0]+
|
170
|
-
assert_equal(selection_names.map { |x| [x[0], x[1]+
|
183
|
+
assert_equal(selection_ids.map { |x| [x[0]+24, x[1]+24] },SelectExcludeSingle.id_select)
|
184
|
+
assert_equal(selection_ids.map { |x| x[0]+24 },SelectExcludeSingle.id_list)
|
185
|
+
assert_equal(selection_names.map { |x| [x[0], x[1]+24] },SelectExcludeSingle.name_select)
|
171
186
|
assert_equal(selection_names.map(&:first),SelectExcludeSingle.name_list)
|
172
|
-
assert_equal(selection_descriptions.map { |x| [x[0], x[1]+
|
187
|
+
assert_equal(selection_descriptions.map { |x| [x[0], x[1]+24] },SelectExcludeSingle.description_select)
|
173
188
|
assert_equal(selection_descriptions.map(&:first),SelectExcludeSingle.description_list)
|
174
189
|
assert_raises(NoMethodError) { SelectExcludeSingle.excluded_string_select }
|
175
190
|
assert_raises(NoMethodError) { SelectExcludeSingle.excluded_string_list }
|
@@ -177,9 +192,9 @@ class SelectTest < (begin MiniTest::Test rescue Test::Unit::TestCase end)
|
|
177
192
|
|
178
193
|
def test_multi_field_exclusion
|
179
194
|
SelectExcludeMulti.acts_as_select :exclude => %w(description excluded_string)
|
180
|
-
assert_equal(selection_ids.map { |x| [x[0]+
|
181
|
-
assert_equal(selection_ids.map { |x| x[0]+
|
182
|
-
assert_equal(selection_names.map { |x| [x[0], x[1]+
|
195
|
+
assert_equal(selection_ids.map { |x| [x[0]+30, x[1]+30] },SelectExcludeMulti.id_select)
|
196
|
+
assert_equal(selection_ids.map { |x| x[0]+30 },SelectExcludeMulti.id_list)
|
197
|
+
assert_equal(selection_names.map { |x| [x[0], x[1]+30] },SelectExcludeMulti.name_select)
|
183
198
|
assert_equal(selection_names.map(&:first),SelectExcludeMulti.name_list)
|
184
199
|
assert_raises(NoMethodError) { SelectExcludeMulti.description_select }
|
185
200
|
assert_raises(NoMethodError) { SelectExcludeMulti.description_list }
|
@@ -191,7 +206,7 @@ class SelectTest < (begin MiniTest::Test rescue Test::Unit::TestCase end)
|
|
191
206
|
SelectedIncludeExclude.acts_as_select :include => %w(name description), :exclude => %w(description excluded_string)
|
192
207
|
assert_raises(NoMethodError) { SelectedIncludeExclude.id_select }
|
193
208
|
assert_raises(NoMethodError) { SelectedIncludeExclude.id_list }
|
194
|
-
assert_equal(selection_names.map { |x| [x[0], x[1]+
|
209
|
+
assert_equal(selection_names.map { |x| [x[0], x[1]+36] },SelectedIncludeExclude.name_select)
|
195
210
|
assert_equal(selection_names.map(&:first),SelectedIncludeExclude.name_list)
|
196
211
|
assert_raises(NoMethodError) { SelectedIncludeExclude.description_select }
|
197
212
|
assert_raises(NoMethodError) { SelectedIncludeExclude.description_list }
|
@@ -200,8 +215,8 @@ class SelectTest < (begin MiniTest::Test rescue Test::Unit::TestCase end)
|
|
200
215
|
end
|
201
216
|
|
202
217
|
def test_sorted_fields
|
203
|
-
|
204
|
-
assert_equal(selection_names_sorted.map { |x| [x[0], x[1]+6] },
|
218
|
+
SelectIncludeSingleString.acts_as_select :include => 'name'
|
219
|
+
assert_equal(selection_names_sorted.map { |x| [x[0], x[1]+6] }, SelectIncludeSingleString.order('name asc').name_select)
|
205
220
|
end
|
206
221
|
|
207
222
|
def test_sorted_field_collections
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -80,17 +80,17 @@ dependencies:
|
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
|
-
- -
|
83
|
+
- - ~>
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
85
|
+
version: '3.0'
|
86
86
|
type: :development
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
93
|
+
version: '3.0'
|
94
94
|
description: Creation of automatic selection suitable for drop downs from column fields
|
95
95
|
in an ActiveRecord table
|
96
96
|
email:
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
132
|
rubyforge_project:
|
133
|
-
rubygems_version: 1.8.
|
133
|
+
rubygems_version: 1.8.30
|
134
134
|
signing_key:
|
135
135
|
specification_version: 3
|
136
136
|
summary: Automated selection for Activerecord Tables
|