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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4e4e20ddfd99284928ca78469531ddfe129ea93
4
- data.tar.gz: 9007db83c5225dce2fc96805c3b4de78b55eedfd
3
+ metadata.gz: 31ee3732403546691dbd1deef7d620263fae1981
4
+ data.tar.gz: ce0fcb850fdc7b0e3a3440827e322146bee5e63a
5
5
  SHA512:
6
- metadata.gz: dc2ef8e33c46fb75cddd5b07b8b01c698f71b6ca73b3de0c80378d10881691198ffb29ba98d84c3d2d6ea1d8950ebc70bc26f89f206d144afabb20a1dd92fffa
7
- data.tar.gz: a52d9af452e3f706c39eb0ff18853b9e3f7ec4dc4d5f752e85ca54761d58a80d1fc0aba0345665db37f5d83a2a07723346f9075d0cd28a45f6b988e9c50eeb1f
6
+ metadata.gz: 7ce07210f73a7903ee56c31bad4bb46c2120b3132abef6bf8a3b701a85324c2d1fb496b8e89614d59a2b81f9c5c0fa9b7dd2e1c3da09f937bca5a8de956d50c5
7
+ data.tar.gz: c0a4188a0fdeb8fdcfb48a1cbfd11ad77463b72b799312ad238f29b02e5716977082db63cebd478ed78b7e136bfb5f860d7a4056e90125669b11049d7ddc4a7e
@@ -1,3 +1,3 @@
1
1
  module BuiltInData
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
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
- YAML.load(ERB.new(File.read(Rails.root.join('db', 'built_in_data', "#{table_name}.yml"))).result)
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)
@@ -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
@@ -0,0 +1,5 @@
1
+ class AddActiveToNationalParks < ActiveRecord::Migration
2
+ def change
3
+ add_column :national_parks, :active, :boolean
4
+ end
5
+ end
@@ -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: 20141111224715) do
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
Binary file
@@ -10,3 +10,10 @@ Migrating to RemoveProtectedAttributeColumnFromNationalParks (20141111224715)
10
10
  SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20141111224715"]]
11
11
   (1.7ms) commit transaction
12
12
  ActiveRecord::SchemaMigration Load (1.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
13
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
14
+ Migrating to AddActiveToNationalParks (20141113214328)
15
+  (0.1ms) begin transaction
16
+  (0.5ms) ALTER TABLE "national_parks" ADD "active" boolean
17
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20141113214328"]]
18
+  (1.1ms) commit transaction
19
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"