Fixed user settings.
This commit is contained in:
parent
ef2ce98e46
commit
f759552022
19 changed files with 925 additions and 5 deletions
117
vendor/plugins/acts_as_configurable/test/acts_as_configurable_test.rb
vendored
Normal file
117
vendor/plugins/acts_as_configurable/test/acts_as_configurable_test.rb
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
require 'test/unit'
|
||||
require File.dirname(__FILE__) + '/test_helper'
|
||||
require File.join(File.dirname(__FILE__), 'fixtures/entities')
|
||||
|
||||
|
||||
class ActsAsConfigurableTest < Test::Unit::TestCase
|
||||
fixtures :test_users, :test_groups
|
||||
|
||||
def setup
|
||||
@group = TestGroup.create(:display_name => 'Rails Core')
|
||||
@user = TestUser.create(:login => 'sam', :name => 'Sam Testuser', :email => 'sam@example.com')
|
||||
end
|
||||
|
||||
SETTINGS = ActiveRecord::Base.const_get('ConfigurableSettings')
|
||||
TARGETEDSETTINGS = ActiveRecord::Base.const_get('TargetedSettings')
|
||||
PROXYSETTING = ActiveRecord::Base.const_get('ProxySetting')
|
||||
USR_CFG = {
|
||||
:how_many_time_i_eat_out_a_week => 4,
|
||||
'what i am made of' => 'steel',
|
||||
:friends => ['bob', 'ken']
|
||||
}
|
||||
GR_ROLES = ['creator', 'member', 'fundraiser']
|
||||
|
||||
def test_user_model_settings
|
||||
|
||||
assert_equal 'sam', @user.login
|
||||
assert_equal 'Rails Core', @group.display_name
|
||||
|
||||
assert_equal 0, @user._configurable_settings.size
|
||||
assert_equal Array, @user.settings.class
|
||||
assert_equal SETTINGS, @user.settings.real_class
|
||||
assert_equal 0, @user.settings.size
|
||||
|
||||
@user.settings[:config] = USR_CFG
|
||||
|
||||
assert_equal 1, @user._configurable_settings.size
|
||||
assert_equal USR_CFG, @user.settings[:config]
|
||||
assert_equal 1, @user.settings.size
|
||||
assert_equal Hash, @user.settings[:config].class
|
||||
assert_equal PROXYSETTING, @user.settings[:config].real_class
|
||||
assert_equal 3, @user.settings[:config].keys.size
|
||||
assert_equal 4, @user.settings[:config][:how_many_time_i_eat_out_a_week]
|
||||
assert_equal Array, @user.settings[:config][:friends].class
|
||||
assert_equal 2, @user.settings[:config][:friends].size
|
||||
|
||||
@user.settings[:my_group] = @group
|
||||
|
||||
assert_equal 2, @user.settings.size
|
||||
assert_equal TestGroup, @user.settings[:my_group].class
|
||||
|
||||
end
|
||||
|
||||
def test_new_each_with_key
|
||||
@user.settings[:config] = USR_CFG
|
||||
@user.settings.each_with_key do |key, setting|
|
||||
assert_equal :config.to_s, key
|
||||
assert_equal USR_CFG, setting
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_valid_raw_setting
|
||||
|
||||
assert ConfigurableSetting.find(:first).nil?
|
||||
|
||||
@user.settings[:config] = USR_CFG
|
||||
|
||||
first_setting = ConfigurableSetting.find(:first)
|
||||
|
||||
assert_equal 'config', first_setting.name
|
||||
assert_equal 'TestUser', first_setting.configurable_type
|
||||
assert_equal @user.id, first_setting.configurable_id
|
||||
assert_equal nil, first_setting.targetable_type
|
||||
assert_equal nil, first_setting.targetable_id
|
||||
assert_equal USR_CFG.to_yaml, first_setting.value
|
||||
|
||||
end
|
||||
|
||||
|
||||
def test_associated_settings
|
||||
|
||||
assert_equal [], @user.settings
|
||||
assert_equal [], @user.settings_for(@group)
|
||||
|
||||
@user.settings_for(@group)[:roles] = GR_ROLES
|
||||
|
||||
assert_equal GR_ROLES, @user.settings_for(@group)[:roles]
|
||||
assert_equal 1, @user.settings_for(@group).size
|
||||
assert_equal 0, @user.settings.size
|
||||
|
||||
end
|
||||
|
||||
|
||||
def test_associated_target_settings
|
||||
|
||||
assert_equal [], @group.targeted_settings
|
||||
assert_equal TARGETEDSETTINGS, @group.targeted_settings.real_class
|
||||
|
||||
@user.settings_for(@group)[:roles] = GR_ROLES
|
||||
|
||||
assert_equal 1, @group._targetable_settings.size
|
||||
assert_equal 1, @group.targeted_settings.size
|
||||
assert_equal 1, @group.targeted_settings_for(@user).size
|
||||
assert_equal GR_ROLES, @group.targeted_settings_for(@user)[:roles]
|
||||
@group.targeted_settings.each do |x|
|
||||
assert x.owner == @user and x.target == @group and x.name == 'roles'
|
||||
end
|
||||
@group.targeted_settings.each do |x|
|
||||
assert x == GR_ROLES
|
||||
end
|
||||
@group.targeted_settings[:roles].each do |x|
|
||||
assert x.owner == @user and x == GR_ROLES
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
14
vendor/plugins/acts_as_configurable/test/fixtures/entities.rb
vendored
Normal file
14
vendor/plugins/acts_as_configurable/test/fixtures/entities.rb
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class TestUser < ActiveRecord::Base
|
||||
|
||||
acts_as_configurable
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
class TestGroup < ActiveRecord::Base
|
||||
|
||||
acts_as_configurable
|
||||
acts_as_configurable_target
|
||||
|
||||
end
|
||||
4
vendor/plugins/acts_as_configurable/test/fixtures/test_groups.yml
vendored
Normal file
4
vendor/plugins/acts_as_configurable/test/fixtures/test_groups.yml
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
test_groups_001:
|
||||
id: "1"
|
||||
display_name: Clan of the Cavebear
|
||||
11
vendor/plugins/acts_as_configurable/test/fixtures/test_users.yml
vendored
Normal file
11
vendor/plugins/acts_as_configurable/test/fixtures/test_users.yml
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
test_users_001:
|
||||
name: Bob Testuser
|
||||
id: "1"
|
||||
login: bob
|
||||
email: bob@example.com
|
||||
test_users_002:
|
||||
name: Ken Testuser
|
||||
id: "2"
|
||||
login: ken
|
||||
email: ken@example.com
|
||||
28
vendor/plugins/acts_as_configurable/test/schema.rb
vendored
Normal file
28
vendor/plugins/acts_as_configurable/test/schema.rb
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
ActiveRecord::Migration.verbose = false
|
||||
|
||||
ActiveRecord::Schema.define(:version => 0) do
|
||||
|
||||
create_table :configurable_settings, :force => true do |t|
|
||||
t.column :configurable_id, :integer
|
||||
t.column :configurable_type, :string
|
||||
t.column :targetable_id, :integer
|
||||
t.column :targetable_type, :string
|
||||
t.column :name, :string, :default => "", :null => false
|
||||
t.column :value_type, :string
|
||||
t.column :value, :text
|
||||
end
|
||||
add_index :configurable_settings, :name
|
||||
|
||||
create_table :test_groups, :force => true do |t|
|
||||
t.column :display_name, :string, :limit => 80
|
||||
end
|
||||
|
||||
create_table :test_users, :force => true do |t|
|
||||
t.column :login, :string, :limit => 20
|
||||
t.column :name, :string, :limit => 80
|
||||
t.column :email, :string
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ActiveRecord::Migration.verbose = true
|
||||
30
vendor/plugins/acts_as_configurable/test/test_helper.rb
vendored
Normal file
30
vendor/plugins/acts_as_configurable/test/test_helper.rb
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
ENV["RAILS_ENV"] = "test"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
|
||||
|
||||
require 'test/unit'
|
||||
require 'active_record/fixtures'
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
||||
|
||||
load(File.dirname(__FILE__) + '/schema.rb')
|
||||
|
||||
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + '/fixtures/'
|
||||
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
||||
|
||||
class Test::Unit::TestCase #:nodoc:
|
||||
def create_fixtures(*table_names)
|
||||
if block_given?
|
||||
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
|
||||
else
|
||||
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
|
||||
end
|
||||
end
|
||||
|
||||
# Turn off transactional fixtures if you're working with MyISAM tables in MySQL
|
||||
self.use_transactional_fixtures = true
|
||||
|
||||
# Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
|
||||
self.use_instantiated_fixtures = false
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue