selections 0.1.11 → 0.1.12
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/CHANGELOG.md +4 -0
- data/README.md +22 -0
- data/lib/selections/selectable.rb +24 -0
- data/lib/selections/version.rb +1 -1
- data/spec/selections/selectable_spec.rb +6 -0
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -202,6 +202,28 @@ tell selections so by adding the following to a new file, `config/initializers/s
|
|
202
202
|
Selections.model { YourSelectionModel }
|
203
203
|
```
|
204
204
|
|
205
|
+
## Fast Factories
|
206
|
+
### label_to_id
|
207
|
+
|
208
|
+
When using fixtures with the label same as the system_code, use this method to return the ID of the of the fixture and use this in Factories instead of using a lookup as it does not need a DB search.
|
209
|
+
|
210
|
+
eg:
|
211
|
+
Fixture File
|
212
|
+
----------------------------------------
|
213
|
+
priority_high:
|
214
|
+
name: Priorities
|
215
|
+
system_code: priority_high
|
216
|
+
parent: priority
|
217
|
+
----------------------------------------
|
218
|
+
|
219
|
+
#### in Factory
|
220
|
+
---------------------------------------
|
221
|
+
priority: { Selection.priority_high } <== Don't do this as it will need a DB lookup
|
222
|
+
|
223
|
+
priority_id: { Selection.label_to_id(:priority_high) } <== This will be much quicker
|
224
|
+
|
225
|
+
|
226
|
+
|
205
227
|
# TODO
|
206
228
|
|
207
229
|
* Add model generators
|
@@ -52,8 +52,32 @@ module Selections
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
# label_to_id
|
56
|
+
#
|
57
|
+
# When using fixtures with the label same as the system_code, use this method to return the ID of the of the fixture
|
58
|
+
# and use this in Factories instead of using a lookup as it does not need a DB search.
|
59
|
+
#
|
60
|
+
# eg:
|
61
|
+
# Fixture File
|
62
|
+
#----------------------------------------
|
63
|
+
# priority_high:
|
64
|
+
# name: Priorities
|
65
|
+
# system_code: priority_high
|
66
|
+
# parent: priority
|
67
|
+
#----------------------------------------
|
68
|
+
#
|
69
|
+
# in Factory
|
70
|
+
# ---------------------------------------
|
71
|
+
# priority: { Selection.priority_high } <== Don't do this as it will need a DB lookup
|
72
|
+
#
|
73
|
+
# priority_id: { Selection.label_to_id(:priority_high) } <== This will be much quicker
|
74
|
+
#
|
75
|
+
def label_to_id(label)
|
76
|
+
ActiveRecord::Fixtures.identify(label)
|
77
|
+
end
|
55
78
|
end
|
56
79
|
|
80
|
+
|
57
81
|
def to_s #:nodoc:
|
58
82
|
name.to_s
|
59
83
|
end
|
data/lib/selections/version.rb
CHANGED
@@ -40,6 +40,12 @@ describe Selections do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
describe '#fixture_id' do
|
44
|
+
context 'returns ID without DB access' do
|
45
|
+
it { expect(Selection.label_to_id('priority_high')).to eq ActiveRecord::Fixtures.identify(:priority_high) }
|
46
|
+
it { expect(Selection.label_to_id(:priority_high)).to eq ActiveRecord::Fixtures.identify(:priority_high) }
|
47
|
+
end
|
48
|
+
end
|
43
49
|
|
44
50
|
describe ".leaf?" do
|
45
51
|
it { selection_1; expect(parent.leaf?).to be_false }
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
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: 2013-04-
|
12
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|