property_sets 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -14,3 +14,8 @@ group :development do
14
14
  gem "jeweler", "~> 1.5.1"
15
15
  gem "ruby-debug"
16
16
  end
17
+
18
+ group :test do
19
+ gem "sqlite3"
20
+ gem "mocha"
21
+ end
@@ -14,6 +14,7 @@ GEM
14
14
  git (>= 1.2.5)
15
15
  rake
16
16
  linecache (0.43)
17
+ mocha (0.9.12)
17
18
  rack (1.1.0)
18
19
  rake (0.8.7)
19
20
  ruby-debug (0.10.4)
@@ -22,6 +23,7 @@ GEM
22
23
  ruby-debug-base (0.10.4)
23
24
  linecache (>= 0.3)
24
25
  shoulda (2.11.3)
26
+ sqlite3 (1.3.3)
25
27
 
26
28
  PLATFORMS
27
29
  ruby
@@ -32,5 +34,7 @@ DEPENDENCIES
32
34
  activesupport (= 2.3.10)
33
35
  bundler (~> 1.0.0)
34
36
  jeweler (~> 1.5.1)
37
+ mocha
35
38
  ruby-debug
36
39
  shoulda
40
+ sqlite3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -0,0 +1 @@
1
+ property_sets_test.sqlite
@@ -33,7 +33,7 @@ module PropertySets
33
33
 
34
34
  # Reports the coerced truth value of the property
35
35
  define_method "#{key}?" do
36
- lookup(key).true?
36
+ lookup_or_default(key).true?
37
37
  end
38
38
 
39
39
  # Returns the value of the property
@@ -70,6 +70,15 @@ module PropertySets
70
70
  instance = detect { |property| property.name.to_sym == arg.to_sym }
71
71
  instance ||= @owner.send(association).build(:name => arg.to_s, :value => property_class.default(arg))
72
72
  end
73
+
74
+ # This finder method returns the property if present,
75
+ # otherwise a new instance with the default value.
76
+ # It does not have the side effect of adding a new setting object.
77
+ define_method 'lookup_or_default' do |arg|
78
+ instance = detect { |property| property.name.to_sym == arg.to_sym }
79
+ instance ||= property_class.new(:value => property_class.default(arg))
80
+ end
81
+
73
82
  end
74
83
  end
75
84
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{property_sets}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
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"]
12
- s.date = %q{2011-03-17}
12
+ s.date = %q{2011-03-28}
13
13
  s.description = %q{This gem is an ActiveRecord extension which provides a convenient interface for managing per row properties}
14
14
  s.email = %q{morten@zendesk.com}
15
15
  s.extra_rdoc_files = [
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "VERSION",
27
+ "db/.gitignore",
27
28
  "lib/property_sets.rb",
28
29
  "lib/property_sets/action_view_extension.rb",
29
30
  "lib/property_sets/active_record_extension.rb",
@@ -40,7 +41,7 @@ Gem::Specification.new do |s|
40
41
  ]
41
42
  s.homepage = %q{http://github.com/morten/property_sets}
42
43
  s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.7}
44
+ s.rubygems_version = %q{1.6.2}
44
45
  s.summary = %q{Property sets for ActiveRecord}
45
46
  s.test_files = [
46
47
  "test/helper.rb",
@@ -50,7 +51,6 @@ Gem::Specification.new do |s|
50
51
  ]
51
52
 
52
53
  if s.respond_to? :specification_version then
53
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
54
  s.specification_version = 3
55
55
 
56
56
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -1,7 +1,6 @@
1
1
  test:
2
- adapter: mysql
2
+ adapter: sqlite3
3
3
  encoding: utf8
4
- database: property_sets_test
4
+ database: db/property_sets_test.sqlite
5
5
  username: root
6
6
  password:
7
- socket: /tmp/mysql.sock
@@ -53,6 +53,21 @@ class TestPropertySets < ActiveSupport::TestCase
53
53
  assert_equal 'skep', @account.settings.hep
54
54
  end
55
55
 
56
+ context 'querying for a setting that does not exist' do
57
+ setup do
58
+ assert_equal([], @account.settings)
59
+ assert_equal(true, @account.settings.hep?)
60
+ end
61
+
62
+ should 'not add a new setting' do
63
+ assert_equal([], @account.settings)
64
+ end
65
+
66
+ should 'give back the default value' do
67
+ assert_equal('skep', @account.settings.hep)
68
+ end
69
+ end
70
+
56
71
  should "reject settings with an invalid name" do
57
72
  s = AccountSetting.new(:account => @account)
58
73
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: property_sets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease: false
4
+ hash: 11
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Morten Primdahl
@@ -15,14 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-17 00:00:00 -07:00
18
+ date: 2011-03-28 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
22
  type: :runtime
24
- name: activesupport
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
26
24
  none: false
27
25
  requirements:
28
26
  - - "="
@@ -33,12 +31,12 @@ dependencies:
33
31
  - 3
34
32
  - 10
35
33
  version: 2.3.10
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ version_requirements: *id001
38
36
  prerelease: false
37
+ - !ruby/object:Gem::Dependency
39
38
  type: :runtime
40
- name: activerecord
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ requirement: &id002 !ruby/object:Gem::Requirement
42
40
  none: false
43
41
  requirements:
44
42
  - - "="
@@ -49,12 +47,12 @@ dependencies:
49
47
  - 3
50
48
  - 10
51
49
  version: 2.3.10
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
50
+ name: activerecord
51
+ version_requirements: *id002
54
52
  prerelease: false
53
+ - !ruby/object:Gem::Dependency
55
54
  type: :runtime
56
- name: actionpack
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
58
56
  none: false
59
57
  requirements:
60
58
  - - "="
@@ -65,12 +63,12 @@ dependencies:
65
63
  - 3
66
64
  - 10
67
65
  version: 2.3.10
68
- requirement: *id003
69
- - !ruby/object:Gem::Dependency
66
+ name: actionpack
67
+ version_requirements: *id003
70
68
  prerelease: false
69
+ - !ruby/object:Gem::Dependency
71
70
  type: :development
72
- name: shoulda
73
- version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ requirement: &id004 !ruby/object:Gem::Requirement
74
72
  none: false
75
73
  requirements:
76
74
  - - ">="
@@ -79,12 +77,12 @@ dependencies:
79
77
  segments:
80
78
  - 0
81
79
  version: "0"
82
- requirement: *id004
83
- - !ruby/object:Gem::Dependency
80
+ name: shoulda
81
+ version_requirements: *id004
84
82
  prerelease: false
83
+ - !ruby/object:Gem::Dependency
85
84
  type: :development
86
- name: bundler
87
- version_requirements: &id005 !ruby/object:Gem::Requirement
85
+ requirement: &id005 !ruby/object:Gem::Requirement
88
86
  none: false
89
87
  requirements:
90
88
  - - ~>
@@ -95,12 +93,12 @@ dependencies:
95
93
  - 0
96
94
  - 0
97
95
  version: 1.0.0
98
- requirement: *id005
99
- - !ruby/object:Gem::Dependency
96
+ name: bundler
97
+ version_requirements: *id005
100
98
  prerelease: false
99
+ - !ruby/object:Gem::Dependency
101
100
  type: :development
102
- name: jeweler
103
- version_requirements: &id006 !ruby/object:Gem::Requirement
101
+ requirement: &id006 !ruby/object:Gem::Requirement
104
102
  none: false
105
103
  requirements:
106
104
  - - ~>
@@ -111,12 +109,12 @@ dependencies:
111
109
  - 5
112
110
  - 1
113
111
  version: 1.5.1
114
- requirement: *id006
115
- - !ruby/object:Gem::Dependency
112
+ name: jeweler
113
+ version_requirements: *id006
116
114
  prerelease: false
115
+ - !ruby/object:Gem::Dependency
117
116
  type: :development
118
- name: ruby-debug
119
- version_requirements: &id007 !ruby/object:Gem::Requirement
117
+ requirement: &id007 !ruby/object:Gem::Requirement
120
118
  none: false
121
119
  requirements:
122
120
  - - ">="
@@ -125,12 +123,12 @@ dependencies:
125
123
  segments:
126
124
  - 0
127
125
  version: "0"
128
- requirement: *id007
129
- - !ruby/object:Gem::Dependency
126
+ name: ruby-debug
127
+ version_requirements: *id007
130
128
  prerelease: false
129
+ - !ruby/object:Gem::Dependency
131
130
  type: :development
132
- name: thoughtbot-shoulda
133
- version_requirements: &id008 !ruby/object:Gem::Requirement
131
+ requirement: &id008 !ruby/object:Gem::Requirement
134
132
  none: false
135
133
  requirements:
136
134
  - - ">="
@@ -139,7 +137,9 @@ dependencies:
139
137
  segments:
140
138
  - 0
141
139
  version: "0"
142
- requirement: *id008
140
+ name: thoughtbot-shoulda
141
+ version_requirements: *id008
142
+ prerelease: false
143
143
  description: This gem is an ActiveRecord extension which provides a convenient interface for managing per row properties
144
144
  email: morten@zendesk.com
145
145
  executables: []
@@ -157,6 +157,7 @@ files:
157
157
  - README.rdoc
158
158
  - Rakefile
159
159
  - VERSION
160
+ - db/.gitignore
160
161
  - lib/property_sets.rb
161
162
  - lib/property_sets/action_view_extension.rb
162
163
  - lib/property_sets/active_record_extension.rb
@@ -200,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
201
  requirements: []
201
202
 
202
203
  rubyforge_project:
203
- rubygems_version: 1.3.7
204
+ rubygems_version: 1.6.2
204
205
  signing_key:
205
206
  specification_version: 3
206
207
  summary: Property sets for ActiveRecord