cantango-config 0.1.0

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.
Files changed (83) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +40 -0
  4. data/Gemfile.lock +163 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.mdown +21 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/cantango-config.gemspec +145 -0
  10. data/lib/cantango/adapter/compiler.rb +9 -0
  11. data/lib/cantango/adapter/moneta.rb +23 -0
  12. data/lib/cantango/config.rb +12 -0
  13. data/lib/cantango/configuration/ability.rb +14 -0
  14. data/lib/cantango/configuration/account.rb +23 -0
  15. data/lib/cantango/configuration/accounts.rb +8 -0
  16. data/lib/cantango/configuration/adapters.rb +24 -0
  17. data/lib/cantango/configuration/autoload.rb +38 -0
  18. data/lib/cantango/configuration/candidate_registry.rb +94 -0
  19. data/lib/cantango/configuration/categories.rb +57 -0
  20. data/lib/cantango/configuration/debug.rb +41 -0
  21. data/lib/cantango/configuration/engine.rb +33 -0
  22. data/lib/cantango/configuration/engines.rb +97 -0
  23. data/lib/cantango/configuration/factory.rb +59 -0
  24. data/lib/cantango/configuration/guest.rb +57 -0
  25. data/lib/cantango/configuration/hash_registry.rb +91 -0
  26. data/lib/cantango/configuration/hooks.rb +12 -0
  27. data/lib/cantango/configuration/localhosts.rb +12 -0
  28. data/lib/cantango/configuration/models/actions.rb +26 -0
  29. data/lib/cantango/configuration/models/active_record.rb +22 -0
  30. data/lib/cantango/configuration/models/data_mapper.rb +12 -0
  31. data/lib/cantango/configuration/models/generic.rb +12 -0
  32. data/lib/cantango/configuration/models/mongo.rb +12 -0
  33. data/lib/cantango/configuration/models/mongo_mapper.rb +11 -0
  34. data/lib/cantango/configuration/models/mongoid.rb +13 -0
  35. data/lib/cantango/configuration/models.rb +77 -0
  36. data/lib/cantango/configuration/modes.rb +21 -0
  37. data/lib/cantango/configuration/orms.rb +8 -0
  38. data/lib/cantango/configuration/registry.rb +56 -0
  39. data/lib/cantango/configuration/user.rb +47 -0
  40. data/lib/cantango/configuration/users.rb +8 -0
  41. data/lib/cantango/configuration.rb +99 -0
  42. data/spec/cantango/config_spec.rb +8 -0
  43. data/spec/cantango/configuration/ability_spec.rb +13 -0
  44. data/spec/cantango/configuration/account_spec.rb +21 -0
  45. data/spec/cantango/configuration/accounts_spec.rb +18 -0
  46. data/spec/cantango/configuration/adapters_spec.rb +30 -0
  47. data/spec/cantango/configuration/autoload_spec.rb +52 -0
  48. data/spec/cantango/configuration/candidate_registry_spec.rb +12 -0
  49. data/spec/cantango/configuration/categories_spec.rb +58 -0
  50. data/spec/cantango/configuration/debug_spec.rb +39 -0
  51. data/spec/cantango/configuration/engines/engine_shared.rb +22 -0
  52. data/spec/cantango/configuration/engines_spec.rb +102 -0
  53. data/spec/cantango/configuration/factory_spec.rb +18 -0
  54. data/spec/cantango/configuration/guest/find_guest_default_way_spec.rb +32 -0
  55. data/spec/cantango/configuration/guest_spec.rb +61 -0
  56. data/spec/cantango/configuration/hash_registry_spec.rb +22 -0
  57. data/spec/cantango/configuration/localhosts_spec.rb +9 -0
  58. data/spec/cantango/configuration/models_spec.rb +47 -0
  59. data/spec/cantango/configuration/orms_spec.rb +9 -0
  60. data/spec/cantango/configuration/registry_spec.rb +15 -0
  61. data/spec/cantango/configuration/shared/candidate_registry_ex.rb +47 -0
  62. data/spec/cantango/configuration/shared/factory_ex.rb +40 -0
  63. data/spec/cantango/configuration/shared/hash_registry_ex.rb +55 -0
  64. data/spec/cantango/configuration/shared/modes_ex.rb +14 -0
  65. data/spec/cantango/configuration/shared/registry_ex.rb +40 -0
  66. data/spec/cantango/configuration/shared/role_registry_ex.rb +22 -0
  67. data/spec/cantango/configuration/user_spec.rb +45 -0
  68. data/spec/cantango/configuration/users_spec.rb +18 -0
  69. data/spec/cantango/configuration_spec.rb +112 -0
  70. data/spec/db/database.yml +4 -0
  71. data/spec/factories/project.rb +6 -0
  72. data/spec/fixtures/models/admin.rb +2 -0
  73. data/spec/fixtures/models/admin_account.rb +22 -0
  74. data/spec/fixtures/models/items.rb +8 -0
  75. data/spec/fixtures/models/permission.rb +12 -0
  76. data/spec/fixtures/models/project.rb +2 -0
  77. data/spec/fixtures/models/simple_roles.rb +49 -0
  78. data/spec/fixtures/models/user.rb +52 -0
  79. data/spec/fixtures/models/user_account.rb +21 -0
  80. data/spec/fixtures/models.rb +2 -0
  81. data/spec/migrations/001_create_projects.rb +12 -0
  82. data/spec/spec_helper.rb +35 -0
  83. metadata +231 -0
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+ require 'cantango/configuration/shared/hash_registry_ex'
3
+
4
+ class MyEngine < CanTango::Engine
5
+ end
6
+
7
+ class MyOtherEngine < CanTango::Engine
8
+ end
9
+
10
+
11
+ describe CanTango::Configuration::Modes do
12
+ subject { CanTango.config.engines }
13
+
14
+ it_should_behave_like "Hash Registry" do
15
+ let(:hash1) do
16
+ {:my_engine => MyEngine}
17
+ end
18
+
19
+ let(:hash2) do
20
+ {:my_other_engine => MyOtherEngine}
21
+ end
22
+ end
23
+
24
+ specify do
25
+ lambda { subject.register :my_engine => 3 }.should raise_error
26
+ end
27
+
28
+ specify do
29
+ lambda { subject.register :my_engine => MyEngine }.should_not raise_error
30
+ end
31
+
32
+ describe '#registered' do
33
+ before do
34
+ subject.register :my_engine => MyEngine
35
+ end
36
+
37
+ specify { subject.registered[:my_engine].should == MyEngine }
38
+ specify { subject.registered_names.should include('my_engine') }
39
+ specify { subject.available.should include('my_engine') }
40
+ specify { subject.available?('my_engine').should be_true }
41
+ specify { subject.available?('not_my_engine').should be_false }
42
+ end
43
+
44
+ let(:engines) do
45
+ {:my_engine => MyEngine}.merge :my_other_engine => MyOtherEngine
46
+ end
47
+
48
+ before do
49
+ subject.register engines
50
+ end
51
+
52
+ describe 'execution order' do
53
+ before do
54
+ subject.set_execution_order :my_other_engine, :engine, :my_engine, :my_other_engine
55
+ end
56
+
57
+ its(:execution_order) { should == ['my_other_engine', 'my_engine'] }
58
+ end
59
+
60
+ describe 'excute_first' do
61
+ before do
62
+ subject.set_execution_order :my_other_engine, :my_engine
63
+ subject.execute_first :my_engine
64
+ end
65
+
66
+ its(:execution_order) { should == ['my_engine', 'my_other_engine'] }
67
+ end
68
+
69
+ describe 'execute_last' do
70
+ before do
71
+ subject.set_execution_order :my_other_engine, :my_engine
72
+ subject.execute_last :my_other_engine
73
+ end
74
+
75
+ its(:execution_order) { should == ['my_engine', 'my_other_engine'] }
76
+ end
77
+
78
+ describe 'execute_before' do
79
+ before do
80
+ subject.set_execution_order :my_other_engine, :my_engine
81
+ subject.execute_before :my_other_engine, :my_engine
82
+ end
83
+
84
+ its(:execution_order) { should == ['my_engine', 'my_other_engine'] }
85
+ end
86
+
87
+ describe 'execute_after' do
88
+ before do
89
+ subject.set_execution_order :my_other_engine, :my_engine
90
+ subject.execute_after :my_engine, :my_other_engine,
91
+ end
92
+
93
+ its(:execution_order) { should == ['my_engine', 'my_other_engine'] }
94
+ end
95
+
96
+ # all state
97
+ # any? state
98
+ # clear!
99
+ # each
100
+ # active? name
101
+ # active
102
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'cantango/configuration/shared/factory_ex'
3
+
4
+ class MyFactory
5
+ include CanTango::Configuration::Factory
6
+ include Singleton
7
+ end
8
+
9
+ describe CanTango::Configuration::Factory do
10
+ subject { MyFactory.instance }
11
+
12
+ specify { lambda { subject.default_factory}.should raise_error }
13
+
14
+ it_should_behave_like 'Factory' do
15
+ end
16
+ end
17
+
18
+
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ class MyAccount
4
+ def self.guest
5
+ :guest_account
6
+ end
7
+ end
8
+
9
+ class MyUser
10
+ def self.guest
11
+ :guest
12
+ end
13
+ end
14
+
15
+ describe CanTango::Configuration::Guest do
16
+ describe 'default settings with class methods for #guest defined' do
17
+ before do
18
+ CanTango.config.user.base_class = MyUser
19
+ CanTango.config.user_account.base_class = MyAccount
20
+ end
21
+
22
+ subject { CanTango.config.guest }
23
+ its(:default_user?) { should be_true }
24
+ its(:user) { should == :guest }
25
+
26
+ its(:default_account?) { should be_true }
27
+ its(:account) { should == :guest_account }
28
+ end
29
+ end
30
+
31
+
32
+
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/models'
3
+
4
+ describe CanTango::Configuration::Guest do
5
+ before do
6
+ CanTango.config.user.base_class = User
7
+ CanTango.config.user_account.base_class = UserAccount
8
+ end
9
+
10
+ subject { CanTango.config.guest }
11
+
12
+ describe 'default settings' do
13
+ it 'should not have defined UserAccount.guest' do
14
+ UserAccount.should_not respond_to(:guest)
15
+ end
16
+
17
+ it 'should not have defined User.guest' do
18
+ User.should_not respond_to(:guest)
19
+ end
20
+
21
+ its(:account) { should be_nil } # should be set to UserAccount.guest if defined
22
+ its(:user) { should be_nil } # should set to User.guest if defined ?
23
+ end
24
+
25
+ describe 'set user' do
26
+ describe 'with obj arg' do
27
+ before :each do
28
+ subject.user = '2'
29
+ end
30
+
31
+ its(:user) { should == '2' }
32
+ end
33
+
34
+ describe 'with block arg' do
35
+ before :each do
36
+ subject.user { 2 }
37
+ end
38
+
39
+ its(:user) { should == 2 }
40
+ end
41
+
42
+ describe 'with Proc arg' do
43
+ before :each do
44
+ subject.user Proc.new { 2 }
45
+ end
46
+
47
+ its(:user) { should be_a Proc }
48
+ end
49
+ end
50
+
51
+ describe 'set user account' do
52
+ before :each do
53
+ subject.account = '2'
54
+ end
55
+
56
+ its(:account) { should == '2' }
57
+ end
58
+ end
59
+
60
+
61
+
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'cantango/configuration/shared/hash_registry_ex'
3
+
4
+ class MyRegis < CanTango::Configuration::HashRegistry
5
+ end
6
+
7
+ describe MyRegis do
8
+ subject { MyRegis.new }
9
+
10
+ it_should_behave_like "Hash Registry" do
11
+ let(:hash1) do
12
+ {:a => 1, :b => 2}
13
+ end
14
+
15
+ let(:hash2) do
16
+ {:c => 3}
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+ require 'cantango/configuration/shared/registry_ex'
3
+
4
+ describe CanTango::Configuration::Localhosts do
5
+ subject { CanTango.config.localhosts }
6
+
7
+ it_should_behave_like "Registry" do
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'cantango/configuration/shared/hash_registry_ex'
3
+ require 'fixtures/models/project'
4
+
5
+ CanTango.debug!
6
+ connect_db
7
+ migrate
8
+
9
+ describe CanTango::Configuration::Models do
10
+ let(:models) { CanTango.config.models }
11
+ let(:orms) { CanTango.config.orms }
12
+
13
+ it_should_behave_like "Hash Registry" do
14
+ subject { models.actions }
15
+
16
+ let(:hash1) do
17
+ {:a => 1, :b => 2}
18
+ end
19
+
20
+ let(:hash2) do
21
+ {:c => 3}
22
+ end
23
+ end
24
+
25
+ subject { models }
26
+
27
+ describe 'available_models' do
28
+ before do
29
+ orms.register :active_record
30
+ end
31
+
32
+ specify { subject.available_models.should_not be_empty }
33
+ specify { subject.available_models.should include('Project') }
34
+ end
35
+
36
+ describe 'by_reg_exp' do
37
+ end
38
+
39
+ describe 'by_category' do
40
+ end
41
+
42
+ describe 'exclude' do
43
+ end
44
+
45
+ describe 'excluded' do
46
+ end
47
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+ require 'cantango/configuration/shared/registry_ex'
3
+
4
+ describe CanTango::Configuration::Orms do
5
+ subject { CanTango.config.orms }
6
+
7
+ it_should_behave_like "Registry" do
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'cantango/configuration/shared/role_registry_ex'
3
+
4
+ class MyRegi < CanTango::Configuration::Registry
5
+ end
6
+
7
+ describe MyRegi do
8
+ subject { MyRegi.new }
9
+
10
+ it_should_behave_like "Registry" do
11
+ end
12
+ end
13
+
14
+
15
+
@@ -0,0 +1,47 @@
1
+ class A
2
+ end
3
+
4
+ class B
5
+ end
6
+
7
+ shared_examples_for 'Candidate Registry' do
8
+ let(:hash1) do
9
+ {:a => A, :b => B}
10
+ end
11
+
12
+ let(:hash2) do
13
+ {:c => 3}
14
+ end
15
+
16
+ describe 'register' do
17
+ before do
18
+ subject.register :a, A
19
+
20
+ end
21
+ its(:registered) { should include(:a) }
22
+ specify do
23
+ lambda { subject.register :b, 3 }.should raise_error
24
+ end
25
+ end
26
+
27
+ describe 'append <<' do
28
+ before do
29
+ subject << hash1
30
+ end
31
+ its(:registered) { should include(*hash1.keys) }
32
+ its(:registered_classes) { should include(*hash1.values) }
33
+
34
+ specify do
35
+ lambda { subject << hash2 }.should raise_error
36
+ end
37
+ end
38
+
39
+ describe 'set index []=' do
40
+ before do
41
+ subject.clean!
42
+ subject[:a] = B
43
+ end
44
+ its(:registered_classes) { should include(B) }
45
+ end
46
+ end
47
+
@@ -0,0 +1,40 @@
1
+ class CustomFactory
2
+ attr_accessor :name, :options
3
+
4
+ def initialize name, options = {}
5
+ @name, @options = [name, options]
6
+ end
7
+ end
8
+
9
+ shared_examples_for 'Factory' do
10
+ describe 'configure factory' do
11
+ describe 'set factory' do
12
+ describe 'using non-callable' do
13
+ it 'should not allow factory to be defined' do
14
+ lambda { subject.factory {|name, opts| CustomFactory.new name, opts} }.should raise_error
15
+ end
16
+ end
17
+
18
+ describe 'using lambda' do
19
+ before :each do
20
+ subject.factory lambda {|name, opts| CustomFactory.new name, opts}
21
+ end
22
+
23
+ it 'should set it' do
24
+ subject.factory_build('hello', :works => true).name.should == 'hello'
25
+ end
26
+ end
27
+
28
+ describe 'using Proc' do
29
+ before :each do
30
+ subject.factory Proc.new {|name, opts| CustomFactory.new name, opts}
31
+ end
32
+
33
+ it 'should set it' do
34
+ subject.factory_build('hello', :works => true).name.should == 'hello'
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,55 @@
1
+ shared_examples_for 'Hash Registry' do
2
+ describe 'default settings' do
3
+ describe 'defaults' do
4
+ before do
5
+ subject.default = hash1
6
+ end
7
+
8
+ its(:default) { should include(hash1) }
9
+ end
10
+ end
11
+
12
+ describe 'register' do
13
+ before do
14
+ subject.register hash1
15
+ subject.register hash2
16
+ end
17
+ its(:registered) { should include(hash1) }
18
+ its(:registered) { should include(hash2) }
19
+ end
20
+
21
+ describe 'append <<' do
22
+ before do
23
+ subject << hash2
24
+ subject.register hash1
25
+ subject << hash2
26
+ end
27
+ its(:registered) { should include(hash1, hash2) }
28
+ end
29
+
30
+ describe 'get index []' do
31
+ before do
32
+ subject.register hash1
33
+ subject << hash2
34
+ end
35
+
36
+ it 'should respond to :symbol keys' do
37
+ subject[:c].should == hash2[:c]
38
+ end
39
+
40
+ it "should respond to 'string' keys" do
41
+ subject['c'].should == hash2[:c]
42
+ end
43
+ end
44
+
45
+ describe 'set index []=' do
46
+ before do
47
+ subject.clean!
48
+ subject.register hash1
49
+ subject[:d] = hash2[:c]
50
+ end
51
+ specify { subject[:d].should == hash2[:c] }
52
+
53
+ end
54
+ end
55
+
@@ -0,0 +1,14 @@
1
+ shared_examples_for 'Modes' do
2
+ describe 'valid mode=' do
3
+ before do
4
+ subject.mode = :cache
5
+ end
6
+ specify { subject.modes.should == [:cache] }
7
+ end
8
+
9
+ describe 'invalid mode=' do
10
+ specify do
11
+ lambda { subject.mode = :cachy! }.should raise_error
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ shared_examples_for 'Registry' do
2
+ describe 'default settings' do
3
+
4
+ #its(:registered) { should be_empty }
5
+
6
+ it 'should register groups' do
7
+ subject.register(:a, :b)
8
+ subject.registered.should include(:a, :b)
9
+ end
10
+
11
+ it 'should set defaults' do
12
+ subject.default = :a, :b
13
+ subject.default.should include(:a, :b)
14
+ end
15
+ end
16
+
17
+ describe 'register' do
18
+ before do
19
+ subject.register :abc, :def
20
+ end
21
+ its(:registered) { should include(:abc, :def) }
22
+ end
23
+
24
+ describe 'append <<' do
25
+ before do
26
+ subject.clean!
27
+ subject.register :abc, :def
28
+ subject << :xyz
29
+ end
30
+ its(:registered) { should include(:abc, :def, :xyz) }
31
+ end
32
+
33
+ describe 'get index []' do
34
+ before do
35
+ subject.clean!
36
+ subject.register :abc, :def
37
+ end
38
+ specify {subject[0].should == :abc }
39
+ end
40
+ end
@@ -0,0 +1,22 @@
1
+ require 'cantango/configuration/shared/registry_ex'
2
+
3
+ shared_examples_for 'Role Registry' do
4
+ it_should_behave_like "Registry"
5
+
6
+ describe 'default settings' do
7
+ its(:has_method) { should == has }
8
+ its(:list_method) { should == list }
9
+
10
+ its(:default_has_method) { should be_a Symbol }
11
+ its(:default_list_method) { should be_a Symbol }
12
+ end
13
+
14
+ describe "exclude" do
15
+ before do
16
+ subject.exclude :admin
17
+ end
18
+
19
+ its(:excluded) { should include(:admin) }
20
+ end
21
+ end
22
+
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'fixtures/models'
3
+
4
+ class BaseUser
5
+ def initialize
6
+ end
7
+ end
8
+
9
+ describe CanTango::Configuration::User do
10
+ before do
11
+ CanTango.config.user.base_class = User
12
+ CanTango.config.user_account.base_class = UserAccount
13
+ end
14
+
15
+ subject { CanTango.config.user }
16
+
17
+ describe 'default settings' do
18
+ its(:relations) { should_not be_empty }
19
+ its(:unique_key_field) { should == :email }
20
+ its(:base_class) { should == ::User }
21
+ end
22
+
23
+ describe 'set base class' do
24
+ before do
25
+ subject.base_class = BaseUser
26
+ end
27
+
28
+ its(:base_class) { should == BaseUser }
29
+ end
30
+
31
+ describe 'relations config' do
32
+ before do
33
+ subject.relations = :mine
34
+ end
35
+ its(:relations) { should include(:mine) }
36
+ end
37
+
38
+ describe 'unique_key_field config' do
39
+ before do
40
+ subject.unique_key_field = :username
41
+ end
42
+ its(:unique_key_field) { should == :username }
43
+ end
44
+ end
45
+
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'cantango/configuration/shared/candidate_registry_ex'
3
+
4
+ class User
5
+ end
6
+
7
+ class Admin
8
+ end
9
+
10
+ describe CanTango::Configuration::Users do
11
+ subject { CanTango.config.users }
12
+
13
+ it_should_behave_like "Candidate Registry" do
14
+ let(:hash1) do
15
+ {:a => User, :b => Admin}
16
+ end
17
+ end
18
+ end