built_in_data 1.1.0 → 1.1.4

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
- SHA1:
3
- metadata.gz: b28022b96a300e723ae2377d8322e285298f2b79
4
- data.tar.gz: 6d006c9c8cb191997c23f7395e95c0b3a3cf7918
2
+ SHA256:
3
+ metadata.gz: 9394bd2479dccf207f906c6ca48653287a621c5d6522306b770e556fce552d56
4
+ data.tar.gz: 9e1d7d9e4ef5706036452492f31bdd1061b79d8fc048c8cd891a1c68bb9f1793
5
5
  SHA512:
6
- metadata.gz: 5537320180706f97934bad8e6a16bca311bfe7d5e8e092a3d4e08228639af911a8778dfcce949698fcc56adb51c99c48466135e66f16820bbe433ca62d7d2ec4
7
- data.tar.gz: d2fbcb5b365937c789614121107acc97f2684fe7e9aa56aeb1739a051690bdb30a385fd62302e48310f0db70c85f7bdb26053feacb5ba8cce327eecc0ac4377f
6
+ metadata.gz: 638ce6c855a13e1254ff71a0e3fe5888d7c4c8996d70277e58ea2636f470dabde48922bca6aa60c6459487d0604329a4f8d9d49c266732c2dcd192281f49e874
7
+ data.tar.gz: 6d737a730d0b4a63b7393babcb4de49fdff07e0b1a556bd07d436769c97d3d8c6bf05ee9befea440798a580ad19a2f291f32f9c05529cae747b6e65ed972006a
data/Rakefile CHANGED
@@ -1,32 +1,10 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'BuiltInData'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
-
18
-
19
-
20
- Bundler::GemHelper.install_tasks
21
-
22
- require 'rake/testtask'
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
23
3
 
24
4
  Rake::TestTask.new(:test) do |t|
25
- t.libs << 'lib'
26
- t.libs << 'test'
27
- t.pattern = 'test/**/*_test.rb'
28
- t.verbose = false
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
29
8
  end
30
9
 
31
-
32
10
  task default: :test
@@ -1,3 +1,3 @@
1
1
  module BuiltInData
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.4"
3
3
  end
data/lib/built_in_data.rb CHANGED
@@ -3,7 +3,7 @@ module BuiltInData
3
3
 
4
4
  included do
5
5
  # all built in data objects should have a built_in_key, model objects without a key will not be modified or removed
6
- validates_uniqueness_of :built_in_key, :allow_nil => true
6
+ validates_uniqueness_of :built_in_key, allow_nil: true, case_sensitive: false
7
7
 
8
8
  scope :built_in, -> { where "#{table_name}.built_in_key IS NOT NULL" }
9
9
  end
@@ -29,6 +29,11 @@ module BuiltInData
29
29
  built_in_object_ids[key]
30
30
  end
31
31
 
32
+ def delete_all
33
+ @built_in_object_ids = nil
34
+ super
35
+ end
36
+
32
37
  private
33
38
 
34
39
  def prepare_objects_hash(hash)
@@ -36,10 +41,14 @@ module BuiltInData
36
41
  end
37
42
 
38
43
  def load_yaml_data
39
- # allow a standard key to be used for doing defaults in YAML
40
- YAML.load(read_and_erb_process_yaml_file).except('DEFAULTS')
44
+ # allow a standard key to be used for defaults in YAML files
45
+ YAML.safe_load(
46
+ read_and_erb_process_yaml_file,
47
+ permitted_classes: [Date],
48
+ aliases: true
49
+ ).except('DEFAULTS')
41
50
  end
42
-
51
+
43
52
  def read_and_erb_process_yaml_file
44
53
  ERB.new(File.read(Rails.root.join('db', 'built_in_data', "#{table_name}.yml"))).result
45
54
  end
@@ -50,7 +59,7 @@ module BuiltInData
50
59
  object.save!
51
60
  end
52
61
  end
53
-
62
+
54
63
  # memoized hash of built in object ids
55
64
  def built_in_object_ids
56
65
  @built_in_object_ids ||= Hash.new do |hash, key|
@@ -58,7 +67,7 @@ module BuiltInData
58
67
  end
59
68
  end
60
69
  end
61
-
70
+
62
71
  def built_in?
63
72
  !built_in_key.blank?
64
73
  end
@@ -87,6 +87,13 @@ class BuiltInDataTest < ActiveSupport::TestCase
87
87
  load_hash_data
88
88
  assert_equal NationalPark.where(name: 'Yellowstone National Park').first.id, NationalPark.built_in_object_id(:test)
89
89
  end
90
+
91
+ test 'should clear built_in_object_ids cache when delete_all is called' do
92
+ NationalPark.instance_variable_set('@built_in_object_ids', 'testing')
93
+
94
+ NationalPark.delete_all
95
+ assert_nil NationalPark.instance_variable_get('@built_in_object_ids')
96
+ end
90
97
 
91
98
  private
92
99
 
@@ -0,0 +1,4 @@
1
+
2
+ //= link_tree ../images
3
+ //= link_directory ../javascripts .js
4
+ //= link_directory ../stylesheets .css
@@ -20,4 +20,3 @@ module Dummy
20
20
  # config.i18n.default_locale = :de
21
21
  end
22
22
  end
23
-
Binary file