class-action 0.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +33 -16
- data/.travis.yml +6 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile.lock +62 -0
- data/README.md +42 -11
- data/class-action.gemspec +1 -0
- data/lib/class-action/rspec.rb +2 -0
- data/lib/class_action/action.rb +113 -63
- data/lib/class_action/rspec/class_action_example_group.rb +57 -0
- data/lib/class_action/rspec/have_class_action_matcher.rb +67 -0
- data/lib/class_action/rspec/respond_to_format_matcher.rb +72 -0
- data/lib/class_action/rspec/respond_with_matcher.rb +60 -0
- data/lib/class_action/rspec.rb +3 -0
- data/lib/class_action/version.rb +1 -1
- data/lib/class_action.rb +12 -8
- data/spec/class_action/action_spec.rb +202 -29
- data/spec/class_action/rspec/have_class_action_matcher_spec.rb +69 -0
- data/spec/class_action/rspec/respond_to_format_matcher_spec.rb +76 -0
- data/spec/class_action/rspec/respond_with_matcher_spec.rb +84 -0
- data/spec/class_action_spec.rb +8 -1
- data/spec/spec_helper.rb +6 -0
- metadata +32 -7
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/ClassAction.sublime-project +0 -10
- data/ClassAction.sublime-workspace +0 -1873
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'class_action/rspec'
|
3
|
+
|
4
|
+
describe ClassAction::RSpec::RespondToFormatMatcher do
|
5
|
+
|
6
|
+
class RespondToTestClassAction1 < ClassAction::Action
|
7
|
+
end
|
8
|
+
class RespondToTestClassAction2 < ClassAction::Action
|
9
|
+
respond_to :json
|
10
|
+
respond_to :html do
|
11
|
+
@responded_to_html = true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
class RespondToTestClassAction3 < ClassAction::Action
|
15
|
+
respond_to :html, on: :ok
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:controller) { ActionController::Base.new }
|
19
|
+
|
20
|
+
context "without a condition" do
|
21
|
+
|
22
|
+
it "should fail if the action does not respond to the given format" do
|
23
|
+
action = RespondToTestClassAction1.new(controller)
|
24
|
+
expect { expect(action).to respond_to_format(:html) }.to \
|
25
|
+
raise_error(
|
26
|
+
RSpec::Expectations::ExpectationNotMetError,
|
27
|
+
"expected action of class RespondToTestClassAction1 to respond to format :html"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should pass if the action responds to the given format" do
|
32
|
+
action = RespondToTestClassAction2.new(controller)
|
33
|
+
expect { expect(action).to respond_to_format(:json) }.not_to raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should execute a given block" do
|
37
|
+
action = RespondToTestClassAction2.new(controller)
|
38
|
+
|
39
|
+
called = false
|
40
|
+
expect(action).to respond_to_format(:json) do
|
41
|
+
called = true
|
42
|
+
end
|
43
|
+
expect(called).to be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should first execute the response block for a given format" do
|
47
|
+
action = RespondToTestClassAction2.new(controller)
|
48
|
+
|
49
|
+
response_block_called = false
|
50
|
+
expect(action).to respond_to_format(:html) do
|
51
|
+
response_block_called = controller.instance_variable_get('@responded_to_html')
|
52
|
+
end
|
53
|
+
expect(response_block_called).to be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with a condition" do
|
59
|
+
|
60
|
+
it "should fail if the action does not respond to the given format for the given condition" do
|
61
|
+
action = RespondToTestClassAction3.new(controller)
|
62
|
+
expect { expect(action).to respond_to_format(:html).on(:invalid) }.to \
|
63
|
+
raise_error(
|
64
|
+
RSpec::Expectations::ExpectationNotMetError,
|
65
|
+
"expected action of class RespondToTestClassAction3 to respond to format :html on :invalid"
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should pass if the action responds to the given format for the given condition" do
|
70
|
+
action = RespondToTestClassAction3.new(controller)
|
71
|
+
expect { expect(action).to respond_to_format(:html).on(:ok) }.not_to raise_error
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'class_action/rspec'
|
3
|
+
|
4
|
+
describe ClassAction::RSpec::RespondWithMatcher do
|
5
|
+
|
6
|
+
class RespondWithTestClassAction1 < ClassAction::Action
|
7
|
+
end
|
8
|
+
class RespondWithTestClassAction2 < ClassAction::Action
|
9
|
+
respond_with :result
|
10
|
+
end
|
11
|
+
class RespondWithTestClassAction3 < ClassAction::Action
|
12
|
+
respond_with :result, on: :ok
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:controller) { ActionController::Base.new }
|
16
|
+
|
17
|
+
context "without a condition" do
|
18
|
+
|
19
|
+
it "should fail if the action does not have a response method" do
|
20
|
+
action = RespondWithTestClassAction1.new(controller)
|
21
|
+
expect { expect(action).to respond_with(:object) }.to \
|
22
|
+
raise_error(
|
23
|
+
RSpec::Expectations::ExpectationNotMetError,
|
24
|
+
"expected action of class RespondWithTestClassAction1 to respond with :object, but it has no response method"
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should fail if the action responds with a different method" do
|
29
|
+
action = RespondWithTestClassAction2.new(controller)
|
30
|
+
|
31
|
+
expect { expect(action).to respond_with(:object) }.to \
|
32
|
+
raise_error(
|
33
|
+
RSpec::Expectations::ExpectationNotMetError,
|
34
|
+
"expected action of class RespondWithTestClassAction2 to respond with :object, but it responds with :result"
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should pass if the action responded with the specified method" do
|
39
|
+
action = RespondWithTestClassAction2.new(controller)
|
40
|
+
expect { expect(action).to respond_with(:result) }.not_to raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should fail if the action does not have a generic response method" do
|
44
|
+
action = RespondWithTestClassAction3.new(controller)
|
45
|
+
expect { expect(action).to respond_with(:object) }.to \
|
46
|
+
raise_error(
|
47
|
+
RSpec::Expectations::ExpectationNotMetError,
|
48
|
+
"expected action of class RespondWithTestClassAction3 to respond with :object, but it has no response method"
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with a condition" do
|
55
|
+
|
56
|
+
it "should fail if the action responds with a different method for the given condition" do
|
57
|
+
action = RespondWithTestClassAction3.new(controller)
|
58
|
+
|
59
|
+
expect { expect(action).to respond_with(:object).on(:ok) }.to \
|
60
|
+
raise_error(
|
61
|
+
RSpec::Expectations::ExpectationNotMetError,
|
62
|
+
"expected action of class RespondWithTestClassAction3 to respond with :object on :ok, but it responds with :result"
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should fail if the action has no response method for the given condition" do
|
67
|
+
action = RespondWithTestClassAction1.new(controller)
|
68
|
+
|
69
|
+
expect { expect(action).to respond_with(:object).on(:ok) }.to \
|
70
|
+
raise_error(
|
71
|
+
RSpec::Expectations::ExpectationNotMetError,
|
72
|
+
"expected action of class RespondWithTestClassAction1 to respond with :object on :ok, but it has no response method"
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should pass if the action responded with the specified method" do
|
77
|
+
action = RespondWithTestClassAction3.new(controller)
|
78
|
+
expect { expect(action).to respond_with(:result).on(:ok) }.not_to raise_error
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
end
|
data/spec/class_action_spec.rb
CHANGED
@@ -59,6 +59,13 @@ describe ClassAction do
|
|
59
59
|
controller.show
|
60
60
|
expect(controller.view_assigns).not_to have_key('_class_action')
|
61
61
|
end
|
62
|
+
|
63
|
+
it "should expose the current action as #_class_action" do
|
64
|
+
controller.show
|
65
|
+
allow(controller).to receive(:action_name).and_return('show')
|
66
|
+
expect(controller.send(:_class_action)).to be(action)
|
67
|
+
end
|
68
|
+
|
62
69
|
end
|
63
70
|
|
64
71
|
context "giving another action class" do
|
@@ -153,7 +160,7 @@ describe ClassAction do
|
|
153
160
|
end
|
154
161
|
|
155
162
|
it "should leave everything alone if the class action has no responders" do
|
156
|
-
allow(ClassActionTestController::Show).to receive(:
|
163
|
+
allow(ClassActionTestController::Show).to receive(:_responders).and_return({})
|
157
164
|
|
158
165
|
ClassActionTestController.class_eval do
|
159
166
|
respond_to :json
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class-action
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joost Lubach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.14'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: actionpack
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,20 +102,28 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- .gitignore
|
91
|
-
- .
|
92
|
-
- .
|
93
|
-
- ClassAction.sublime-project
|
94
|
-
- ClassAction.sublime-workspace
|
105
|
+
- .travis.yml
|
106
|
+
- CHANGELOG.md
|
95
107
|
- Gemfile
|
108
|
+
- Gemfile.lock
|
96
109
|
- LICENSE.txt
|
97
110
|
- README.md
|
98
111
|
- Rakefile
|
99
112
|
- class-action.gemspec
|
100
113
|
- lib/class-action.rb
|
114
|
+
- lib/class-action/rspec.rb
|
101
115
|
- lib/class_action.rb
|
102
116
|
- lib/class_action/action.rb
|
117
|
+
- lib/class_action/rspec.rb
|
118
|
+
- lib/class_action/rspec/class_action_example_group.rb
|
119
|
+
- lib/class_action/rspec/have_class_action_matcher.rb
|
120
|
+
- lib/class_action/rspec/respond_to_format_matcher.rb
|
121
|
+
- lib/class_action/rspec/respond_with_matcher.rb
|
103
122
|
- lib/class_action/version.rb
|
104
123
|
- spec/class_action/action_spec.rb
|
124
|
+
- spec/class_action/rspec/have_class_action_matcher_spec.rb
|
125
|
+
- spec/class_action/rspec/respond_to_format_matcher_spec.rb
|
126
|
+
- spec/class_action/rspec/respond_with_matcher_spec.rb
|
105
127
|
- spec/class_action_spec.rb
|
106
128
|
- spec/spec_helper.rb
|
107
129
|
homepage: ''
|
@@ -124,12 +146,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
146
|
version: '0'
|
125
147
|
requirements: []
|
126
148
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.1.4
|
128
150
|
signing_key:
|
129
151
|
specification_version: 4
|
130
152
|
summary: Allows you to write controller actions as classes, rather than methods.
|
131
153
|
test_files:
|
132
154
|
- spec/class_action/action_spec.rb
|
155
|
+
- spec/class_action/rspec/have_class_action_matcher_spec.rb
|
156
|
+
- spec/class_action/rspec/respond_to_format_matcher_spec.rb
|
157
|
+
- spec/class_action/rspec/respond_with_matcher_spec.rb
|
133
158
|
- spec/class_action_spec.rb
|
134
159
|
- spec/spec_helper.rb
|
135
160
|
has_rdoc:
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
flux
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.0.0-p247
|
data/ClassAction.sublime-project
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"folders":
|
3
|
-
[
|
4
|
-
{
|
5
|
-
"path": "/Users/joost/Work/Flux/class-action",
|
6
|
-
"folder_exclude_patterns": [ "log", "tmp", "doc", ".yardoc", "tools", "coverage", ".zeus*" ],
|
7
|
-
"file_exclude_patterns": [ "*.sublime-workspace", "*.tmproj", "Gemfile.lock", ".*" ]
|
8
|
-
}
|
9
|
-
]
|
10
|
-
}
|