preferences 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,10 @@
1
1
  == master
2
2
 
3
+ == 0.3.0 / 2009-04-13
4
+
5
+ * Add dependency on Rails 2.3
6
+ * Remove dependency on plugins_plus
7
+
3
8
  == 0.2.0 / 2008-12-14
4
9
 
5
10
  * Remove the PluginAWeek namespace
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Aaron Pfeifer
1
+ Copyright (c) 2008-2009 Aaron Pfeifer
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -182,5 +182,4 @@ To run against a specific version of Rails:
182
182
 
183
183
  == Dependencies
184
184
 
185
- * Rails 2.1 or later
186
- * plugins_plus[http://github.com/pluginaweek/plugins_plugins] (optional if app files are copied to your project tree)
185
+ * Rails 2.3 or later
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'preferences'
8
- s.version = '0.2.0'
8
+ s.version = '0.3.0'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Adds support for easily creating custom preferences for models'
11
11
 
@@ -8,16 +8,11 @@
8
8
  # +owner+ is the User, the +attribute+ is the color, and the +group+ is the Car.
9
9
  # This allows preferences to have a sort of context around them.
10
10
  class Preference < ActiveRecord::Base
11
- belongs_to :owner,
12
- :polymorphic => true
13
- belongs_to :group,
14
- :polymorphic => true
11
+ belongs_to :owner, :polymorphic => true
12
+ belongs_to :group, :polymorphic => true
15
13
 
16
- validates_presence_of :attribute,
17
- :owner_id,
18
- :owner_type
19
- validates_presence_of :group_type,
20
- :if => :group_id?
14
+ validates_presence_of :attribute, :owner_id, :owner_type
15
+ validates_presence_of :group_type, :if => :group_id?
21
16
 
22
17
  class << self
23
18
  # Splits the given group into its corresponding id and type. For simple
data/lib/preferences.rb CHANGED
@@ -50,7 +50,7 @@ module Preferences
50
50
  # be typecasted to true/false based on ActiveRecord rules.
51
51
  #
52
52
  # Configuration options:
53
- # * +default+ - The default value for the preference. Default is nil.
53
+ # * <tt>:default</tt> - The default value for the preference. Default is nil.
54
54
  #
55
55
  # == Examples
56
56
  #
@@ -70,7 +70,9 @@ module Preferences
70
70
  #
71
71
  # After the first preference is defined, the following associations are
72
72
  # created for the model:
73
- # * +stored_preferences+ - A collection of all the custom preferences specified for a record. This will not include default preferences unless they have been explicitly set.
73
+ # * +stored_preferences+ - A collection of all the custom preferences
74
+ # specified for a record. This will not include default preferences
75
+ # unless they have been explicitly set.
74
76
  #
75
77
  # == Generated accessors
76
78
  #
@@ -120,9 +122,7 @@ module Preferences
120
122
  class_inheritable_hash :default_preferences
121
123
  self.default_preferences = {}
122
124
 
123
- has_many :stored_preferences,
124
- :as => :owner,
125
- :class_name => 'Preference'
125
+ has_many :stored_preferences, :as => :owner, :class_name => 'Preference'
126
126
 
127
127
  after_save :update_preferences
128
128
 
@@ -175,20 +175,24 @@ module Preferences
175
175
  # == Examples
176
176
  #
177
177
  # A user with no stored values:
178
+ #
178
179
  # user = User.find(:first)
179
180
  # user.preferences
180
181
  # => {"language"=>"English", "color"=>nil}
181
182
  #
182
183
  # A user with stored values for a particular group:
184
+ #
183
185
  # user.preferred_color = 'red', 'cars'
184
186
  # user.preferences
185
187
  # => {"language"=>"English", "color"=>nil, "cars"=>{"language=>"English", "color"=>"red"}}
186
188
  #
187
189
  # Getting preference values *just* for the owning record (i.e. excluding groups):
190
+ #
188
191
  # user.preferences(nil)
189
192
  # => {"language"=>"English", "color"=>nil}
190
193
  #
191
194
  # Getting preference values for a particular group:
195
+ #
192
196
  # user.preferences('cars')
193
197
  # => {"language"=>"English", "color"=>"red"}
194
198
  def preferences(*args)
@@ -1,9 +1,13 @@
1
1
  class MigratePreferencesToVersion1 < ActiveRecord::Migration
2
2
  def self.up
3
- Rails::Plugin.find(:preferences).migrate(1)
3
+ ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../db/migrate", 0).migrations.each do |migration|
4
+ migration.migrate(:up)
5
+ end
4
6
  end
5
7
 
6
8
  def self.down
7
- Rails::Plugin.find(:preferences).migrate(0)
9
+ ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../db/migrate", 0).migrations.each do |migration|
10
+ migration.migrate(:down)
11
+ end
8
12
  end
9
13
  end
@@ -1,6 +1,6 @@
1
1
  require "#{File.dirname(__FILE__)}/../test_helper"
2
2
 
3
- class PreferencesTest < Test::Unit::TestCase
3
+ class PreferencesTest < ActiveSupport::TestCase
4
4
  def setup
5
5
  User.preference :notifications, :boolean
6
6
 
@@ -54,7 +54,7 @@ class PreferencesTest < Test::Unit::TestCase
54
54
  end
55
55
  end
56
56
 
57
- class UserByDefaultTest < Test::Unit::TestCase
57
+ class UserByDefaultTest < ActiveSupport::TestCase
58
58
  def setup
59
59
  @user = User.new
60
60
  end
@@ -94,7 +94,7 @@ class UserByDefaultTest < Test::Unit::TestCase
94
94
  end
95
95
  end
96
96
 
97
- class UserTest < Test::Unit::TestCase
97
+ class UserTest < ActiveSupport::TestCase
98
98
  def setup
99
99
  @user = new_user
100
100
  end
@@ -162,7 +162,7 @@ class UserTest < Test::Unit::TestCase
162
162
  end
163
163
  end
164
164
 
165
- class UserAfterBeingCreatedTest < Test::Unit::TestCase
165
+ class UserAfterBeingCreatedTest < ActiveSupport::TestCase
166
166
  def setup
167
167
  @user = create_user
168
168
  end
@@ -172,7 +172,7 @@ class UserAfterBeingCreatedTest < Test::Unit::TestCase
172
172
  end
173
173
  end
174
174
 
175
- class UserWithoutStoredPreferencesTest < Test::Unit::TestCase
175
+ class UserWithoutStoredPreferencesTest < ActiveSupport::TestCase
176
176
  def setup
177
177
  @user = create_user
178
178
  end
@@ -206,7 +206,7 @@ class UserWithoutStoredPreferencesTest < Test::Unit::TestCase
206
206
  end
207
207
  end
208
208
 
209
- class UserWithStoredPreferencesTest < Test::Unit::TestCase
209
+ class UserWithStoredPreferencesTest < ActiveSupport::TestCase
210
210
  def setup
211
211
  @user = create_user
212
212
  @user.preferred_language = 'Latin'
@@ -281,7 +281,7 @@ class UserWithStoredPreferencesTest < Test::Unit::TestCase
281
281
  end
282
282
  end
283
283
 
284
- class UserWithStoredPreferencesForBasicGroupsTest < Test::Unit::TestCase
284
+ class UserWithStoredPreferencesForBasicGroupsTest < ActiveSupport::TestCase
285
285
  def setup
286
286
  @user = create_user
287
287
  @user.preferred_color = 'red', 'cars'
@@ -363,7 +363,7 @@ class UserWithStoredPreferencesForBasicGroupsTest < Test::Unit::TestCase
363
363
  end
364
364
  end
365
365
 
366
- class UserWithStoredPreferencesForActiveRecordGroupsTest < Test::Unit::TestCase
366
+ class UserWithStoredPreferencesForActiveRecordGroupsTest < ActiveSupport::TestCase
367
367
  def setup
368
368
  @car = create_car
369
369
 
@@ -1,6 +1,6 @@
1
1
  require "#{File.dirname(__FILE__)}/../test_helper"
2
2
 
3
- class PreferenceDefinitionByDefaultTest < Test::Unit::TestCase
3
+ class PreferenceDefinitionByDefaultTest < ActiveSupport::TestCase
4
4
  def setup
5
5
  @definition = Preferences::PreferenceDefinition.new(:notifications)
6
6
  end
@@ -22,13 +22,13 @@ class PreferenceDefinitionByDefaultTest < Test::Unit::TestCase
22
22
  end
23
23
  end
24
24
 
25
- class PreferenceDefinitionTest < Test::Unit::TestCase
25
+ class PreferenceDefinitionTest < ActiveSupport::TestCase
26
26
  def test_should_raise_exception_if_invalid_option_specified
27
27
  assert_raise(ArgumentError) {Preferences::PreferenceDefinition.new(:notifications, :invalid => true)}
28
28
  end
29
29
  end
30
30
 
31
- class PreferenceDefinitionWithDefaultValueTest < Test::Unit::TestCase
31
+ class PreferenceDefinitionWithDefaultValueTest < ActiveSupport::TestCase
32
32
  def setup
33
33
  @definition = Preferences::PreferenceDefinition.new(:notifications, :boolean, :default => 1)
34
34
  end
@@ -38,7 +38,7 @@ class PreferenceDefinitionWithDefaultValueTest < Test::Unit::TestCase
38
38
  end
39
39
  end
40
40
 
41
- class PreferenceDefinitionWithAnyTypeTest < Test::Unit::TestCase
41
+ class PreferenceDefinitionWithAnyTypeTest < ActiveSupport::TestCase
42
42
  def setup
43
43
  @definition = Preferences::PreferenceDefinition.new(:notifications, :any)
44
44
  end
@@ -74,7 +74,7 @@ class PreferenceDefinitionWithAnyTypeTest < Test::Unit::TestCase
74
74
  end
75
75
  end
76
76
 
77
- class PreferenceDefinitionWithBooleanTypeTest < Test::Unit::TestCase
77
+ class PreferenceDefinitionWithBooleanTypeTest < ActiveSupport::TestCase
78
78
  def setup
79
79
  @definition = Preferences::PreferenceDefinition.new(:notifications)
80
80
  end
@@ -120,7 +120,7 @@ class PreferenceDefinitionWithBooleanTypeTest < Test::Unit::TestCase
120
120
  end
121
121
  end
122
122
 
123
- class PreferenceDefinitionWithNumericTypeTest < Test::Unit::TestCase
123
+ class PreferenceDefinitionWithNumericTypeTest < ActiveSupport::TestCase
124
124
  def setup
125
125
  @definition = Preferences::PreferenceDefinition.new(:notifications, :integer)
126
126
  end
@@ -150,7 +150,7 @@ class PreferenceDefinitionWithNumericTypeTest < Test::Unit::TestCase
150
150
  end
151
151
  end
152
152
 
153
- class PreferenceDefinitionWithStringTypeTest < Test::Unit::TestCase
153
+ class PreferenceDefinitionWithStringTypeTest < ActiveSupport::TestCase
154
154
  def setup
155
155
  @definition = Preferences::PreferenceDefinition.new(:notifications, :string)
156
156
  end
@@ -1,6 +1,6 @@
1
1
  require "#{File.dirname(__FILE__)}/../test_helper"
2
2
 
3
- class PreferenceByDefaultTest < Test::Unit::TestCase
3
+ class PreferenceByDefaultTest < ActiveSupport::TestCase
4
4
  def setup
5
5
  @preference = Preference.new
6
6
  end
@@ -34,7 +34,7 @@ class PreferenceByDefaultTest < Test::Unit::TestCase
34
34
  end
35
35
  end
36
36
 
37
- class PreferenceTest < Test::Unit::TestCase
37
+ class PreferenceTest < ActiveSupport::TestCase
38
38
  def test_should_be_valid_with_a_set_of_valid_attributes
39
39
  preference = new_preference
40
40
  assert preference.valid?
@@ -102,7 +102,7 @@ class PreferenceTest < Test::Unit::TestCase
102
102
  end
103
103
  end
104
104
 
105
- class PreferenceAsAClassTest < Test::Unit::TestCase
105
+ class PreferenceAsAClassTest < ActiveSupport::TestCase
106
106
  def test_should_be_able_to_split_nil_groups
107
107
  group_id, group_type = Preference.split_group(nil)
108
108
  assert_nil group_id
@@ -128,7 +128,7 @@ class PreferenceAsAClassTest < Test::Unit::TestCase
128
128
  end
129
129
  end
130
130
 
131
- class PreferenceAfterBeingCreatedTest < Test::Unit::TestCase
131
+ class PreferenceAfterBeingCreatedTest < ActiveSupport::TestCase
132
132
  def setup
133
133
  User.preference :notifications, :boolean
134
134
 
@@ -157,7 +157,7 @@ class PreferenceAfterBeingCreatedTest < Test::Unit::TestCase
157
157
  end
158
158
  end
159
159
 
160
- class PreferenceWithBasicGroupTest < Test::Unit::TestCase
160
+ class PreferenceWithBasicGroupTest < ActiveSupport::TestCase
161
161
  def setup
162
162
  @preference = create_preference(:group_type => 'car')
163
163
  end
@@ -167,7 +167,7 @@ class PreferenceWithBasicGroupTest < Test::Unit::TestCase
167
167
  end
168
168
  end
169
169
 
170
- class PreferenceWithActiveRecordGroupTest < Test::Unit::TestCase
170
+ class PreferenceWithActiveRecordGroupTest < ActiveSupport::TestCase
171
171
  def setup
172
172
  @car = create_car
173
173
  @preference = create_preference(:group => @car)
@@ -178,7 +178,7 @@ class PreferenceWithActiveRecordGroupTest < Test::Unit::TestCase
178
178
  end
179
179
  end
180
180
 
181
- class PreferenceWithBooleanAttributeTest < Test::Unit::TestCase
181
+ class PreferenceWithBooleanAttributeTest < ActiveSupport::TestCase
182
182
  def setup
183
183
  User.preference :notifications, :boolean
184
184
  end
@@ -210,7 +210,7 @@ class PreferenceWithBooleanAttributeTest < Test::Unit::TestCase
210
210
  end
211
211
  end
212
212
 
213
- class PreferenceWithSTIOwnerTest < Test::Unit::TestCase
213
+ class PreferenceWithSTIOwnerTest < ActiveSupport::TestCase
214
214
  def setup
215
215
  @manager = create_manager
216
216
  @preference = create_preference(:owner => @manager, :attribute => 'health_insurance', :value => true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preferences
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-14 00:00:00 -05:00
12
+ date: 2009-04-13 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -41,8 +41,6 @@ files:
41
41
  - test/app_root/db/migrate/002_create_cars.rb
42
42
  - test/app_root/db/migrate/001_create_users.rb
43
43
  - test/app_root/db/migrate/003_create_employees.rb
44
- - test/app_root/config
45
- - test/app_root/config/environment.rb
46
44
  - test/app_root/app
47
45
  - test/app_root/app/models
48
46
  - test/app_root/app/models/car.rb
@@ -76,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
74
  requirements: []
77
75
 
78
76
  rubyforge_project: pluginaweek
79
- rubygems_version: 1.2.0
77
+ rubygems_version: 1.3.1
80
78
  signing_key:
81
79
  specification_version: 2
82
80
  summary: Adds support for easily creating custom preferences for models
@@ -1,9 +0,0 @@
1
- require 'config/boot'
2
- require "#{File.dirname(__FILE__)}/../../../../plugins_plus/boot"
3
-
4
- Rails::Initializer.run do |config|
5
- config.plugin_paths << '..'
6
- config.plugins = %w(plugins_plus preferences)
7
- config.cache_classes = false
8
- config.whiny_nils = true
9
- end