consul 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of consul might be problematic. Click here for more details.

Files changed (53) hide show
  1. data/README.md +49 -2
  2. data/Rakefile +26 -6
  3. data/consul.gemspec +8 -7
  4. data/lib/consul.rb +1 -0
  5. data/lib/consul/active_record.rb +5 -1
  6. data/lib/consul/controller.rb +18 -11
  7. data/lib/consul/errors.rb +1 -0
  8. data/lib/consul/power.rb +29 -4
  9. data/lib/consul/version.rb +1 -1
  10. data/spec/rails-2.3/Gemfile +12 -0
  11. data/spec/rails-2.3/Rakefile +11 -0
  12. data/spec/{app_root → rails-2.3/app_root}/app/controllers/application_controller.rb +0 -0
  13. data/spec/{app_root → rails-2.3/app_root}/app/controllers/cakes_controller.rb +0 -0
  14. data/spec/{app_root → rails-2.3/app_root}/app/controllers/dashboards_controller.rb +0 -0
  15. data/spec/{app_root → rails-2.3/app_root}/app/controllers/risks_controller.rb +0 -0
  16. data/spec/{app_root → rails-2.3/app_root}/app/controllers/songs_controller.rb +0 -0
  17. data/spec/{app_root → rails-2.3/app_root}/app/controllers/users_controller.rb +0 -0
  18. data/spec/{app_root → rails-2.3/app_root}/app/models/client.rb +0 -0
  19. data/spec/{app_root → rails-2.3/app_root}/app/models/note.rb +0 -0
  20. data/spec/{app_root → rails-2.3/app_root}/app/models/power.rb +25 -1
  21. data/spec/{app_root → rails-2.3/app_root}/app/models/user.rb +0 -0
  22. data/spec/{app_root → rails-2.3/app_root}/config/boot.rb +14 -0
  23. data/spec/{app_root → rails-2.3/app_root}/config/database.yml +0 -0
  24. data/spec/{app_root → rails-2.3/app_root}/config/environment.rb +0 -0
  25. data/spec/{app_root → rails-2.3/app_root}/config/environments/in_memory.rb +0 -0
  26. data/spec/{app_root → rails-2.3/app_root}/config/environments/mysql.rb +0 -0
  27. data/spec/{app_root → rails-2.3/app_root}/config/environments/postgresql.rb +0 -0
  28. data/spec/{app_root → rails-2.3/app_root}/config/environments/sqlite.rb +0 -0
  29. data/spec/{app_root → rails-2.3/app_root}/config/environments/sqlite3.rb +0 -0
  30. data/spec/rails-2.3/app_root/config/preinitializer.rb +20 -0
  31. data/spec/{app_root → rails-2.3/app_root}/config/routes.rb +0 -0
  32. data/spec/{app_root → rails-2.3/app_root}/db/migrate/001_create_users.rb +0 -0
  33. data/spec/{app_root → rails-2.3/app_root}/db/migrate/002_create_clients.rb +0 -0
  34. data/spec/{app_root → rails-2.3/app_root}/db/migrate/003_create_notes.rb +0 -0
  35. data/spec/{app_root → rails-2.3/app_root}/lib/console_with_fixtures.rb +0 -0
  36. data/spec/rails-2.3/app_root/log/.gitignore +1 -0
  37. data/spec/{app_root → rails-2.3/app_root}/script/console +0 -0
  38. data/spec/{rcov.opts → rails-2.3/rcov.opts} +0 -0
  39. data/spec/{spec.opts → rails-2.3/spec.opts} +0 -0
  40. data/spec/{spec_helper.rb → rails-2.3/spec_helper.rb} +9 -6
  41. data/spec/{consul → shared/consul}/active_record_spec.rb +0 -0
  42. data/spec/shared/consul/power_spec.rb +361 -0
  43. data/spec/{controllers → shared/controllers}/cakes_controller_spec.rb +1 -1
  44. data/spec/{controllers → shared/controllers}/dashboards_controller_spec.rb +1 -1
  45. data/spec/{controllers → shared/controllers}/risks_controller_spec.rb +1 -1
  46. data/spec/{controllers → shared/controllers}/songs_controller_spec.rb +1 -1
  47. data/spec/shared/controllers/users_controller_spec.rb +25 -0
  48. metadata +46 -119
  49. data/Gemfile +0 -3
  50. data/spec/consul/power_spec.rb +0 -127
  51. data/spec/controllers/users_controller_spec.rb +0 -13
  52. data/spec/support/spec.opts +0 -4
  53. data/spec/support/spec_candy.rb +0 -179
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source :rubygems
2
-
3
- gemspec
@@ -1,127 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Consul::Power do
4
-
5
- before :each do
6
- @user = User.create!
7
- @deleted_client = Client.create!(:deleted => true)
8
- @client1 = Client.create!
9
- @client1_note1 = @client1.notes.create!
10
- @client1_note2 = @client1.notes.create!
11
- @client2 = Client.create!
12
- @client2_note1 = @client2.notes.create!
13
- @client2_note2 = @client2.notes.create!
14
- end
15
-
16
- describe 'example scenario' do
17
-
18
- it 'should work as expected' do
19
- Client.active.should == [@client1, @client2]
20
- @client1.notes.should == [@client1_note1, @client1_note2]
21
- end
22
-
23
- end
24
-
25
- describe 'scope methods' do
26
-
27
- it 'should return the registered scope' do
28
- @user.power.clients.all.should == [@client1, @client2]
29
- end
30
-
31
- it 'should allow to register scopes with arguments' do
32
- @user.power.client_notes(@client1).should == [@client1_note1, @client1_note2]
33
- end
34
-
35
- end
36
-
37
- describe 'scope_ids methods' do
38
-
39
- it 'should return record ids that match the registered scope' do
40
- @user.power.client_ids.should == [@client1.id, @client2.id]
41
- end
42
-
43
- it 'should cache scope ids' do
44
- @user.power.should_receive(:clients).once.and_return(double('scope', :construct_finder_sql => 'SELECT 1').as_null_object)
45
- 2.times { @user.power.client_ids }
46
- end
47
-
48
- it 'should return ids when the scope joins another table (bugfix)' do
49
- expect { @user.power.note_ids }.to_not raise_error
50
- end
51
-
52
- end
53
-
54
- describe 'include?' do
55
-
56
- it 'should return true if a given record belongs to a scope' do
57
- @user.power.client?(@client1).should be_true
58
- end
59
-
60
- it 'should return false if a given record does not belong to a scope' do
61
- @user.power.client?(@deleted_client).should be_false
62
- end
63
-
64
- it 'should only trigger a single query for multiple checks on the same scope' do
65
- ActiveRecord::Base.connection.should_receive(:select_values).once.and_return([]) #.and_return(double('connection').as_null_object)
66
- @user.power.client?(@client1)
67
- @user.power.client?(@deleted_client)
68
- end
69
-
70
- it 'should return true when the queried power returns a scope (which might or might not match records)' do
71
- @user.power.clients?.should be_true
72
- end
73
-
74
- it 'should return true when the queried power is not a scope, but returns true' do
75
- @user.power.always_true?.should be_true
76
- end
77
-
78
- it 'should return false when the queried power is not a scope, but returns false' do
79
- @user.power.always_false?.should be_false
80
- end
81
-
82
- it 'should return false when the queried power is not a scope, but returns nil' do
83
- @user.power.always_nil?.should be_false
84
- end
85
-
86
- end
87
-
88
- describe 'include!' do
89
-
90
- it 'should raise Consul::Powerless when the given record belongs to a scope' do
91
- expect { @user.power.client!(@deleted_client) }.to raise_error(Consul::Powerless)
92
- end
93
-
94
- it 'should not raise Consul::Powerless when the given record does not belong to a scope' do
95
- expect { @user.power.client!(@client1) }.to_not raise_error
96
- end
97
-
98
- it 'should not raise Consul::Powerless when the queried power returns a scope (which might or might not match records)' do
99
- expect { @user.power.clients! }.to_not raise_error
100
- end
101
-
102
- it 'should not raise Consul::Powerless when the queried power is not a scope, but returns true' do
103
- expect { @user.power.always_true! }.to_not raise_error
104
- end
105
-
106
- it 'should raise Consul::Powerless when the queried power is not a scope, but returns false' do
107
- expect { @user.power.always_false! }.to raise_error(Consul::Powerless)
108
- end
109
-
110
- it 'should raise Consul::Powerless when the queried power is not a scope, but returns nil' do
111
- expect { @user.power.always_nil! }.to raise_error(Consul::Powerless)
112
- end
113
-
114
- end
115
-
116
- describe '.current' do
117
-
118
- it 'should provide a class method to set and get the current Power' do
119
- Power.current = 'current power'
120
- Power.current.should == 'current power'
121
- Power.current = nil
122
- Power.current.should be_nil
123
- end
124
-
125
- end
126
-
127
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe UsersController do
4
-
5
- it "should raise an error if the checked power is not given" do
6
- expect { get :update, :id => '1' }.to raise_error(Consul::Powerless)
7
- end
8
-
9
- it 'should allow to map actions to another power using the :map option' do
10
- expect { get :show, :id => '1' }.to_not raise_error
11
- end
12
-
13
- end
@@ -1,4 +0,0 @@
1
- --colour
2
- --format progress
3
- --loadby mtime
4
- --reverse
@@ -1,179 +0,0 @@
1
- # From https://makandracards.com/makandra/627-the-definitive-spec_candy-rb-rspec-helper
2
- Object.class_eval do
3
-
4
- def should_receive_chain(*parts)
5
- setup_expectation_chain(parts)
6
- end
7
-
8
- def self.new_with_stubs(attrs)
9
- new.tap do |obj|
10
- obj.stub_existing attrs
11
- end
12
- end
13
-
14
- def stub_existing(attrs)
15
- attrs.each do |method, value|
16
- if respond_to?(method, true)
17
- stub(method => value)
18
- else
19
- raise "Attempted to stub non-existing method ##{method} on a #{self.class.name}"
20
- end
21
- end
22
- end
23
-
24
- def should_receive_and_return(methods_and_values)
25
- methods_and_values.each do |method, value|
26
- should_receive(method).and_return(value)
27
- end
28
- end
29
-
30
- def should_receive_all_with(methods_and_values)
31
- methods_and_values.each do |method, value|
32
- should_receive(method).with(value)
33
- end
34
- end
35
-
36
- def should_not_receive_and_execute(method)
37
- should_receive_and_execute(method, true)
38
- end
39
-
40
- def should_receive_and_execute(method, negate = false)
41
- method_base = method.to_s.gsub(/([\?\!\=\[\]]+)$/, '')
42
- method_suffix = $1
43
-
44
- method_called = "_#{method_base}_called#{method_suffix}"
45
- method_with_spy = "#{method_base}_with_spy#{method_suffix}"
46
- method_without_spy = "#{method_base}_without_spy#{method_suffix}"
47
-
48
- prototype = respond_to?(:singleton_class) ? singleton_class : metaclass
49
- prototype.class_eval do
50
-
51
- unless method_defined?(method_with_spy)
52
-
53
- define_method method_called do
54
- end
55
-
56
- define_method method_with_spy do |*args, &block|
57
- send(method_called, *args)
58
- send(method_without_spy, *args, &block)
59
- end
60
- alias_method_chain method, :spy
61
- end
62
-
63
- end
64
-
65
- expectation = negate ? :should_not_receive : :should_receive
66
- send(expectation, method_called)
67
- end
68
-
69
- private
70
-
71
- def setup_expectation_chain(parts)
72
- obj = self
73
- for part in parts
74
- if part == parts.last
75
- obj = add_expectation_chain_link(obj, part)
76
- else
77
- next_obj = Spec::Mocks::Mock.new('chain link')
78
- add_expectation_chain_link(obj, part).at_least(:once).and_return(next_obj)
79
- obj = next_obj
80
- end
81
- end
82
- obj
83
- end
84
-
85
- def add_expectation_chain_link(obj, part)
86
- if part.is_a?(Array)
87
- obj.should_receive(part.first).with(*part[1..-1])
88
- else
89
- obj.should_receive(part)
90
- end
91
- end
92
-
93
- end
94
-
95
- Spec::Example::ExampleGroupMethods.class_eval do
96
-
97
- # Improves it_should_behave_like in some ways:
98
- # - It scopes the reused examples so #let und #subject does not bleed into the reusing example groups
99
- # - It allows to parametrize the reused example group by appending a hash argument.
100
- # Every key/value pair in the hash will become a #let variable for the reused example group
101
- # - You can call it with a block. It will be available to the reused example group as let(:block)
102
- def it_should_act_like(shared_example_group, environment = {}, &block)
103
- description = "as #{shared_example_group}"
104
- description << " (#{environment.inspect})" if environment.present?
105
- describe description do
106
- environment.each do |name, value|
107
- let(name) { value }
108
- end
109
- let(:block) { block } if block
110
- it_should_behave_like(shared_example_group)
111
- end
112
- end
113
-
114
- end
115
-
116
- Spec::Rails::Example::ModelExampleGroup.class_eval do
117
-
118
- def self.it_should_run_callbacks_in_order(*callbacks)
119
- callbacks.push(:ordered => true)
120
- it_should_run_callbacks(*callbacks)
121
- end
122
-
123
- def self.it_should_run_callbacks(*callbacks)
124
- options = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
125
- reason = callbacks.pop if callbacks.last.is_a?(String)
126
- hook = description_parts.last.sub(/^#/, '')
127
- should = ['should run callbacks', callbacks.inspect, ('in order' if options[:ordered]), reason].compact.join ' '
128
- send(:it, should) do
129
- callbacks.each do |callback|
130
- expectation = subject.should_receive(callback).once
131
- expectation.ordered if options[:ordered]
132
- end
133
- run_state_machine_callbacks_from_prose(hook) || subject.run_callbacks(hook)
134
- end
135
- end
136
-
137
- private
138
-
139
- def run_state_machine_callbacks_from_prose(prose)
140
- if parts = prose.match(/^(\w+) from ([\:\w]+) to ([\:\w]+)$/)
141
- name = parts[1].to_sym
142
- from = parts[2].sub(/^:/, '').to_sym
143
- to = parts[3].sub(/^:/, '').to_sym
144
- transition = StateMachine::Transition.new(subject, subject.class.state_machine, name, from, to)
145
- transition.run_callbacks
146
- end
147
- end
148
-
149
- end
150
-
151
- ActiveRecord::Base.class_eval do
152
-
153
- # Prevents the databse from being touched, but still runs all validations.
154
- def keep_invalid!
155
- errors.stub :empty? => false
156
- end
157
-
158
- end
159
-
160
- Class.class_eval do
161
-
162
- define_method :stub_any_instance do |stubs|
163
- unstubbed_new = method(:new)
164
- stub(:new).and_return do |*args|
165
- unstubbed_new.call(*args).tap do |obj|
166
- obj.stub stubs
167
- end
168
- end
169
- stubs
170
- end
171
-
172
- define_method :disposable_copy do |&body|
173
- this = self
174
- copy = Class.new(self, &body)
175
- copy.singleton_class.send(:define_method, :name) { this.name }
176
- copy
177
- end
178
-
179
- end