organism-generators 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
  SHA256:
3
- metadata.gz: 2c2ab838d78d3a2b059712f53e60a61947b8c49b0ea70f7b380cedf87b8b6767
4
- data.tar.gz: c9bc7b056f4f6b2865aa51511680b4ba1d5abc4ee621451eaac8dd86a675696d
3
+ metadata.gz: bd942f651568b859542a8de9a624c6178b9ec86ba7326b3434dd4e02bd7234b9
4
+ data.tar.gz: 752ad642497467a444bdc24f15b13f682122bf7ecfc0b0a03102195e521aeec3
5
5
  SHA512:
6
- metadata.gz: 38f8811f1f517286b15f5afc156459cc937a96b0710c6da2f65e3619642f42ef2fb33ca098df1db3f3fa538119c5fabff02b00e7c092ff15fb9d8d5919b2227f
7
- data.tar.gz: 9b1f94d49da3c3538b1771081c75d0eb42637f1f7ee9b714d3f72d19d36dacecb5b8f165ed3c0e5ea869464ca8edba8322fb8a983e9f2a65815cdf123a19157d
6
+ metadata.gz: 9463ab6b2b3205460827b4222c161bb686ffafab86af71d7d96a35e58d6b6120475c26f740a5dcc8d56843df77dab2eb2ce37db161ebc7c182eae7c883520f3c
7
+ data.tar.gz: bf09c5a135bf1b4c9e7106be8e781ca826600178e3984c2804c95d52a4ed724aae0fcf46685ad6fc21cdf377536a1e55900ca4911d35038e869c69b782919a95
@@ -9,6 +9,7 @@ module Organism
9
9
  def create_cells
10
10
  cells.each do |cell|
11
11
  create_cell(cell)
12
+ create_cell_spec(cell) if %w[cell form list table].include?(cell)
12
13
 
13
14
  next if cell == 'list'
14
15
  next if cell == 'table'
@@ -38,10 +39,24 @@ module Organism
38
39
  )
39
40
  end
40
41
 
42
+ def create_cell_spec(type)
43
+ template(
44
+ "#{type}/spec.rb",
45
+ File.join('spec/cells', singular_file_path, "#{type}_spec.rb")
46
+ )
47
+ end
48
+
41
49
  def singular_file_path
42
50
  model_class_path.join('/')
43
51
  end
44
52
 
53
+ def cell_actions
54
+ [].tap do |array|
55
+ array << 'list' if list?
56
+ array << 'show' if show?
57
+ end
58
+ end
59
+
45
60
  def cells
46
61
  [].tap do |array|
47
62
  array << 'form' if form?
@@ -0,0 +1,22 @@
1
+ describe <%= namespaced_model_class %>::Cell, type: :cell do
2
+ controller ApplicationController
3
+ let(:result) { Capybara::Node::Simple.new(html) }
4
+ let(:model) do
5
+ <%= namespaced_model_class %>.new(id: 1)
6
+ end
7
+ <% cell_actions.map do |action| -%>
8
+
9
+ context '#<%= action %>' do
10
+ let(:html) do
11
+ cell(
12
+ described_class,
13
+ model,
14
+ ).(:<%= action %>)
15
+ end
16
+
17
+ it 'renders the <%= action %> action without error' do
18
+ expect(result).to have_xpath '//article'
19
+ end
20
+ end
21
+ <% end -%>
22
+ end
@@ -1,4 +1,4 @@
1
- <%%= simple_form_for model, as: :<%= singular_table_name %>, url: submit_url do |f| %>
1
+ <%%= simple_form_for model, as: :<%= singular_file_name %>, url: submit_url do |f| %>
2
2
  <fieldset>
3
3
  <%%= legend %>
4
4
  </fieldset>
@@ -0,0 +1,21 @@
1
+ describe <%= namespaced_model_class %>::Form, type: :cell do
2
+ controller ApplicationController
3
+ let(:result) { Capybara::Node::Simple.new(html) }
4
+ let(:model) do
5
+ <%= contract_class('create') %>.new(<%= namespaced_model_class %>.new)
6
+ end
7
+ let(:html) do
8
+ cell(
9
+ described_class,
10
+ model,
11
+ path: {
12
+ submit: '#',
13
+ back: '#'
14
+ }
15
+ ).()
16
+ end
17
+
18
+ it 'renders the form without error' do
19
+ expect(result).to have_xpath '//form'
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ describe <%= namespaced_model_class %>::List, type: :cell do
2
+ controller ApplicationController
3
+ let(:result) { Capybara::Node::Simple.new(html) }
4
+ let(:items) do
5
+ [<%= namespaced_model_class %>.new(id: 1)]
6
+ end
7
+ let(:html) do
8
+ cell(
9
+ described_class,
10
+ model,
11
+ ).()
12
+ end
13
+
14
+ it 'renders the list without error' do
15
+ expect(result).to have_xpath '//ul'
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ describe <%= namespaced_model_class %>::Table, type: :cell do
2
+ controller ApplicationController
3
+ let(:result) { Capybara::Node::Simple.new(html) }
4
+ let(:items) do
5
+ [<%= namespaced_model_class %>.new(id: 1)]
6
+ end
7
+ let(:html) do
8
+ cell(
9
+ described_class,
10
+ model,
11
+ ).()
12
+ end
13
+
14
+ it 'renders the table without error' do
15
+ expect(result).to have_xpath '//table'
16
+ end
17
+ end
@@ -61,10 +61,6 @@ module Organism
61
61
  'ApplicationContract'
62
62
  end
63
63
 
64
- def contract_class(action)
65
- model_class_path.concat(['contracts', action]).map(&:camelize).join('::')
66
- end
67
-
68
64
  def nested_namespace(&block)
69
65
  content = capture(&block)
70
66
  content = wrap_model(indent(content))
@@ -1,10 +1,8 @@
1
- require 'rails_helper'
2
-
3
1
  describe <%= namespaced_model_class %>::Create do
4
2
  let(:result) { described_class.trace(params: params) }
5
3
  let(:params) do
6
4
  {
7
- <%= singular_table_name %>: attributes_for(:<%= singular_table_name %>)
5
+ <%= singular_file_name %>: attributes_for(:<%= singular_file_name %>)
8
6
  }
9
7
  end
10
8
 
@@ -1,12 +1,10 @@
1
- require 'rails_helper'
2
-
3
1
  describe <%= namespaced_model_class %>::Update do
4
2
  let(:result) { described_class.trace(params: params) }
5
- let(:model) { <%= model_class %>::Factory.call }
3
+ let(:model) { <%= namespaced_model_class %>::Factory.call }
6
4
  let(:params) do
7
5
  {
8
6
  id: model.id,
9
- <%= singular_table_name %>: attributes_for(:<%= singular_table_name %>)
7
+ <%= singular_file_name %>: attributes_for(:<%= singular_file_name %>)
10
8
  }
11
9
  end
12
10
 
@@ -10,7 +10,7 @@ module Organism
10
10
  def create_controller_files
11
11
  template(
12
12
  'controller.rb',
13
- File.join('app/controllers', class_path, "#{file_name}_controller.rb")
13
+ File.join('app/controllers', class_path, "#{plural_file_name}_controller.rb")
14
14
  )
15
15
  end
16
16
 
@@ -18,7 +18,7 @@ module Organism
18
18
  return if actions.empty?
19
19
 
20
20
  route(
21
- "resources :#{file_name}, only: %i[#{actions.join(' ')}]",
21
+ "resources :#{plural_file_name}, only: %i[#{actions.join(' ')}]",
22
22
  namespace: regular_class_path
23
23
  )
24
24
  end
@@ -6,7 +6,7 @@ class <%= controller_class_name %>Controller < ApplicationController
6
6
  <% if index? -%>
7
7
 
8
8
  def index
9
- @<%= file_name %> = <%= namespaced_model_class %>.all
9
+ @<%= plural_file_name %> = <%= namespaced_model_class %>.all
10
10
  end
11
11
  <% end -%>
12
12
  <% if show? -%>
@@ -25,7 +25,7 @@ class <%= controller_class_name %>Controller < ApplicationController
25
25
  run <%= namespaced_model_class %>::Create do |result|
26
26
  return redirect_to(
27
27
  <%= after_create_path %>,
28
- notice: t('<%= notice_namespace %>.create.success')
28
+ notice: t('<%= i18n_scope %>.create.success')
29
29
  )
30
30
  end
31
31
 
@@ -44,7 +44,7 @@ class <%= controller_class_name %>Controller < ApplicationController
44
44
  run <%= namespaced_model_class %>::Update do |result|
45
45
  return redirect_to(
46
46
  <%= after_update_path %>,
47
- notice: t('<%= notice_namespace %>.update.success')
47
+ notice: t('<%= i18n_scope %>.update.success')
48
48
  )
49
49
  end
50
50
 
@@ -57,7 +57,7 @@ class <%= controller_class_name %>Controller < ApplicationController
57
57
  @<%= singular_file_name %>.destroy
58
58
  redirect_to(
59
59
  <%= after_destroy_path %>,
60
- notice: t('<%= notice_namespace %>.destroy.success')
60
+ notice: t('<%= i18n_scope %>.destroy.success')
61
61
  )
62
62
  end
63
63
  <% end -%>
@@ -3,11 +3,11 @@ module Organism
3
3
  private
4
4
 
5
5
  def controller_class_name
6
- human_name
6
+ file_name.pluralize.camelize
7
7
  end
8
8
 
9
- def notice_namespace
10
- model_class_path.map(&:underscore).join('.')
9
+ def contract_class(action)
10
+ model_class_path.concat(['contracts', action]).map(&:camelize).join('::')
11
11
  end
12
12
 
13
13
  def nested_namespace(&block)
@@ -58,7 +58,7 @@ module Organism
58
58
  end
59
59
 
60
60
  def model_class
61
- options[:model].blank? ? human_name.singularize : options[:model]
61
+ options[:model].blank? ? file_name.singularize.camelize : options[:model]
62
62
  end
63
63
 
64
64
  def singular_actions
@@ -1,5 +1,5 @@
1
1
  module Organism
2
2
  module Generators
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: organism-generators
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
  - Nolan Tait
@@ -79,10 +79,14 @@ files:
79
79
  - lib/organism/generators/cells/templates/cell/cell.rb.tt
80
80
  - lib/organism/generators/cells/templates/cell/list.rb.tt
81
81
  - lib/organism/generators/cells/templates/cell/show.rb.tt
82
+ - lib/organism/generators/cells/templates/cell/spec.rb.tt
82
83
  - lib/organism/generators/cells/templates/form/cell.rb.tt
83
84
  - lib/organism/generators/cells/templates/form/show.rb.tt
85
+ - lib/organism/generators/cells/templates/form/spec.rb.tt
84
86
  - lib/organism/generators/cells/templates/list/cell.rb.tt
87
+ - lib/organism/generators/cells/templates/list/spec.rb.tt
85
88
  - lib/organism/generators/cells/templates/table/cell.rb.tt
89
+ - lib/organism/generators/cells/templates/table/spec.rb.tt
86
90
  - lib/organism/generators/concept/USAGE
87
91
  - lib/organism/generators/concept/concept_generator.rb
88
92
  - lib/organism/generators/concept/templates/contracts/create.rb.tt