hexx 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e785de1749dfa0413059159c18f56b3249f057cf
4
- data.tar.gz: 3d29b3bdcc0a0af55f7915a034872a35bd128409
3
+ metadata.gz: 328ff58d93538e10c8f80618deaf8c4e640f8ecf
4
+ data.tar.gz: 6b3957ae87b7f0dd01da5f5213acf9567df9e076
5
5
  SHA512:
6
- metadata.gz: b3bb5ed74006254480995a7a7eb1a1f44c586d19dc3aadfa3d632556ff14e90098de4ea192b282550d109e3f43a0266a61918b4f9f068cd96658d8b2634c136f
7
- data.tar.gz: 43298906942eaf319ad0a25d9bdb7a466dc22d0dcc45d68780cf4505213da94d70d1a9d67d47fe0aeef9a3a3b7bce9ed501b02b8a81580a8865fcdbf0d7e2332
6
+ metadata.gz: 24bedd30a43978ea114d5acff719bdb8416ff1ba0cdacfe75ca722163d67e4560dcfab4841a2965227626f182c15c4d0973a33efb87678bd35eb74e29772c0ba
7
+ data.tar.gz: 194270afa308dfdae9648aec04055b8ae99d539fc203df8efe83cd000662cc86a631cf353a73b03c93de9c3fb447c0d3881d0712495e6f50b89bfa289b8951c3
@@ -45,10 +45,10 @@ module Hexx
45
45
  )
46
46
  end
47
47
 
48
- def create_application_controller
48
+ def create_responder
49
49
  template(
50
- "application_controller.erb",
51
- "app/controllers/#{api_path}/application_controller.rb",
50
+ "responder.erb",
51
+ "app/controllers/#{api_path}/responder.rb",
52
52
  skip: true
53
53
  )
54
54
  end
@@ -65,7 +65,7 @@ module Hexx
65
65
  inject_template_into_file(
66
66
  "controller_action.erb",
67
67
  "app/controllers/#{api_path}/#{file_name}_controller.rb",
68
- after: " < ApplicationController"
68
+ after: " < Responder"
69
69
  )
70
70
  end
71
71
 
@@ -3,7 +3,7 @@ module <%= module_name %>
3
3
  module V1
4
4
 
5
5
  # TODO: add a description
6
- class <%= class_name %>Controller < ApplicationController
6
+ class <%= class_name %>Controller < Responder
7
7
 
8
8
  # ======================================================================
9
9
  # Inner ports (to be called by use cases)
@@ -7,15 +7,16 @@
7
7
  # before { allow(<%= use_case %>).to receive(:new).and_return(use_case) }
8
8
  # after { <%= action_type %> :<%= action_name %>, params }
9
9
 
10
- # it "provides a use case with proper parameters" do
11
- # expect(<%= use_case %>).to receive(:new).with(params.slice("something"))
10
+ # it "sets use case with proper parameters" do
11
+ # expect(<%= use_case %>).to receive(:new)
12
+ # .with params.slice("something")
12
13
  # end
13
14
 
14
- # it "listens to use case" do
15
+ # it "listens to the case" do
15
16
  # expect(controller).to listen_to use_case
16
17
  # end
17
18
 
18
- # it "runs the case after subscribtion" do
19
- # expect(use_case).to run_after_subscription
19
+ # it "runs the case after subscribtions" do
20
+ # expect(use_case).to run_after_subscriptions
20
21
  # end
21
22
  # end
@@ -1,5 +1,4 @@
1
1
  require "spec_helper"
2
- require "support/matchers/controllers"
3
2
 
4
3
  module <%= module_name %>
5
4
  module Api
@@ -12,8 +11,8 @@ module <%= module_name %>
12
11
  # let(:use_case) { double "use_case" }
13
12
 
14
13
  # before do
15
- # allow(use_case).to receive(:run) { controller.render inline: "" }
16
14
  # allow(use_case).to receive(:subscribe)
15
+ # allow(use_case).to receive(:run) { controller.render inline: "" }
17
16
  # end
18
17
 
19
18
  describe "action" do
@@ -30,12 +29,12 @@ module <%= module_name %>
30
29
  # expect(assigns(:messages)).to eq :messages
31
30
  # end
32
31
 
33
- # it "renders a proper template" do
32
+ # it "renders 'error'" do
34
33
  # expect(response)
35
34
  # .to render_template "<%= gem_name %>/api/v1/shared/error"
36
35
  # end
37
36
 
38
- # it "returns status 400" do
37
+ # it "responds with 400" do
39
38
  # expect(response.status).to eq 400
40
39
  # end
41
40
  # end
@@ -49,12 +48,12 @@ module <%= module_name %>
49
48
  # expect(assigns(:messages)).to eq :messages
50
49
  # end
51
50
 
52
- # it "renders a proper template" do
51
+ # it "renders 'error'" do
53
52
  # expect(response)
54
53
  # .to render_template "<%= gem_name %>/api/v1/shared/error"
55
54
  # end
56
55
 
57
- # it "returns status 404" do
56
+ # it "responds with 404" do
58
57
  # expect(response.status).to eq 404
59
58
  # end
60
59
  # end
@@ -2,9 +2,8 @@ module <%= module_name %>
2
2
  module Api
3
3
  module V1
4
4
 
5
- # Base controller for the API
6
- # Collects standard method for responding to users.
7
- class ApplicationController < ::ApplicationController
5
+ # Responds to the client depending of use case result.
6
+ class Responder < ::ApplicationController
8
7
 
9
8
  # def on_error(messages, status: 400)
10
9
  # @messages = messages
@@ -68,7 +68,7 @@ module Hexx
68
68
  end
69
69
 
70
70
  def add_json_schemas_path
71
- run "mkdir spec/json_schemas"
71
+ run "mkdir spec/examples/json_schemas"
72
72
  end
73
73
 
74
74
  def add_services
@@ -115,7 +115,7 @@ module Hexx
115
115
 
116
116
  def initializers
117
117
  %w(
118
- caching coveralls database_cleaner factory_girl factory_girl_rails
118
+ caching coveralls database_cleaner factory_girl_rails
119
119
  focus garbage_collection i18n migrations rails random_order rspec
120
120
  timecop
121
121
  )
@@ -30,6 +30,7 @@ require "rspec/core/rake_task"
30
30
 
31
31
  RSpec::Core::RakeTask.new :spec
32
32
  task :default do
33
+ sh "bundle exec rake db:migrate RAILS_ENV=test"
33
34
  sh "bundle exec rspec spec"
34
35
  end
35
36
 
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "database_cleaner"
25
25
  s.add_development_dependency "factory_girl_rails"
26
26
  s.add_development_dependency "inch"
27
- s.add_development_dependency "json_schema"
27
+ s.add_development_dependency "json-schema"
28
28
  s.add_development_dependency "metric_fu"
29
29
  s.add_development_dependency "rspec-rails"
30
30
  s.add_development_dependency "rubocop"
@@ -3,7 +3,7 @@ require "json_schema"
3
3
 
4
4
  RSpec::Matchers.define :match_json_schema do |schema|
5
5
  match do |response|
6
- schema_directory = "#{Dir.pwd}/spec/support/json_schemas"
6
+ schema_directory = "#{Dir.pwd}/spec/support/examples/json_schemas"
7
7
  schema_path = "#{schema_directory}/#{schema}.json"
8
8
  JSON::Validator.validate!(schema_path, response, strict: true)
9
9
  end
@@ -31,12 +31,12 @@ module Hexx
31
31
 
32
32
  # full_path: "items/{id}"
33
33
  def full_name
34
- @full_name ||= parts[1]
34
+ @full_name ||= parts[1].to_s
35
35
  end
36
36
 
37
37
  # type of action: "get"
38
38
  def action_type
39
- @action_type ||= parts[0]
39
+ @action_type ||= parts[0].to_s
40
40
  end
41
41
 
42
42
  # path from the request: get:items/{id} => ["get", "items/{id}"]
@@ -1,76 +1,65 @@
1
1
  require "spec_helper"
2
- require "support/matchers/requests"
3
2
 
4
3
  module <%= module_name %>
5
4
  describe "<%= action_type.upcase %> api/v1/<%= full_name %>" do
6
5
 
7
6
  # ==========================================================================
8
- # Prepare environment
7
+ # Prepare context
9
8
  # ==========================================================================
10
9
 
11
- # before { Timecop.freeze }
12
- # after { Timecop.return }
13
-
14
10
  # let!(:something) { something }
15
11
 
16
12
  # ==========================================================================
17
13
  # Prepare variables
18
14
  # ==========================================================================
19
15
 
20
- # let!(:params) { { something: something } }
16
+ # let!(:params) { { "something" => something } }
21
17
 
22
18
  # def call_request(params)
23
19
  # <%= action_type %> "<%= gem_name %>/api/v1/<%= escaped_name %>", params
24
20
  # end
25
21
 
26
- # let!(:expected_data) do
27
- # {
28
- # something: something
29
- # }
30
- # end
31
-
32
- # def check_data(id)
33
- # get "<%= gem_name %>/api/v1/<%= escaped_name %>"
34
- # JSON.parse(response.body)["data"]
35
- # end
36
-
37
22
  # ==========================================================================
38
23
  # Run tests
39
24
  # ==========================================================================
40
25
 
41
26
  # context "with proper params" do
42
27
 
43
- # before { call_request params }
44
- # let(:json) { JSON.parse(response.body) }
28
+ # before { call_request params }
45
29
 
46
- # it "receives http response 200" do
30
+ # it "changes something" do
31
+ # expect (something).to eq something
32
+ # end
33
+
34
+ # it "responds with 200" do
47
35
  # expect(response.status).to eq 200
48
36
  # end
49
37
 
50
- # it "receives a proper json response" do
51
- # expect(json["success"]).to eq true
52
- # expect(json["messages"]).not_to be_blank
53
- # expect(json["data"]).to eq check_data(id)
38
+ # it "receives proper json" do
39
+ # expect(response.body).to match_json_schema(:something)
54
40
  # end
55
41
 
56
- # it "changes something" do
57
- # data = check_data(id)
58
- # expect(data["something"]).to eq params[:something]
42
+ # it "receives something" do
43
+ # something = JSON.parse(response.body)["something"]
44
+ # expect(something).to eq something
59
45
  # end
60
46
  # end
61
47
 
62
- # context "with improper params" do
48
+ # context "with wrong params" do
63
49
  #
64
- # before { params[:something] = something }
65
- # before { call_request params }
50
+ # before { params["something"] = something }
51
+ # before { call_request params }
52
+
53
+ # it "doesn't change something" do
54
+ # expect (something).to eq something
55
+ # end
66
56
 
67
- # it "reports error 400" do
68
- # expect(response).to report_error 400
57
+ # it "responds with 400" do
58
+ # expect(response.status).to eq 400
69
59
  # end
70
60
 
71
- # it "doesn't change something" do
72
- # data = check_data(id)
73
- # expect(data["something"]).not_to eq params[:something]
61
+ # it "receives proper json" do
62
+ # expect(response.body).to match_json_schema(:get_errors)
74
63
  # end
75
64
  # end
76
65
  end
@@ -4,7 +4,7 @@ module <%= module_name %>
4
4
  describe <%= class_name %> do
5
5
 
6
6
  # ==========================================================================
7
- # Prepare environment
7
+ # Prepare context
8
8
  # ==========================================================================
9
9
 
10
10
  # let!(:something) { create :something }
@@ -13,9 +13,8 @@ module <%= module_name %>
13
13
  # Prepare variables
14
14
  # ==========================================================================
15
15
 
16
- # let!(:params) { { key: value } }
17
- # let!(:expected_result) { something }
18
- # let(:listener) { double "listener" }
16
+ # let!(:params) { { key: value } }
17
+ # let(:listener) { double "listener" }
19
18
 
20
19
  # def prepare_case(params)
21
20
  # use_case = <%= class_name %>.new params
@@ -34,8 +33,7 @@ module <%= module_name %>
34
33
  # subject(:use_case) { prepare_case params }
35
34
 
36
35
  # it "does something" do
37
- # expect { use_case.run }.to change { something }
38
- # .from(something).to(something)
36
+ # expect { use_case.run }.to change { something }.to(something)
39
37
  # end
40
38
 
41
39
  # it "returns something" do
@@ -58,7 +56,6 @@ module <%= module_name %>
58
56
 
59
57
  # it "doesn't do something" do
60
58
  # expect { use_case.run }.not_to change { something }
61
- # .from something
62
59
  # end
63
60
 
64
61
  # it "returns nil" do
@@ -0,0 +1,20 @@
1
+ module Hexx
2
+
3
+ # A message to be returned by use_case
4
+ class Message
5
+
6
+ attr_reader :type, :text
7
+
8
+ def initialize(type:, text:)
9
+ @type, @text = type.to_s, text.to_s
10
+ end
11
+
12
+ def type=(value)
13
+ @type = value.to_s
14
+ end
15
+
16
+ def text=(value)
17
+ @text = value.to_s
18
+ end
19
+ end
20
+ end
@@ -220,7 +220,7 @@ module Hexx
220
220
  # notifications to listeners.
221
221
  #
222
222
  # Expected to be called from a controller action.
223
- #
223
+ #
224
224
  def run
225
225
  run!
226
226
  rescue Hexx::NotFoundError => error
@@ -242,8 +242,8 @@ module Hexx
242
242
  fail UseCaseInvalid.new(self)
243
243
  end
244
244
 
245
- def finish_with(name, arg)
246
- publish name, arg
245
+ def finish_with(name, errors)
246
+ publish name, errors.map { |text| Message.new type: :error, text: text }
247
247
  nil
248
248
  end
249
249
 
@@ -1,4 +1,4 @@
1
1
  # Core classes to follow hexagonal domain architecture.
2
2
  module Hexx
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
@@ -0,0 +1,31 @@
1
+ module Hexx
2
+ describe Message do
3
+
4
+ let!(:message) { Message.new type: "info", text: "" }
5
+
6
+ describe ".new" do
7
+
8
+ it "requires type" do
9
+ expect { Message.new text: "" }.to raise_error
10
+ end
11
+
12
+ it "requires text" do
13
+ expect { Message.new type: "" }.to raise_error
14
+ end
15
+ end
16
+
17
+ describe "#type=" do
18
+
19
+ it "sets the type" do
20
+ expect { message.type = :error }.to change { message.type }.to "error"
21
+ end
22
+ end
23
+
24
+ describe "#text=" do
25
+
26
+ it "sets the text" do
27
+ expect { message.text = "Text" }.to change { message.text }.to "Text"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -166,7 +166,8 @@ module Hexx
166
166
 
167
167
  it "publishes the :not_found notification" do
168
168
  expect(listener).to receive(:not_found) do |messages|
169
- expect(messages).to eq errors.values
169
+ expect(messages.map(&:type)).to eq ["error"]
170
+ expect(messages.map(&:text)).to eq ["invalid"]
170
171
  end
171
172
  use_case.run
172
173
  end
@@ -188,7 +189,8 @@ module Hexx
188
189
 
189
190
  it "publishes the :error notification" do
190
191
  expect(listener).to receive(:error) do |messages|
191
- expect(messages).to eq errors.values
192
+ expect(messages.map(&:type)).to eq ["error"]
193
+ expect(messages.map(&:text)).to eq ["invalid"]
192
194
  end
193
195
  use_case.run
194
196
  end
@@ -209,8 +211,9 @@ module Hexx
209
211
  end
210
212
 
211
213
  it "publishes the :error notification" do
212
- expect(listener).to receive(:error) do |arg|
213
- expect(arg).to eq ["StandardError"]
214
+ expect(listener).to receive(:error) do |messages|
215
+ expect(messages.map(&:type)).to eq ["error"]
216
+ expect(messages.map(&:text)).to eq ["StandardError"]
214
217
  end
215
218
  use_case.run
216
219
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-28 00:00:00.000000000 Z
11
+ date: 2014-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -155,11 +155,11 @@ files:
155
155
  - bin/hexx
156
156
  - lib/generators/base.rb
157
157
  - lib/generators/controller/controller.rb
158
- - lib/generators/controller/templates/application_controller.erb
159
158
  - lib/generators/controller/templates/controller.erb
160
159
  - lib/generators/controller/templates/controller_action.erb
161
160
  - lib/generators/controller/templates/controller_action_spec.erb
162
161
  - lib/generators/controller/templates/controller_spec.erb
162
+ - lib/generators/controller/templates/responder.erb
163
163
  - lib/generators/controller/templates/routing_action_spec.erb
164
164
  - lib/generators/controller/templates/routing_spec.erb
165
165
  - lib/generators/dependency/dependency.rb
@@ -191,12 +191,11 @@ files:
191
191
  - lib/generators/install/templates/spec/controllers.erb
192
192
  - lib/generators/install/templates/spec/coveralls.erb
193
193
  - lib/generators/install/templates/spec/database_cleaner.erb
194
- - lib/generators/install/templates/spec/factory_girl.erb
195
194
  - lib/generators/install/templates/spec/factory_girl_rails.erb
196
195
  - lib/generators/install/templates/spec/focus.erb
197
196
  - lib/generators/install/templates/spec/garbage_collection.erb
198
197
  - lib/generators/install/templates/spec/i18n.erb
199
- - lib/generators/install/templates/spec/json_shema.erb
198
+ - lib/generators/install/templates/spec/json_schema.erb
200
199
  - lib/generators/install/templates/spec/migrations.erb
201
200
  - lib/generators/install/templates/spec/rails.erb
202
201
  - lib/generators/install/templates/spec/random_order.erb
@@ -214,6 +213,7 @@ files:
214
213
  - lib/hexx/exceptions/record_invalid.rb
215
214
  - lib/hexx/exceptions/runtime_error.rb
216
215
  - lib/hexx/exceptions/use_case_invalid.rb
216
+ - lib/hexx/message.rb
217
217
  - lib/hexx/models.rb
218
218
  - lib/hexx/settings.rb
219
219
  - lib/hexx/use_case.rb
@@ -222,6 +222,7 @@ files:
222
222
  - spec/hexx/exceptions/record_invalid_spec.rb
223
223
  - spec/hexx/exceptions/runtime_error_spec.rb
224
224
  - spec/hexx/exceptions/use_case_invalid_spec.rb
225
+ - spec/hexx/message_spec.rb
225
226
  - spec/hexx/models_spec.rb
226
227
  - spec/hexx/settings_spec.rb
227
228
  - spec/hexx/use_case_spec.rb
@@ -259,6 +260,7 @@ specification_version: 4
259
260
  summary: UseCase part of a Hexx framework.
260
261
  test_files:
261
262
  - spec/spec_helper.rb
263
+ - spec/hexx/message_spec.rb
262
264
  - spec/hexx/settings_spec.rb
263
265
  - spec/hexx/exceptions/record_invalid_spec.rb
264
266
  - spec/hexx/exceptions/not_found_error_spec.rb
@@ -1,6 +0,0 @@
1
- # Add factory girl syntax
2
- require "factory_girl"
3
-
4
- RSpec.configure do |config|
5
- config.include FactoryGirl::Syntax::Methods
6
- end