enumerate_by 0.4.1 → 0.4.2
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.rdoc +4 -0
- data/Rakefile +2 -1
- data/lib/enumerate_by.rb +6 -2
- data/test/unit/enumerate_by_test.rb +38 -0
- metadata +15 -15
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -5,9 +5,10 @@ require 'rake/contrib/sshpublisher'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = 'enumerate_by'
|
8
|
-
s.version = '0.4.
|
8
|
+
s.version = '0.4.2'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.summary = 'Adds support for declaring an ActiveRecord class as an enumeration'
|
11
|
+
s.description = s.summary
|
11
12
|
|
12
13
|
s.files = FileList['{lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
|
13
14
|
s.require_path = 'lib'
|
data/lib/enumerate_by.rb
CHANGED
@@ -253,7 +253,10 @@ module EnumerateBy
|
|
253
253
|
uncached do
|
254
254
|
# Remove records that are no longer being used
|
255
255
|
records.flatten!
|
256
|
-
|
256
|
+
ids = records.map {|record| record[:id]}.compact
|
257
|
+
delete_all(ids.any? ? ['id NOT IN (?)', ids] : nil)
|
258
|
+
|
259
|
+
# Find remaining existing records (to be updated)
|
257
260
|
existing = all.inject({}) {|existing, record| existing[record.id] = record; existing}
|
258
261
|
|
259
262
|
records.map! do |attributes|
|
@@ -302,7 +305,8 @@ module EnumerateBy
|
|
302
305
|
def fast_bootstrap(*records)
|
303
306
|
# Remove records that are no longer being used
|
304
307
|
records.flatten!
|
305
|
-
|
308
|
+
ids = records.map {|record| record[:id]}.compact
|
309
|
+
delete_all(ids.any? ? ['id NOT IN (?)', ids] : nil)
|
306
310
|
|
307
311
|
# Find remaining existing records (to be updated)
|
308
312
|
quoted_table_name = self.quoted_table_name
|
@@ -295,6 +295,25 @@ class EnumerationBootstrappedWithExistingRecordsTest < ActiveRecord::TestCase
|
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
|
+
class EnumerationBootstrappedWithExistingDynamicRecordsTest < ActiveRecord::TestCase
|
299
|
+
def setup
|
300
|
+
create_color(:name => 'RED')
|
301
|
+
create_color(:name => 'GREEN')
|
302
|
+
|
303
|
+
@red, @green = Color.bootstrap(
|
304
|
+
{:name => 'red'},
|
305
|
+
{:name => 'green'}
|
306
|
+
)
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_should_synchronize_all_attributes
|
310
|
+
assert_equal 2, Color.count
|
311
|
+
|
312
|
+
assert_equal 'red', @red.name
|
313
|
+
assert_equal 'green', @green.name
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
298
317
|
class EnumerationBootstrappedWithDefaultsTest < ActiveRecord::TestCase
|
299
318
|
def setup
|
300
319
|
@red = create_color(:name => 'RED', :html => '#f00')
|
@@ -375,6 +394,25 @@ class EnumeratioFastBootstrappedWithExistingRecordsTest < ActiveRecord::TestCase
|
|
375
394
|
end
|
376
395
|
end
|
377
396
|
|
397
|
+
class EnumerationFastBootstrappedWithExistingDynamicRecordsTest < ActiveRecord::TestCase
|
398
|
+
def setup
|
399
|
+
create_color(:name => 'RED')
|
400
|
+
create_color(:name => 'GREEN')
|
401
|
+
|
402
|
+
Color.fast_bootstrap(
|
403
|
+
{:name => 'red'},
|
404
|
+
{:name => 'green'}
|
405
|
+
)
|
406
|
+
end
|
407
|
+
|
408
|
+
def test_should_synchronize_all_attributes
|
409
|
+
assert_equal 2, Color.count
|
410
|
+
|
411
|
+
assert Color.exists?(:name => 'red')
|
412
|
+
assert Color.exists?(:name => 'green')
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
378
416
|
class EnumerationFastBootstrappedWithDefaultsTest < ActiveRecord::TestCase
|
379
417
|
def setup
|
380
418
|
@red = create_color(:name => 'RED', :html => '#f00')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerate_by
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-03 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: Adds support for declaring an ActiveRecord class as an enumeration
|
17
17
|
email: aaron@pluginaweek.org
|
18
18
|
executables: []
|
19
19
|
|
@@ -25,28 +25,28 @@ files:
|
|
25
25
|
- lib/enumerate_by.rb
|
26
26
|
- lib/enumerate_by
|
27
27
|
- lib/enumerate_by/extensions
|
28
|
-
- lib/enumerate_by/extensions/associations.rb
|
29
|
-
- lib/enumerate_by/extensions/xml_serializer.rb
|
30
28
|
- lib/enumerate_by/extensions/base_conditions.rb
|
29
|
+
- lib/enumerate_by/extensions/associations.rb
|
31
30
|
- lib/enumerate_by/extensions/serializer.rb
|
32
|
-
-
|
33
|
-
- test/test_helper.rb
|
31
|
+
- lib/enumerate_by/extensions/xml_serializer.rb
|
34
32
|
- test/unit
|
33
|
+
- test/unit/xml_serializer_test.rb
|
35
34
|
- test/unit/enumerate_by_test.rb
|
35
|
+
- test/unit/serializer_test.rb
|
36
36
|
- test/unit/assocations_test.rb
|
37
37
|
- test/unit/json_serializer_test.rb
|
38
|
-
- test/unit/serializer_test.rb
|
39
|
-
- test/unit/xml_serializer_test.rb
|
40
38
|
- test/unit/base_conditions_test.rb
|
39
|
+
- test/factory.rb
|
41
40
|
- test/app_root
|
41
|
+
- test/app_root/app
|
42
|
+
- test/app_root/app/models
|
43
|
+
- test/app_root/app/models/color.rb
|
44
|
+
- test/app_root/app/models/car.rb
|
42
45
|
- test/app_root/db
|
43
46
|
- test/app_root/db/migrate
|
44
47
|
- test/app_root/db/migrate/001_create_colors.rb
|
45
48
|
- test/app_root/db/migrate/002_create_cars.rb
|
46
|
-
- test/
|
47
|
-
- test/app_root/app/models
|
48
|
-
- test/app_root/app/models/car.rb
|
49
|
-
- test/app_root/app/models/color.rb
|
49
|
+
- test/test_helper.rb
|
50
50
|
- CHANGELOG.rdoc
|
51
51
|
- init.rb
|
52
52
|
- LICENSE
|
@@ -79,9 +79,9 @@ signing_key:
|
|
79
79
|
specification_version: 2
|
80
80
|
summary: Adds support for declaring an ActiveRecord class as an enumeration
|
81
81
|
test_files:
|
82
|
+
- test/unit/xml_serializer_test.rb
|
82
83
|
- test/unit/enumerate_by_test.rb
|
84
|
+
- test/unit/serializer_test.rb
|
83
85
|
- test/unit/assocations_test.rb
|
84
86
|
- test/unit/json_serializer_test.rb
|
85
|
-
- test/unit/serializer_test.rb
|
86
|
-
- test/unit/xml_serializer_test.rb
|
87
87
|
- test/unit/base_conditions_test.rb
|