has_settings 0.0.3 → 0.0.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/has_settings.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_settings}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Morten Primdahl"]
@@ -9,7 +9,7 @@ module HasSettings
9
9
 
10
10
  def build(*setting_names)
11
11
  setting_names.each do |setting_name|
12
- self << settings_class.new(:name => setting_name)
12
+ self << proxy_reflection.klass.new(:name => setting_name)
13
13
  end
14
14
  end
15
15
 
@@ -51,7 +51,7 @@ module HasSettings
51
51
  @owner_class_sym = owner_class.name.underscore.to_sym
52
52
  belongs_to owner_class_sym
53
53
  validates_presence_of owner_class_sym
54
- validates_uniqueness_of :type, :scope => owner_class_key_sym
54
+ validates_uniqueness_of :name, :scope => owner_class_key_sym
55
55
 
56
56
  if owner_class.table_exists? && owner_class.column_names.include?('updated_at')
57
57
  before_create :update_owner_timestamp
@@ -69,5 +69,20 @@ class TestHasSettings < ActiveSupport::TestCase
69
69
  assert !a.settings.archive?
70
70
  assert a.settings.ssl?
71
71
  end
72
+
73
+ should "be able to build multiple settings in one go" do
74
+ a = Account.create(:name => 'name')
75
+ assert a.settings.empty?
76
+ a.settings.build('archive', 'ssl')
77
+ assert a.settings.size == 2
78
+ end
79
+
80
+ should "validate uniqueness of settings" do
81
+ a = Account.create(:name => 'name')
82
+ AccountSetting.create!(:account => a, :name => 'fish')
83
+ assert_raise ActiveRecord::RecordInvalid do
84
+ AccountSetting.create!(:account => a, :name => 'fish')
85
+ end
86
+ end
72
87
  end
73
88
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_settings
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Morten Primdahl