hexx 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +12 -1
  3. data/README.rdoc +11 -2
  4. data/Rakefile +6 -0
  5. data/lib/generators/controller/controller.rb +29 -7
  6. data/lib/generators/controller/templates/application_controller.erb +24 -0
  7. data/lib/generators/controller/templates/controller.erb +4 -8
  8. data/lib/generators/controller/templates/controller_action.erb +2 -2
  9. data/lib/generators/controller/templates/controller_action_spec.erb +13 -20
  10. data/lib/generators/controller/templates/controller_spec.erb +42 -29
  11. data/lib/generators/controller/templates/routing_action_spec.erb +9 -6
  12. data/lib/generators/controller/templates/routing_spec.erb +2 -1
  13. data/lib/generators/dependency/dependency.rb +18 -2
  14. data/lib/generators/dependency/templates/dependency_setting_spec.erb +12 -7
  15. data/lib/generators/dependency/templates/initializer.erb +4 -0
  16. data/lib/generators/dependency/templates/initializer_setting.erb +4 -0
  17. data/lib/generators/dependency/templates/module_spec.erb +5 -5
  18. data/lib/generators/domain/templates/spec.erb +4 -4
  19. data/lib/generators/install/install.rb +28 -14
  20. data/lib/generators/install/templates/CHANGELOG.erb +13 -1
  21. data/lib/generators/install/templates/Gemfile.erb +5 -1
  22. data/lib/generators/install/templates/Guardfile.erb +32 -0
  23. data/lib/generators/install/templates/README.erb +12 -6
  24. data/lib/generators/install/templates/Rakefile.erb +8 -2
  25. data/lib/generators/install/templates/coveralls.erb +1 -0
  26. data/lib/generators/install/templates/gemspec.erb +4 -0
  27. data/lib/generators/install/templates/gitignore.erb +28 -0
  28. data/lib/generators/install/templates/rspec.erb +1 -0
  29. data/lib/generators/install/templates/rubocop.erb +58 -0
  30. data/lib/generators/install/templates/spec/caching.erb +12 -0
  31. data/lib/generators/install/templates/spec/controllers.erb +14 -0
  32. data/lib/generators/install/templates/spec/database_cleaner.erb +1 -0
  33. data/lib/generators/install/templates/spec/json_shema.erb +10 -0
  34. data/lib/generators/install/templates/spec/rspec.erb +5 -0
  35. data/lib/generators/install/templates/travis.erb +3 -0
  36. data/lib/generators/request/templates/request_spec.erb +28 -24
  37. data/lib/generators/use_case/templates/use_case.erb +6 -5
  38. data/lib/generators/use_case/templates/use_case_spec.erb +10 -10
  39. data/lib/hexx/exceptions/not_found_error.rb +4 -0
  40. data/lib/hexx/exceptions/record_invalid.rb +5 -1
  41. data/lib/hexx/exceptions/use_case_invalid.rb +4 -0
  42. data/lib/hexx/models.rb +2 -0
  43. data/lib/hexx/use_case.rb +29 -1
  44. data/lib/hexx/version.rb +1 -1
  45. data/spec/hexx/exceptions/not_found_error_spec.rb +5 -15
  46. data/spec/hexx/exceptions/record_invalid_spec.rb +5 -15
  47. data/spec/hexx/exceptions/runtime_error_spec.rb +7 -13
  48. data/spec/hexx/exceptions/use_case_invalid_spec.rb +5 -15
  49. data/spec/hexx/models_spec.rb +20 -13
  50. data/spec/hexx/settings_spec.rb +3 -3
  51. data/spec/hexx/use_case_spec.rb +19 -1
  52. data/spec/spec_helper.rb +6 -0
  53. data/spec/support/exception_matchers.rb +20 -0
  54. metadata +50 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f14eb96fccf59e4cff2b528b7af4022bc1a06ba0
4
- data.tar.gz: 129481aec498d829b4cfefa8826342d3c2656f52
3
+ metadata.gz: e785de1749dfa0413059159c18f56b3249f057cf
4
+ data.tar.gz: 3d29b3bdcc0a0af55f7915a034872a35bd128409
5
5
  SHA512:
6
- metadata.gz: 33cda7123f07260c0c60b11e81d57fa2acdd15df6e3a918e21956f61564fbd76de750c263d82cdef7b324f757b369ab318ecc5137cf0220faf63d11d465c1da0
7
- data.tar.gz: 2f9fc12483c459cde61bb5581a74e3c126f92722d741d323160af374eeefda52bec304735721f7bee9ca8989fc7b6aebe14bc868964f41c5b8617324f46db203
6
+ metadata.gz: b3bb5ed74006254480995a7a7eb1a1f44c586d19dc3aadfa3d632556ff14e90098de4ea192b282550d109e3f43a0266a61918b4f9f068cd96658d8b2634c136f
7
+ data.tar.gz: 43298906942eaf319ad0a25d9bdb7a466dc22d0dcc45d68780cf4505213da94d70d1a9d67d47fe0aeef9a3a3b7bce9ed501b02b8a81580a8865fcdbf0d7e2332
data/CHANGELOG.rdoc CHANGED
@@ -1 +1,12 @@
1
- = CHANGELOG
1
+ = CHANGELOG
2
+
3
+ == 0.1.0 (28.09.2014)
4
+
5
+ === Changed features:
6
+
7
+ * `install` generator refactored for usage of json_schema in requests specs:
8
+ - `json_schema` matchers added to support
9
+ - `request` matchers removed from support
10
+ - `controllers` matchers refactored
11
+
12
+ * `controller` generator refactored
data/README.rdoc CHANGED
@@ -1,5 +1,6 @@
1
1
  = Hexx
2
2
 
3
+ {<img src="http://img.shields.io/gem/v/hexx.svg?style=flat" alt="Gem Version" />}[https://rubygems.org/gems/hexx]
3
4
  {<img src="http://img.shields.io/travis/nepalez/hexx.svg?style=flat" alt="Bild Status" />}[https://travis-ci.org/nepalez/hexx]
4
5
  {<img src="http://img.shields.io/codeclimate/github/nepalez/hexx.svg?style=flat" alt="Code Metrics" />}[https://codeclimate.com/github/nepalez/hexx]
5
6
  {<img src="http://img.shields.io/gemnasium/nepalez/hexx.svg?style=flat" alt="Dependency Status" />}[https://gemnasium.com/nepalez/hexx]
@@ -17,7 +18,15 @@ Provides:
17
18
 
18
19
  Add this line to your application's Gemfile:
19
20
 
20
- gem 'hexx', git: "https://github.com/nepalez/hexx.git"
21
+ gem "hexx"
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install hexx
21
30
 
22
31
  == Usage
23
32
 
@@ -69,7 +78,7 @@ In a typical case the controller should constist from:
69
78
  # An action (outer port) of the controller
70
79
  def show
71
80
  use_case = GetItem.new params.allow(:id)
72
- # subscribes the controller for listening for the use case
81
+ # subscribes the controller for listening to the use case
73
82
  # notifications via the controller's inner ports.
74
83
  use_case.subscribe self
75
84
  use_case.run
data/Rakefile CHANGED
@@ -29,3 +29,9 @@ RSpec::Core::RakeTask.new(:spec)
29
29
  task :default do
30
30
  sh "bundle exec rspec spec"
31
31
  end
32
+
33
+ task full: [:default] do
34
+ sh "rubocop"
35
+ sh "metric_fu"
36
+ sh "inch"
37
+ end
@@ -16,7 +16,7 @@ module Hexx
16
16
  def create_routing_spec
17
17
  template(
18
18
  "routing_spec.erb",
19
- "spec/routing/#{ api_path }/#{ file_name }_routing_spec.rb",
19
+ "spec/routing/#{api_path}/#{file_name}_routing_spec.rb",
20
20
  skip: true
21
21
  )
22
22
  end
@@ -24,7 +24,7 @@ module Hexx
24
24
  def add_route_spec
25
25
  inject_template_into_file(
26
26
  "routing_action_spec.erb",
27
- "spec/routing/#{ api_path }/#{ file_name }_routing_spec.rb",
27
+ "spec/routing/#{api_path}/#{file_name}_routing_spec.rb",
28
28
  before: " end\nend"
29
29
  )
30
30
  end
@@ -32,7 +32,7 @@ module Hexx
32
32
  def create_controller_spec
33
33
  template(
34
34
  "controller_spec.erb",
35
- "spec/controllers/#{ api_path }/#{ file_name }_controller_spec.rb",
35
+ "spec/controllers/#{api_path}/#{file_name}_controller_spec.rb",
36
36
  skip: true
37
37
  )
38
38
  end
@@ -40,15 +40,23 @@ module Hexx
40
40
  def add_controller_action_spec
41
41
  inject_template_into_file(
42
42
  "controller_action_spec.erb",
43
- "spec/controllers/#{ api_path }/#{ file_name }_controller_spec.rb",
43
+ "spec/controllers/#{api_path}/#{file_name}_controller_spec.rb",
44
44
  after: "describe \"action\" do"
45
45
  )
46
46
  end
47
47
 
48
+ def create_application_controller
49
+ template(
50
+ "application_controller.erb",
51
+ "app/controllers/#{api_path}/application_controller.rb",
52
+ skip: true
53
+ )
54
+ end
55
+
48
56
  def create_controller
49
57
  template(
50
58
  "controller.erb",
51
- "app/controllers/#{ api_path }/#{ file_name }_controller.rb",
59
+ "app/controllers/#{api_path}/#{file_name}_controller.rb",
52
60
  skip: true
53
61
  )
54
62
  end
@@ -56,8 +64,22 @@ module Hexx
56
64
  def add_controller_action
57
65
  inject_template_into_file(
58
66
  "controller_action.erb",
59
- "app/controllers/#{ api_path }/#{ file_name }_controller.rb",
60
- after: " < ActionController"
67
+ "app/controllers/#{api_path}/#{file_name}_controller.rb",
68
+ after: " < ApplicationController"
69
+ )
70
+ end
71
+
72
+ def create_application_layout
73
+ create_file(
74
+ "app/views/layouts/#{api_path}/application.json.jbuilder",
75
+ skip: true
76
+ )
77
+ end
78
+
79
+ def create_view
80
+ create_file(
81
+ "app/views/#{api_path}/#{file_name}/#{action_name}.json.jbuilder",
82
+ skip: true
61
83
  )
62
84
  end
63
85
 
@@ -0,0 +1,24 @@
1
+ module <%= module_name %>
2
+ module Api
3
+ module V1
4
+
5
+ # Base controller for the API
6
+ # Collects standard method for responding to users.
7
+ class ApplicationController < ::ApplicationController
8
+
9
+ # def on_error(messages, status: 400)
10
+ # @messages = messages
11
+ # render template: "<%= gem_name %>/api/v1/shared/error", status: status
12
+ # end
13
+
14
+ # def on_not_found(messages)
15
+ # on_error messages, status: 404
16
+ # end
17
+
18
+ # def on_not_changed
19
+ # render status: 304
20
+ # end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -3,15 +3,11 @@ module <%= module_name %>
3
3
  module V1
4
4
 
5
5
  # TODO: add a description
6
- controller <%= class_name %>Controller < ActionController
6
+ class <%= class_name %>Controller < ApplicationController
7
7
 
8
- # def not_found(messages)
9
- # render json: { success: false, messages: messages }, status: 404
10
- # end
11
-
12
- # def error(messages)
13
- # render json: { success: false, messages: messages }, status: 422
14
- # end
8
+ # ======================================================================
9
+ # Inner ports (to be called by use cases)
10
+ # ======================================================================
15
11
  end
16
12
  end
17
13
  end
@@ -1,8 +1,8 @@
1
1
 
2
-
2
+
3
3
  # TODO: add a description
4
4
  # def <%= action_name %>
5
5
  # use_case = <%= use_case %>.new params.permit(:something)
6
- # use_case.subscribe self
6
+ # use_case.subscribe self, prefix: :on
7
7
  # use_case.run
8
8
  # end
@@ -1,28 +1,21 @@
1
1
 
2
2
 
3
3
  # describe "#<%= action_name %>" do
4
- #
5
- # let!(:params) { { "something" => something } }
6
- # let!(:use_case_class) { <%= use_case %> }
7
- #
8
- # before { allow(use_case_class).to receive(:new) { use_case } }
4
+
5
+ # let!(:params) { { "something" => "something", "wrong" => "wrong" } }
6
+
7
+ # before { allow(<%= use_case %>).to receive(:new).and_return(use_case) }
9
8
  # after { <%= action_type %> :<%= action_name %>, params }
10
- #
11
- # it "initializes a proper use case with allowed parameters" do
12
- # expect(use_case_class).to receive(:new) do |options|
13
- # expect(options).to eq params.
14
- # slice %w(something)
15
- # end
9
+
10
+ # it "provides a use case with proper parameters" do
11
+ # expect(<%= use_case %>).to receive(:new).with(params.slice("something"))
16
12
  # end
17
- #
18
- # it "listens to use case notifications" do
19
- # expect(use_case).to receive(:subscribe) do |listener|
20
- # expect(listener).to eq controller
21
- # end
13
+
14
+ # it "listens to use case" do
15
+ # expect(controller).to listen_to use_case
22
16
  # end
23
- #
24
- # it "runs the case after all subscribtion" do
25
- # expect(use_case).to receive(:subscribe).exactly(1).times.order
26
- # expect(use_case).to receive(:run).order
17
+
18
+ # it "runs the case after subscribtion" do
19
+ # expect(use_case).to run_after_subscription
27
20
  # end
28
21
  # end
@@ -1,48 +1,61 @@
1
1
  require "spec_helper"
2
+ require "support/matchers/controllers"
2
3
 
3
4
  module <%= module_name %>
4
5
  module Api
5
6
  module V1
6
- describe <%= class_name %>Controller
7
- # Add this string if your project is a Rails Engine, not the Application
7
+ describe <%= class_name %>Controller do
8
+
9
+ # Add this line if your project is a Rails Engine, not the Application
8
10
  # routes { <%= module_name %>::Engine.routes }
9
11
 
10
- # let!(:use_case) { double "use_case" }
12
+ # let(:use_case) { double "use_case" }
13
+
11
14
  # before do
12
- # allow(use_case).to receive(:run){ controller.render inline: "" }
15
+ # allow(use_case).to receive(:run) { controller.render inline: "" }
16
+ # allow(use_case).to receive(:subscribe)
13
17
  # end
14
18
 
15
19
  describe "action" do
16
20
  end
17
21
 
18
- describe "listener" do
19
-
20
- # let!(:messages) { ["message"] }
21
- # let!(:item) { { id: 1, name: "name" } }
22
-
23
- # describe "#not_found" do
24
- #
25
- # it "renders a correct json" do
26
- # expect(controller).to receive(:render) do |options|
27
- # expect(options[:json]).to eq {
28
- # something: something
29
- # }
30
- # expect(options[:status]).to eq 404
31
- # end
32
- # controller.not_found(messages)
22
+ describe "responder" do
23
+
24
+ # describe "#on_error" do
25
+
26
+ # controller(<%= class_name %>Controller) { def index; on_error :messages; end }
27
+ # before { get :index, format: :json }
28
+
29
+ # it "sets @messages" do
30
+ # expect(assigns(:messages)).to eq :messages
31
+ # end
32
+
33
+ # it "renders a proper template" do
34
+ # expect(response)
35
+ # .to render_template "<%= gem_name %>/api/v1/shared/error"
36
+ # end
37
+
38
+ # it "returns status 400" do
39
+ # expect(response.status).to eq 400
33
40
  # end
34
41
  # end
35
42
 
36
- # describe "#error" do
37
- #
38
- # it "renders a correct json" do
39
- # expect(controller).to receive(:render) do |options|
40
- # expect(options[:json]).to eq {
41
- # something: something
42
- # }
43
- # expect(options[:status]).to eq 422
44
- # end
45
- # controller.error(messages)
43
+ # describe "#on_not_found" do
44
+
45
+ # controller(<%= class_name %>Controller) { def index; on_not_found :messages; end }
46
+ # before { get :index, format: :json }
47
+
48
+ # it "sets @messages" do
49
+ # expect(assigns(:messages)).to eq :messages
50
+ # end
51
+
52
+ # it "renders a proper template" do
53
+ # expect(response)
54
+ # .to render_template "<%= gem_name %>/api/v1/shared/error"
55
+ # end
56
+
57
+ # it "returns status 404" do
58
+ # expect(response.status).to eq 404
46
59
  # end
47
60
  # end
48
61
  end
@@ -1,10 +1,13 @@
1
1
 
2
2
  # describe "#<%= action_name %>" do
3
- #
4
- # let!(:action) {{ controller: "<%= gem_name %>/#{ root }", action: "<%= action_name %>" }}
5
- #
6
- # it "is routable in a json format" do
7
- # action[:format] = "json"
8
- # expect(<%= action_type %>: "/#{ root }/something").to route_to action
3
+
4
+ # let(:action) do
5
+ # { controller: "<%= gem_name %>/#{ root }", action: "<%= action_name %>" }
6
+ # end
7
+
8
+ # subject(:request) { { <%= action_type %>: "/#{ root }/something" } }
9
+
10
+ # it "is routable in json" do
11
+ # expect(request).to route_to action.merge(format: "json")
9
12
  # end
10
13
  # end
@@ -2,9 +2,10 @@ require "spec_helper"
2
2
 
3
3
  module <%= module_name %>
4
4
  describe "<%= file_name %>" do
5
+
5
6
  # Add this line if your project is a Rails engine, not the application:
6
7
  # routes { <%= module_name %>::Engine.routes }
7
8
 
8
- # let!(:root) { "api/v1/<%= file_name %>" }
9
+ # let(:root) { "api/v1/<%= file_name %>" }
9
10
  end
10
11
  end
@@ -11,13 +11,13 @@ module Hexx
11
11
  end
12
12
 
13
13
  def add_spec
14
- template "module_spec.erb", "spec/#{ gem_name }_spec.rb", skip: true
14
+ template "module_spec.erb", "spec/lib/#{ gem_name }_spec.rb", skip: true
15
15
  end
16
16
 
17
17
  def insert_setting_spec
18
18
  inject_template_into_file(
19
19
  "dependency_setting_spec.erb",
20
- "spec/#{ gem_name }_spec.rb",
20
+ "spec/lib/#{ gem_name }_spec.rb",
21
21
  before: "\nend"
22
22
  )
23
23
  end
@@ -29,6 +29,22 @@ module Hexx
29
29
  before: "\nend"
30
30
  )
31
31
  end
32
+
33
+ def add_initializer
34
+ template(
35
+ "initializer.erb",
36
+ "spec/dummy/config/initializers/#{ gem_name }.rb",
37
+ skip: true
38
+ )
39
+ end
40
+
41
+ def insert_initializer_setting
42
+ inject_template_into_file(
43
+ "initializer_setting.erb",
44
+ "spec/dummy/config/initializers/#{ gem_name }.rb",
45
+ after: " do |config|"
46
+ )
47
+ end
32
48
  end
33
49
  end
34
50
  end
@@ -1,32 +1,37 @@
1
1
 
2
2
 
3
3
  # describe ".<%= file_name %>_name" do
4
- #
4
+
5
5
  # it "is public" do
6
6
  # expect(subject).to respond_to(:<%= file_name %>_name).with(0).arguments
7
7
  # end
8
8
  # end
9
9
 
10
10
  # describe ".<%= file_name %>" do
11
- #
11
+
12
12
  # it "is public" do
13
13
  # expect(subject).to respond_to(:<%= file_name %>).with(0).arguments
14
14
  # end
15
15
  # end
16
16
 
17
17
  # describe ".<%= file_name %>_name=" do
18
- #
19
- # after { subject.<%= file_name %>_name = nil }
20
- #
18
+
19
+ # around do |example|
20
+ # restore = subject.<%= file_name %>_name
21
+ # subject.<%= file_name %>_name = nil
22
+ # example.run
23
+ # subject.<%= file_name %>_name = restore
24
+ # end
25
+
21
26
  # it "is public" do
22
27
  # expect(subject).to respond_to(:<%= file_name %>_name=).with(1).argument
23
28
  # end
24
- #
29
+
25
30
  # it "sets a <%= file_name %>_name" do
26
31
  # expect { subject.<%= file_name %>_name = "TestClass" }
27
32
  # .to change { subject.<%= file_name %>_name }.from(nil).to "TestClass"
28
33
  # end
29
- #
34
+
30
35
  # it "sets a <%= file_name %>" do
31
36
  # expect { subject.<%= file_name %>_name = "TestClass" }
32
37
  # .to change { subject.<%= file_name %> }.from(nil).to TestClass