built_in_data 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/built_in_data/version.rb +1 -1
- data/lib/built_in_data.rb +6 -1
- data/test/built_in_data_test.rb +5 -0
- data/test/dummy/db/built_in_data/national_parks.yml +5 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20141113214328_add_active_to_national_parks.rb +5 -0
- data/test/dummy/db/schema.rb +2 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +7 -0
- data/test/dummy/log/test.log +1779 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31ee3732403546691dbd1deef7d620263fae1981
|
4
|
+
data.tar.gz: ce0fcb850fdc7b0e3a3440827e322146bee5e63a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ce07210f73a7903ee56c31bad4bb46c2120b3132abef6bf8a3b701a85324c2d1fb496b8e89614d59a2b81f9c5c0fa9b7dd2e1c3da09f937bca5a8de956d50c5
|
7
|
+
data.tar.gz: c0a4188a0fdeb8fdcfb48a1cbfd11ad77463b72b799312ad238f29b02e5716977082db63cebd478ed78b7e136bfb5f860d7a4056e90125669b11049d7ddc4a7e
|
data/lib/built_in_data.rb
CHANGED
@@ -31,7 +31,12 @@ module BuiltInData
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def load_yaml_data
|
34
|
-
|
34
|
+
# allow a standard key to be used for doing defaults in YAML
|
35
|
+
YAML.load(read_and_erb_process_yaml_file).except('DEFAULTS')
|
36
|
+
end
|
37
|
+
|
38
|
+
def read_and_erb_process_yaml_file
|
39
|
+
ERB.new(File.read(Rails.root.join('db', 'built_in_data', "#{table_name}.yml"))).result
|
35
40
|
end
|
36
41
|
|
37
42
|
def create_or_update!(key, attributes)
|
data/test/built_in_data_test.rb
CHANGED
@@ -77,6 +77,11 @@ class BuiltInDataTest < ActiveSupport::TestCase
|
|
77
77
|
assert_equal(NationalPark,parks.first.class)
|
78
78
|
assert_equal(false,parks.first.new_record?)
|
79
79
|
end
|
80
|
+
|
81
|
+
test 'should load yaml defaults' do
|
82
|
+
NationalPark.load_built_in_data!
|
83
|
+
assert_equal true, NationalPark.find_by(name: 'Yellowstone National Park').active
|
84
|
+
end
|
80
85
|
|
81
86
|
private
|
82
87
|
|
@@ -1,8 +1,13 @@
|
|
1
|
+
DEFAULTS: &default_values
|
2
|
+
active: true
|
3
|
+
|
1
4
|
yellowstone:
|
5
|
+
<<: *default_values
|
2
6
|
name: Yellowstone National Park
|
3
7
|
established: 1872-03-01
|
4
8
|
url: 'http://www.nps.gov/yell/index.htm'
|
5
9
|
glacier:
|
10
|
+
<<: *default_values
|
6
11
|
name: Glacier National Park
|
7
12
|
established: <%= Date.parse('1910-05-11') %>
|
8
13
|
url: 'http://www.nps.gov/glac/index.htm'
|
Binary file
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20141113214328) do
|
15
15
|
|
16
16
|
create_table "national_parks", force: true do |t|
|
17
17
|
t.string "name"
|
@@ -20,6 +20,7 @@ ActiveRecord::Schema.define(version: 20141111224715) do
|
|
20
20
|
t.datetime "created_at", null: false
|
21
21
|
t.datetime "updated_at", null: false
|
22
22
|
t.string "built_in_key"
|
23
|
+
t.boolean "active"
|
23
24
|
end
|
24
25
|
|
25
26
|
end
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -10,3 +10,10 @@ Migrating to RemoveProtectedAttributeColumnFromNationalParks (20141111224715)
|
|
10
10
|
[1m[36mSQL (0.3ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES (?)[0m [["version", "20141111224715"]]
|
11
11
|
[1m[35m (1.7ms)[0m commit transaction
|
12
12
|
[1m[36mActiveRecord::SchemaMigration Load (1.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
13
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
14
|
+
Migrating to AddActiveToNationalParks (20141113214328)
|
15
|
+
[1m[35m (0.1ms)[0m begin transaction
|
16
|
+
[1m[36m (0.5ms)[0m [1mALTER TABLE "national_parks" ADD "active" boolean[0m
|
17
|
+
[1m[35mSQL (0.2ms)[0m INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20141113214328"]]
|
18
|
+
[1m[36m (1.1ms)[0m [1mcommit transaction[0m
|
19
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|