ee_preferences 0.4.3
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.
- checksums.yaml +15 -0
- data/.gitignore +8 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.rdoc +85 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +224 -0
- data/Rakefile +36 -0
- data/app/models/preference.rb +65 -0
- 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/init.rb +1 -0
- data/lib/preferences/preference_definition.rb +56 -0
- data/lib/preferences/version.rb +3 -0
- data/lib/preferences.rb +616 -0
- data/preferences.gemspec +20 -0
- data/test/app_root/app/models/car.rb +2 -0
- data/test/app_root/app/models/employee.rb +2 -0
- data/test/app_root/app/models/manager.rb +3 -0
- data/test/app_root/app/models/user.rb +8 -0
- data/test/app_root/db/migrate/001_create_users.rb +11 -0
- data/test/app_root/db/migrate/002_create_cars.rb +11 -0
- data/test/app_root/db/migrate/003_create_employees.rb +12 -0
- data/test/app_root/db/migrate/004_migrate_preferences_to_version_1.rb +13 -0
- data/test/factory.rb +65 -0
- data/test/functional/preferences_test.rb +1364 -0
- data/test/test_helper.rb +26 -0
- data/test/unit/preference_definition_test.rb +237 -0
- data/test/unit/preference_test.rb +236 -0
- metadata +122 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
class MigratePreferencesToVersion1 < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../generators/preferences/templates", 0).migrations.each do |migration|
|
4
|
+
migration.migrate(:up)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.down
|
9
|
+
ActiveRecord::Migrator.new(:down, "#{Rails.root}/../../generators/preferences/templates", 0).migrations.each do |migration|
|
10
|
+
migration.migrate(:down)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/test/factory.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Factory
|
2
|
+
# Build actions for the model
|
3
|
+
def self.build(model, &block)
|
4
|
+
name = model.to_s.underscore
|
5
|
+
|
6
|
+
define_method("#{name}_attributes", block)
|
7
|
+
define_method("valid_#{name}_attributes") {|*args| valid_attributes_for(model, *args)}
|
8
|
+
define_method("new_#{name}") {|*args| new_record(model, *args)}
|
9
|
+
define_method("create_#{name}") {|*args| create_record(model, *args)}
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get valid attributes for the model
|
13
|
+
def valid_attributes_for(model, attributes = {})
|
14
|
+
name = model.to_s.underscore
|
15
|
+
send("#{name}_attributes", attributes)
|
16
|
+
attributes.stringify_keys!
|
17
|
+
attributes
|
18
|
+
end
|
19
|
+
|
20
|
+
# Build an unsaved record
|
21
|
+
def new_record(model, *args)
|
22
|
+
attributes = valid_attributes_for(model, *args)
|
23
|
+
record = model.new(attributes)
|
24
|
+
attributes.each {|attr, value| record.send("#{attr}=", value) if model.accessible_attributes && !model.accessible_attributes.include?(attr) || model.protected_attributes && model.protected_attributes.include?(attr)}
|
25
|
+
record
|
26
|
+
end
|
27
|
+
|
28
|
+
# Build and save/reload a record
|
29
|
+
def create_record(model, *args)
|
30
|
+
record = new_record(model, *args)
|
31
|
+
record.save!
|
32
|
+
record.reload
|
33
|
+
record
|
34
|
+
end
|
35
|
+
|
36
|
+
build Car do |attributes|
|
37
|
+
attributes.reverse_merge!(
|
38
|
+
:name => 'Porsche'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
build Employee do |attributes|
|
43
|
+
attributes.reverse_merge!(
|
44
|
+
:name => 'John Smith'
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
build Manager do |attributes|
|
49
|
+
valid_employee_attributes(attributes)
|
50
|
+
end
|
51
|
+
|
52
|
+
build Preference do |attributes|
|
53
|
+
attributes[:owner] = create_user unless attributes.include?(:owner)
|
54
|
+
attributes.reverse_merge!(
|
55
|
+
:name => 'notifications',
|
56
|
+
:value => false
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
build User do |attributes|
|
61
|
+
attributes.reverse_merge!(
|
62
|
+
:login => 'admin'
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|