preferences 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +17 -0
- data/README.rdoc +41 -10
- data/Rakefile +19 -17
- data/app/models/preference.rb +1 -1
- data/generators/preferences/USAGE +5 -0
- data/generators/preferences/preferences_generator.rb +7 -0
- data/generators/preferences/templates/001_create_preferences.rb +16 -0
- data/lib/preferences.rb +334 -63
- data/lib/preferences/preference_definition.rb +12 -4
- data/test/app_root/app/models/user.rb +6 -5
- data/test/app_root/db/migrate/004_migrate_preferences_to_version_1.rb +2 -2
- data/test/functional/preferences_test.rb +1171 -240
- data/test/test_helper.rb +13 -0
- data/test/unit/preference_definition_test.rb +35 -1
- data/test/unit/preference_test.rb +5 -1
- metadata +18 -22
data/test/test_helper.rb
CHANGED
@@ -11,3 +11,16 @@ require File.expand_path("#{File.dirname(__FILE__)}/factory")
|
|
11
11
|
Test::Unit::TestCase.class_eval do
|
12
12
|
include Factory
|
13
13
|
end
|
14
|
+
|
15
|
+
# Add query counter
|
16
|
+
ActiveRecord::Base.connection.class.class_eval do
|
17
|
+
IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /SHOW FIELDS/]
|
18
|
+
|
19
|
+
def execute_with_query_record(sql, name = nil, &block)
|
20
|
+
$queries_executed ||= []
|
21
|
+
$queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
|
22
|
+
execute_without_query_record(sql, name, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method_chain :execute, :query_record
|
26
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
3
|
class PreferenceDefinitionByDefaultTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
@@ -13,6 +13,10 @@ class PreferenceDefinitionByDefaultTest < ActiveSupport::TestCase
|
|
13
13
|
assert_nil @definition.default_value
|
14
14
|
end
|
15
15
|
|
16
|
+
def test_should_have_a_type
|
17
|
+
assert_equal :boolean, @definition.type
|
18
|
+
end
|
19
|
+
|
16
20
|
def test_should_type_cast_values_as_booleans
|
17
21
|
assert_equal nil, @definition.type_cast(nil)
|
18
22
|
assert_equal true, @definition.type_cast(true)
|
@@ -38,11 +42,29 @@ class PreferenceDefinitionWithDefaultValueTest < ActiveSupport::TestCase
|
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
45
|
+
class PreferenceDefinitionWithStringifiedTypeTest < ActiveSupport::TestCase
|
46
|
+
def setup
|
47
|
+
@definition = Preferences::PreferenceDefinition.new(:notifications, 'any')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_should_symbolize_type
|
51
|
+
assert_equal :any, @definition.type
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
41
55
|
class PreferenceDefinitionWithAnyTypeTest < ActiveSupport::TestCase
|
42
56
|
def setup
|
43
57
|
@definition = Preferences::PreferenceDefinition.new(:notifications, :any)
|
44
58
|
end
|
45
59
|
|
60
|
+
def test_use_custom_type
|
61
|
+
assert_equal :any, @definition.type
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_should_not_be_number
|
65
|
+
assert !@definition.number?
|
66
|
+
end
|
67
|
+
|
46
68
|
def test_should_not_type_cast
|
47
69
|
assert_equal nil, @definition.type_cast(nil)
|
48
70
|
assert_equal 0, @definition.type_cast(0)
|
@@ -79,6 +101,10 @@ class PreferenceDefinitionWithBooleanTypeTest < ActiveSupport::TestCase
|
|
79
101
|
@definition = Preferences::PreferenceDefinition.new(:notifications)
|
80
102
|
end
|
81
103
|
|
104
|
+
def test_should_not_be_number
|
105
|
+
assert !@definition.number?
|
106
|
+
end
|
107
|
+
|
82
108
|
def test_should_not_type_cast_if_value_is_nil
|
83
109
|
assert_equal nil, @definition.type_cast(nil)
|
84
110
|
end
|
@@ -125,6 +151,10 @@ class PreferenceDefinitionWithNumericTypeTest < ActiveSupport::TestCase
|
|
125
151
|
@definition = Preferences::PreferenceDefinition.new(:notifications, :integer)
|
126
152
|
end
|
127
153
|
|
154
|
+
def test_should_be_number
|
155
|
+
assert @definition.number?
|
156
|
+
end
|
157
|
+
|
128
158
|
def test_should_type_cast_true_to_integer
|
129
159
|
assert_equal 1, @definition.type_cast(true)
|
130
160
|
end
|
@@ -155,6 +185,10 @@ class PreferenceDefinitionWithStringTypeTest < ActiveSupport::TestCase
|
|
155
185
|
@definition = Preferences::PreferenceDefinition.new(:notifications, :string)
|
156
186
|
end
|
157
187
|
|
188
|
+
def test_should_not_be_number
|
189
|
+
assert !@definition.number?
|
190
|
+
end
|
191
|
+
|
158
192
|
def test_should_type_cast_integers_to_strings
|
159
193
|
assert_equal '1', @definition.type_cast('1')
|
160
194
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
3
|
class PreferenceByDefaultTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
@@ -114,6 +114,10 @@ class PreferenceAsAClassTest < ActiveSupport::TestCase
|
|
114
114
|
assert_nil group_id
|
115
115
|
assert_equal 'car', group_type
|
116
116
|
|
117
|
+
group_id, group_type = Preference.split_group(:car)
|
118
|
+
assert_nil group_id
|
119
|
+
assert_equal 'car', group_type
|
120
|
+
|
117
121
|
group_id, group_type = Preference.split_group(10)
|
118
122
|
assert_nil group_id
|
119
123
|
assert_equal 10, group_type
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-03-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: Adds support for easily creating custom preferences for ActiveRecord models
|
17
17
|
email: aaron@pluginaweek.org
|
18
18
|
executables: []
|
19
19
|
|
@@ -22,31 +22,25 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
- app/models
|
26
25
|
- app/models/preference.rb
|
27
|
-
-
|
26
|
+
- generators/preferences/USAGE
|
27
|
+
- generators/preferences/preferences_generator.rb
|
28
|
+
- generators/preferences/templates/001_create_preferences.rb
|
28
29
|
- lib/preferences/preference_definition.rb
|
29
30
|
- lib/preferences.rb
|
30
|
-
- test/factory.rb
|
31
|
-
- test/test_helper.rb
|
32
|
-
- test/functional
|
33
|
-
- test/functional/preferences_test.rb
|
34
|
-
- test/unit
|
35
31
|
- test/unit/preference_test.rb
|
36
32
|
- test/unit/preference_definition_test.rb
|
37
|
-
- test/app_root
|
38
|
-
- test/app_root/db
|
39
|
-
- test/app_root/db/migrate
|
33
|
+
- test/app_root/db/migrate/003_create_employees.rb
|
40
34
|
- test/app_root/db/migrate/004_migrate_preferences_to_version_1.rb
|
41
35
|
- test/app_root/db/migrate/002_create_cars.rb
|
42
36
|
- test/app_root/db/migrate/001_create_users.rb
|
43
|
-
- test/app_root/db/migrate/003_create_employees.rb
|
44
|
-
- test/app_root/app
|
45
|
-
- test/app_root/app/models
|
46
37
|
- test/app_root/app/models/car.rb
|
47
|
-
- test/app_root/app/models/manager.rb
|
48
|
-
- test/app_root/app/models/user.rb
|
49
38
|
- test/app_root/app/models/employee.rb
|
39
|
+
- test/app_root/app/models/user.rb
|
40
|
+
- test/app_root/app/models/manager.rb
|
41
|
+
- test/test_helper.rb
|
42
|
+
- test/factory.rb
|
43
|
+
- test/functional/preferences_test.rb
|
50
44
|
- CHANGELOG.rdoc
|
51
45
|
- init.rb
|
52
46
|
- LICENSE
|
@@ -54,6 +48,8 @@ files:
|
|
54
48
|
- README.rdoc
|
55
49
|
has_rdoc: true
|
56
50
|
homepage: http://www.pluginaweek.org
|
51
|
+
licenses: []
|
52
|
+
|
57
53
|
post_install_message:
|
58
54
|
rdoc_options: []
|
59
55
|
|
@@ -74,11 +70,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
70
|
requirements: []
|
75
71
|
|
76
72
|
rubyforge_project: pluginaweek
|
77
|
-
rubygems_version: 1.3.
|
73
|
+
rubygems_version: 1.3.5
|
78
74
|
signing_key:
|
79
|
-
specification_version:
|
80
|
-
summary: Adds support for easily creating custom preferences for models
|
75
|
+
specification_version: 3
|
76
|
+
summary: Adds support for easily creating custom preferences for ActiveRecord models
|
81
77
|
test_files:
|
82
|
-
- test/functional/preferences_test.rb
|
83
78
|
- test/unit/preference_test.rb
|
84
79
|
- test/unit/preference_definition_test.rb
|
80
|
+
- test/functional/preferences_test.rb
|