surrounded 0.8.4 → 0.9.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.
@@ -3,18 +3,18 @@ require 'test_helper'
3
3
  describe Surrounded::Context, '.role' do
4
4
  class RoleContextTester
5
5
  extend Surrounded::Context
6
-
6
+
7
7
  role_methods :admin do
8
8
  end
9
9
  end
10
-
10
+
11
11
  describe 'modules' do
12
12
  it 'creates a module' do
13
13
  role = RoleContextTester.const_get(:Admin)
14
14
  refute_instance_of Class, role
15
15
  assert_kind_of Module, role
16
16
  end
17
-
17
+
18
18
  it 'marks the constant private' do
19
19
  error = assert_raises(NameError){
20
20
  RoleContextTester::Admin
@@ -22,21 +22,21 @@ describe Surrounded::Context, '.role' do
22
22
  assert_match(/private constant/i, error.message)
23
23
  end
24
24
  end
25
-
25
+
26
26
  class WrapperRoleContext
27
27
  extend Surrounded::Context
28
-
28
+
29
29
  role :admin, :wrap do
30
-
30
+
31
31
  end
32
32
  end
33
-
33
+
34
34
  describe 'wrappers' do
35
35
  it 'creates a wrapper' do
36
36
  role = WrapperRoleContext.const_get('Admin')
37
37
  assert_includes(role.ancestors, SimpleDelegator)
38
38
  end
39
-
39
+
40
40
  it 'marks the constant private' do
41
41
  error = assert_raises(NameError){
42
42
  WrapperRoleContext::Admin
@@ -44,97 +44,103 @@ describe Surrounded::Context, '.role' do
44
44
  assert_match(/private constant/i, error.message)
45
45
  end
46
46
  end
47
- if test_rebinding_methods?
48
- class InterfaceContext
49
- extend Surrounded::Context
50
-
51
- initialize(:admin, :other)
52
-
53
- role :admin, :interface do
54
- def hello
55
- 'hello from admin'
56
- end
57
- end
58
-
59
- trigger :admin_hello do
60
- admin.hello
61
- end
62
- end
63
-
64
- class Hello
65
- include Surrounded
47
+ class InterfaceContext
48
+ extend Surrounded::Context
49
+
50
+ initialize(:admin, :other)
51
+
52
+ role :admin, :interface do
66
53
  def hello
67
- 'hello'
54
+ 'hello from admin'
68
55
  end
69
56
  end
70
-
71
- describe 'interfaces' do
72
- let(:context){
73
- InterfaceContext.new(Hello.new, Hello.new)
57
+
58
+ trigger :admin_hello do
59
+ admin.hello
60
+ end
61
+ end
62
+
63
+ class Hello
64
+ include Surrounded
65
+ def hello
66
+ 'hello'
67
+ end
68
+ end
69
+
70
+ describe 'interfaces' do
71
+ let(:context){
72
+ InterfaceContext.new(Hello.new, Hello.new)
73
+ }
74
+ it 'sets interface objects to use interface methods before singleton methods' do
75
+ assert_equal 'hello from admin', context.admin_hello
76
+ end
77
+
78
+ it 'marks the inteface constant private' do
79
+ error = assert_raises(NameError){
80
+ InterfaceContext::AdminInterface
74
81
  }
75
- it 'sets interface objects to use interface methods before singleton methods' do
76
- assert_equal 'hello from admin', context.admin_hello
77
- end
78
-
79
- it 'marks the inteface constant private' do
80
- error = assert_raises(NameError){
81
- InterfaceContext::AdminInterface
82
- }
83
- assert_match(/private constant/i, error.message)
84
- end
85
-
86
- it 'creates a private accessor method' do
87
- assert_respond_to(context, :admin)
88
- end
82
+ assert_match(/private constant/i, error.message)
83
+ end
84
+
85
+ it 'creates a private accessor method' do
86
+ assert_respond_to(context, :admin)
89
87
  end
90
88
  end
91
-
89
+
92
90
  describe 'unknown' do
93
91
  it 'raises an error' do
94
92
  assert_raises(Surrounded::Context::InvalidRoleType){
95
93
  class UnknownRole
96
94
  extend Surrounded::Context
97
-
95
+
98
96
  role :admin, :unknown do
99
97
  end
100
98
  end
101
99
  }
102
100
  end
103
101
  end
104
-
102
+
105
103
  describe 'custom default' do
104
+ include Surrounded # the test is a role player here
105
+
106
106
  it 'allows the use of custom default role types' do
107
107
  class CustomDefaultWrap
108
108
  extend Surrounded::Context
109
-
109
+
110
110
  self.default_role_type = :wrap
111
- apply_roles_on(:initialize)
112
-
113
- initialize(:admin)
114
-
111
+
112
+ initialize(:admin, :the_test)
113
+
115
114
  role :admin do
116
115
  end
116
+
117
+ trigger :check_admin_type do
118
+ the_test.assert_kind_of SimpleDelegator, admin
119
+ end
117
120
  end
118
- context = CustomDefaultWrap.new(Object.new)
119
- assert_kind_of(SimpleDelegator, context.send(:admin))
121
+ context = CustomDefaultWrap.new(Object.new, self)
122
+ context.check_admin_type
120
123
  end
121
-
122
- it 'allows the setting of custom default role time for all Surrounded::Contexts' do
124
+
125
+ it 'allows the setting of custom default role type for all Surrounded::Contexts' do
123
126
  begin
124
127
  old_default = Surrounded::Context.default_role_type
125
128
  Surrounded::Context.default_role_type = :wrap
126
129
  class CustomGlobalDefault
127
130
  extend Surrounded::Context
128
- apply_roles_on(:initialize)
129
-
130
- initialize(:admin)
131
-
131
+
132
+ initialize(:admin, :the_test)
133
+
132
134
  role :admin do
133
135
  end
136
+
137
+ trigger :check_admin_type do
138
+ the_test.assert_kind_of SimpleDelegator, admin
139
+ end
134
140
  end
135
-
136
- context = CustomGlobalDefault.new(Object.new)
137
- assert_kind_of(SimpleDelegator, context.send(:admin))
141
+
142
+ context = CustomGlobalDefault.new(Object.new, self)
143
+ context.check_admin_type
138
144
  ensure
139
145
  Surrounded::Context.default_role_type = old_default
140
146
  end
@@ -46,8 +46,9 @@ describe Surrounded::Context, '.trigger' do
46
46
 
47
47
  it 'preserves arguments and blocks' do
48
48
  result = context.block_method('argument') do |*args, obj|
49
- "Having an #{args.first} with #{obj}"
49
+ "Having an #{args.first} with #{obj.class}"
50
50
  end
51
+ assert_equal "Having an argument with TestContext", result
51
52
  end
52
53
 
53
54
  it 'allows usage of regular methods for triggers' do
data/test/test_helper.rb CHANGED
@@ -36,16 +36,3 @@ class TestContext
36
36
  end
37
37
  trigger :regular_method_trigger
38
38
  end
39
-
40
- # This is a different implementation of module_method_rebinding?
41
- # created in order to check that the behavior of the code is correct.
42
- #
43
- # This method is used in tests and module_method_rebinding? is used
44
- # in the library code.
45
- def test_rebinding_methods?
46
- unbound = Enumerable.instance_method(:count)
47
- unbound.bind(Object.new)
48
- true
49
- rescue TypeError
50
- false
51
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surrounded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Jim Gay'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-04 00:00:00.000000000 Z
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: triad
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: 0.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.2
26
+ version: 0.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,18 @@ files:
66
66
  - LICENSE.txt
67
67
  - README.md
68
68
  - Rakefile
69
+ - examples/bottles.rb
69
70
  - examples/rails.rb
71
+ - images/body-bg.png
72
+ - images/highlight-bg.jpg
73
+ - images/hr.png
74
+ - images/octocat-icon.png
75
+ - images/surrounded.png
76
+ - images/tar-gz-icon.png
77
+ - images/zip-icon.png
78
+ - index.html
79
+ - javascripts/main.js
80
+ - javascripts/scale.fix.js
70
81
  - lib/surrounded.rb
71
82
  - lib/surrounded/access_control.rb
72
83
  - lib/surrounded/context.rb
@@ -74,10 +85,16 @@ files:
74
85
  - lib/surrounded/context/negotiator.rb
75
86
  - lib/surrounded/context/role_builders.rb
76
87
  - lib/surrounded/context/role_map.rb
88
+ - lib/surrounded/context/trigger_controls.rb
77
89
  - lib/surrounded/context_errors.rb
78
90
  - lib/surrounded/east_oriented.rb
79
91
  - lib/surrounded/shortcuts.rb
80
92
  - lib/surrounded/version.rb
93
+ - params.json
94
+ - stylesheets/print.css
95
+ - stylesheets/pygment_trac.css
96
+ - stylesheets/styles.css
97
+ - stylesheets/stylesheet.css
81
98
  - surrounded.gemspec
82
99
  - test/context_access_test.rb
83
100
  - test/context_shortcuts_test.rb
@@ -85,6 +102,7 @@ files:
85
102
  - test/example_proxy_test.rb
86
103
  - test/example_threaded_test.rb
87
104
  - test/example_wrapper_test.rb
105
+ - test/override_methods_test.rb
88
106
  - test/role_context_method_test.rb
89
107
  - test/surrounded_context_test.rb
90
108
  - test/surrounded_test.rb
@@ -120,6 +138,7 @@ test_files:
120
138
  - test/example_proxy_test.rb
121
139
  - test/example_threaded_test.rb
122
140
  - test/example_wrapper_test.rb
141
+ - test/override_methods_test.rb
123
142
  - test/role_context_method_test.rb
124
143
  - test/surrounded_context_test.rb
125
144
  - test/surrounded_test.rb