genesis_rails 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -4
  3. data/lib/generators/genesis_rails/install/files/templates/active_record/model/model.rb +1 -1
  4. data/lib/generators/genesis_rails/install/files/templates/erb/scaffold/edit.html.erb +1 -1
  5. data/lib/generators/genesis_rails/install/files/templates/erb/scaffold/index.html.erb +4 -0
  6. data/lib/generators/genesis_rails/install/files/templates/erb/scaffold/show.html.erb +1 -1
  7. data/lib/generators/genesis_rails/install/files/templates/rails/responders_controller/controller.rb +59 -0
  8. data/lib/generators/genesis_rails/install/files/templates/rspec/scaffold/edit_spec.rb +19 -0
  9. data/lib/generators/genesis_rails/install/files/templates/rspec/scaffold/index_spec.rb +18 -0
  10. data/lib/generators/genesis_rails/install/files/templates/rspec/scaffold/new_spec.rb +19 -0
  11. data/lib/generators/genesis_rails/install/files/templates/rspec/scaffold/routing_spec.rb +45 -0
  12. data/lib/generators/genesis_rails/install/files/templates/rspec/scaffold/show_spec.rb +15 -0
  13. data/lib/genesis_rails/version.rb +1 -1
  14. data/test/dummy/lib/templates/rspec/controller/controller_spec.rb +16 -0
  15. data/test/dummy/lib/templates/rspec/controller/view_spec.rb +5 -0
  16. data/test/dummy/lib/templates/rspec/helper/helper_spec.rb +17 -0
  17. data/test/dummy/lib/templates/rspec/integration/request_spec.rb +10 -0
  18. data/test/dummy/lib/templates/rspec/mailer/fixture +3 -0
  19. data/test/dummy/lib/templates/rspec/mailer/mailer_spec.rb +25 -0
  20. data/test/dummy/lib/templates/rspec/mailer/preview.rb +13 -0
  21. data/test/dummy/lib/templates/rspec/model/fixtures.yml +19 -0
  22. data/test/dummy/lib/templates/rspec/model/model_spec.rb +7 -0
  23. data/test/dummy/lib/templates/rspec/observer/observer_spec.rb +7 -0
  24. data/test/dummy/lib/templates/rspec/scaffold/controller_spec.rb +163 -0
  25. data/test/dummy/lib/templates/rspec/scaffold/edit_spec.rb +23 -0
  26. data/test/dummy/lib/templates/rspec/scaffold/index_spec.rb +25 -0
  27. data/test/dummy/lib/templates/rspec/scaffold/new_spec.rb +22 -0
  28. data/test/dummy/lib/templates/rspec/scaffold/routing_spec.rb +45 -0
  29. data/test/dummy/lib/templates/rspec/scaffold/show_spec.rb +21 -0
  30. data/test/dummy/lib/templates/rspec/view/view_spec.rb +5 -0
  31. metadata +62 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fb1fafeec13dac54a08b4eb6849dba8de99c5e4
4
- data.tar.gz: 6b12741f096b061baa3da1f039375ac492d364d1
3
+ metadata.gz: 14cc86ec671374cd2bf818cc111e218d294e3a3f
4
+ data.tar.gz: 0b12fc60867739712ef7e068e3c8d01d9065ff6b
5
5
  SHA512:
6
- metadata.gz: a7fd2e722fc1beb69d831d462535846f16397f4cb6ef7d4d14479814b1c175cfaf6687ff3f0bf6200fecc50581df71423bd6cd54126ea7149d759881e457aae0
7
- data.tar.gz: f2b26ba579155f875b1f8cbccb84258280e339639cda97b8d54464250d5f13f5c071c8f32f03215cf4c9304f1051821936cee20ff2df56dd863960cfc49a8870
6
+ metadata.gz: 977c9958d0d9442f1f2e589de7c4945d55f7236434cfa490807b8398a62f51c11adf124a705947dc3e191a9eafe356aeda9ca5b1dc07a64ef7f4774f7b108738
7
+ data.tar.gz: f6f58e806b40deea694121e5349296f09115ee00f546980f82b8ad851becca9cb22bc01310a836ad8dc70f600aaa26ebf9bacc68781c490f34dc6a9dd5629258
data/README.md CHANGED
@@ -23,6 +23,7 @@ To intall this project, first, you need to add the following to your Gemfile:
23
23
 
24
24
  ```ruby
25
25
  gem 'genesis_rails'
26
+ gem 'kaminari'
26
27
  gem 'responders'
27
28
  gem 'simple_form'
28
29
 
@@ -51,6 +52,8 @@ individually. If you are not so interested in reading everyone, here comes a
51
52
  list of commands you'll probably need to execute:
52
53
 
53
54
  ```bash
55
+ rails g kaminari:config
56
+ rails g kaminari:views bootstrap3
54
57
  rails g responders:install
55
58
  rails g simple_form:install --bootstrap
56
59
  rails g rspec:install
@@ -101,7 +104,7 @@ genesis:
101
104
  *= stub scaffolds
102
105
  *= require bootstrap
103
106
 
104
- <app/assets/javascripts/applicationjs>
107
+ <app/assets/javascripts/application.js>
105
108
  # add the following lines to import the needed bootstrap
106
109
  //= require bootstrap
107
110
  //= require magic_view
@@ -177,7 +180,9 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
177
180
 
178
181
  ## TODO
179
182
 
180
- - [ ] Make that generator become a rake task
181
- - [ ] Create a template.rb file to use with `rails new -m template.rb`
182
- - [ ] Make an install generator to install everything that's needed
183
+ - [ ] Make the install generator to configure the project with the above
184
+ recommended configuration
185
+ - [ ] Create a way to choose which frameworks and helpers to include when
186
+ installing, aaand copy the correct templates and files according on which were
187
+ selected, which not
183
188
 
@@ -13,7 +13,7 @@ class <%= class_name %> < <%= parent_class_name.classify %>
13
13
  end || attributes_to_show.first
14
14
  -%>
15
15
  <% if title_attribute.present? -%>
16
- def to_s
16
+ def to_title
17
17
  <%= title_attribute.name %>
18
18
  end
19
19
  <% end -%>
@@ -1,5 +1,5 @@
1
1
  <h1 class="text-center mb5">
2
- Editing <%= singular_table_name.titleize %> - <%%= @<%= singular_table_name %> %>
2
+ Editing <%= singular_table_name.titleize %> - <%%= @<%= singular_table_name %>.to_title %>
3
3
  </h1>
4
4
 
5
5
  <div class="text-center mb15">
@@ -35,6 +35,10 @@
35
35
  </tbody>
36
36
  </table>
37
37
  </div>
38
+
39
+ <div class="text-center mu15">
40
+ <%%= paginate @<%= singular_table_name %> %>
41
+ </div>
38
42
  </div>
39
43
  </div>
40
44
 
@@ -1,5 +1,5 @@
1
1
  <h1 class="text-center mb5">
2
- <%= singular_table_name.titleize %> - <%%= @<%= singular_table_name %> %>
2
+ <%= singular_table_name.titleize %> - <%%= @<%= singular_table_name %>.to_title %>
3
3
  </h1>
4
4
 
5
5
  <div class="text-center mb15">
@@ -0,0 +1,59 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
8
+
9
+ <% unless options[:singleton] -%>
10
+ def index
11
+ @<%= plural_table_name %> = <%= class_name %>.page(params[:page])
12
+ respond_with @<%= plural_table_name %>
13
+ end
14
+ <% end -%>
15
+
16
+ def show
17
+ respond_with @<%= singular_table_name %>
18
+ end
19
+
20
+ def new
21
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
22
+ respond_with @<%= singular_table_name %>
23
+ end
24
+
25
+ def edit
26
+ respond_with @<%= singular_table_name %>
27
+ end
28
+
29
+ def create
30
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, attributes_params) %>
31
+ <%= "flash[:notice] = '#{class_name} was successfully created.' if " if flash? %>@<%= orm_instance.save %>
32
+ respond_with @<%= singular_table_name %>
33
+ end
34
+
35
+ def update
36
+ <%= "flash[:notice] = '#{class_name} was successfully updated.' if " if flash? %>@<%= orm_instance.update("#{singular_table_name}_params" ) %>
37
+ respond_with @<%= singular_table_name %>
38
+ end
39
+
40
+ def destroy
41
+ @<%= orm_instance.destroy %>
42
+ respond_with @<%= singular_table_name %>
43
+ end
44
+
45
+ private
46
+
47
+ def set_<%= singular_table_name %>
48
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
49
+ end
50
+
51
+ def <%= "#{singular_table_name}_params" %>
52
+ <%- if attributes_names.empty? -%>
53
+ params[:<%= singular_table_name %>]
54
+ <%- else -%>
55
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
56
+ <%- end -%>
57
+ end
58
+ end
59
+ <% end -%>
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, FactoryGirl.create(:<%= ns_file_name %>))
7
+ end
8
+
9
+ it "renders the edit <%= ns_file_name %> form" do
10
+ render
11
+
12
+ assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
13
+ <% for attribute in output_attributes -%>
14
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
15
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
16
+ <% end -%>
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ assign(:<%= table_name %>, [
7
+ FactoryGirl.create(:<%= ns_file_name %>),
8
+ FactoryGirl.create(:<%= ns_file_name %>)
9
+ ])
10
+ end
11
+
12
+ it "renders a list of <%= ns_table_name %>" do
13
+ render
14
+ <% for attribute in output_attributes -%>
15
+ assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2
16
+ <% end -%>
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ assign(:<%= ns_file_name %>, FactoryGirl.build(:<%= ns_file_name %>))
7
+ end
8
+
9
+ it "renders new <%= ns_file_name %> form" do
10
+ render
11
+
12
+ assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
13
+ <% for attribute in output_attributes -%>
14
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
15
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
16
+ <% end -%>
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ require "rails_helper"
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
5
+ describe "routing" do
6
+
7
+ <% unless options[:singleton] -%>
8
+ it "routes to #index" do
9
+ expect(:get => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
10
+ end
11
+
12
+ <% end -%>
13
+ it "routes to #new" do
14
+ expect(:get => "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
15
+ end
16
+
17
+ it "routes to #show" do
18
+ expect(:get => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", :id => "1")
19
+ end
20
+
21
+ it "routes to #edit" do
22
+ expect(:get => "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", :id => "1")
23
+ end
24
+
25
+ it "routes to #create" do
26
+ expect(:post => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
27
+ end
28
+
29
+ it "routes to #update via PUT" do
30
+ expect(:put => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
31
+ end
32
+
33
+ <% if Rails::VERSION::STRING > '4' -%>
34
+ it "routes to #update via PATCH" do
35
+ expect(:patch => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
36
+ end
37
+
38
+ <% end -%>
39
+ it "routes to #destroy" do
40
+ expect(:delete => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", :id => "1")
41
+ end
42
+
43
+ end
44
+ end
45
+ <% end -%>
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, FactoryGirl.create(:<%= ns_file_name %>))
7
+ end
8
+
9
+ it "renders attributes in <p>" do
10
+ render
11
+ <% for attribute in output_attributes -%>
12
+ expect(rendered).to match(/<%= raw_value_for(attribute) %>/)
13
+ <% end -%>
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module GenesisRails
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,16 @@
1
+ require 'rails_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= class_name %>Controller, <%= type_metatag(:controller) %> do
5
+
6
+ <% for action in actions -%>
7
+ describe "GET #<%= action %>" do
8
+ it "returns http success" do
9
+ get :<%= action %>
10
+ expect(response).to have_http_status(:success)
11
+ end
12
+ end
13
+
14
+ <% end -%>
15
+ end
16
+ <% end -%>
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>", <%= type_metatag(:view) %> do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the <%= class_name %>Helper. For example:
5
+ #
6
+ # describe <%= class_name %>Helper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # expect(helper.concat_strings("this","that")).to eq("this that")
10
+ # end
11
+ # end
12
+ # end
13
+ <% module_namespacing do -%>
14
+ RSpec.describe <%= class_name %>Helper, <%= type_metatag(:helper) %> do
15
+ pending "add some examples to (or delete) #{__FILE__}"
16
+ end
17
+ <% end -%>
@@ -0,0 +1,10 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
4
+ describe "GET /<%= table_name %>" do
5
+ it "works! (now write some real specs)" do
6
+ get <%= index_helper %>_path
7
+ expect(response).to have_http_status(200)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ <%= class_name %>#<%= @action %>
2
+
3
+ Hi, find me in app/views/<%= @path %>
@@ -0,0 +1,25 @@
1
+ require "rails_helper"
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= class_name %>, <%= type_metatag(:mailer) %> do
5
+ <% for action in actions -%>
6
+ describe "<%= action %>" do
7
+ let(:mail) { <%= class_name %>.<%= action %> }
8
+
9
+ it "renders the headers" do
10
+ expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)
11
+ expect(mail.to).to eq(["to@example.org"])
12
+ expect(mail.from).to eq(["from@example.com"])
13
+ end
14
+
15
+ it "renders the body" do
16
+ expect(mail.body.encoded).to match("Hi")
17
+ end
18
+ end
19
+
20
+ <% end -%>
21
+ <% if actions.blank? -%>
22
+ pending "add some examples to (or delete) #{__FILE__}"
23
+ <% end -%>
24
+ end
25
+ <% end -%>
@@ -0,0 +1,13 @@
1
+ <% module_namespacing do -%>
2
+ # Preview all emails at http://localhost:3000/rails/mailers/<%= file_path %>
3
+ class <%= class_name %>Preview < ActionMailer::Preview
4
+ <% actions.each do |action| -%>
5
+
6
+ # Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>/<%= action %>
7
+ def <%= action %>
8
+ <%= class_name %>.<%= action %>
9
+ end
10
+ <% end -%>
11
+
12
+ end
13
+ <% end -%>
@@ -0,0 +1,19 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ <% unless attributes.empty? -%>
4
+ one:
5
+ <% for attribute in attributes -%>
6
+ <%= attribute.name %>: <%= attribute.default %>
7
+ <% end -%>
8
+
9
+ two:
10
+ <% for attribute in attributes -%>
11
+ <%= attribute.name %>: <%= attribute.default %>
12
+ <% end -%>
13
+ <% else -%>
14
+ # one:
15
+ # column: value
16
+ #
17
+ # two:
18
+ # column: value
19
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ require 'rails_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= class_name %>, <%= type_metatag(:model) %> do
5
+ pending "add some examples to (or delete) #{__FILE__}"
6
+ end
7
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ require 'rails_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= class_name %>Observer, <%= type_metatag(:observer) %> do
5
+ pending "add some examples to (or delete) #{__FILE__}"
6
+ end
7
+ <% end -%>
@@ -0,0 +1,163 @@
1
+ require 'rails_helper'
2
+
3
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
4
+ # It demonstrates how one might use RSpec to specify the controller code that
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+ #
15
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
20
+
21
+ <% module_namespacing do -%>
22
+ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:controller) %> do
23
+
24
+ # This should return the minimal set of attributes required to create a valid
25
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
26
+ # adjust the attributes here as well.
27
+ let(:valid_attributes) {
28
+ skip("Add a hash of attributes valid for your model")
29
+ }
30
+
31
+ let(:invalid_attributes) {
32
+ skip("Add a hash of attributes invalid for your model")
33
+ }
34
+
35
+ # This should return the minimal set of values that should be in the session
36
+ # in order to pass any filters (e.g. authentication) defined in
37
+ # <%= controller_class_name %>Controller. Be sure to keep this updated too.
38
+ let(:valid_session) { {} }
39
+
40
+ <% unless options[:singleton] -%>
41
+ describe "GET #index" do
42
+ it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
43
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
44
+ get :index, {}, valid_session
45
+ expect(assigns(:<%= table_name %>)).to eq([<%= file_name %>])
46
+ end
47
+ end
48
+
49
+ <% end -%>
50
+ describe "GET #show" do
51
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
52
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
53
+ get :show, {:id => <%= file_name %>.to_param}, valid_session
54
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
55
+ end
56
+ end
57
+
58
+ describe "GET #new" do
59
+ it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
60
+ get :new, {}, valid_session
61
+ expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
62
+ end
63
+ end
64
+
65
+ describe "GET #edit" do
66
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
67
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
68
+ get :edit, {:id => <%= file_name %>.to_param}, valid_session
69
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
70
+ end
71
+ end
72
+
73
+ describe "POST #create" do
74
+ context "with valid params" do
75
+ it "creates a new <%= class_name %>" do
76
+ expect {
77
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
78
+ }.to change(<%= class_name %>, :count).by(1)
79
+ end
80
+
81
+ it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
82
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
83
+ expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
84
+ expect(assigns(:<%= ns_file_name %>)).to be_persisted
85
+ end
86
+
87
+ it "redirects to the created <%= ns_file_name %>" do
88
+ post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
89
+ expect(response).to redirect_to(<%= class_name %>.last)
90
+ end
91
+ end
92
+
93
+ context "with invalid params" do
94
+ it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
95
+ post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
96
+ expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
97
+ end
98
+
99
+ it "re-renders the 'new' template" do
100
+ post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
101
+ expect(response).to render_template("new")
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "PUT #update" do
107
+ context "with valid params" do
108
+ let(:new_attributes) {
109
+ skip("Add a hash of attributes valid for your model")
110
+ }
111
+
112
+ it "updates the requested <%= ns_file_name %>" do
113
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
114
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session
115
+ <%= file_name %>.reload
116
+ skip("Add assertions for updated state")
117
+ end
118
+
119
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
120
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
121
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
122
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
123
+ end
124
+
125
+ it "redirects to the <%= ns_file_name %>" do
126
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
127
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
128
+ expect(response).to redirect_to(<%= file_name %>)
129
+ end
130
+ end
131
+
132
+ context "with invalid params" do
133
+ it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
134
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
135
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
136
+ expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
137
+ end
138
+
139
+ it "re-renders the 'edit' template" do
140
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
141
+ put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
142
+ expect(response).to render_template("edit")
143
+ end
144
+ end
145
+ end
146
+
147
+ describe "DELETE #destroy" do
148
+ it "destroys the requested <%= ns_file_name %>" do
149
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
150
+ expect {
151
+ delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
152
+ }.to change(<%= class_name %>, :count).by(-1)
153
+ end
154
+
155
+ it "redirects to the <%= table_name %> list" do
156
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
157
+ delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
158
+ expect(response).to redirect_to(<%= index_helper %>_url)
159
+ end
160
+ end
161
+
162
+ end
163
+ <% end -%>
@@ -0,0 +1,23 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
7
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
8
+ :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
9
+ <% end -%>
10
+ <%= output_attributes.empty? ? "" : " ))\n" -%>
11
+ end
12
+
13
+ it "renders the edit <%= ns_file_name %> form" do
14
+ render
15
+
16
+ assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
17
+ <% for attribute in output_attributes -%>
18
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
19
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
20
+ <% end -%>
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/index", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ assign(:<%= table_name %>, [
7
+ <% [1,2].each_with_index do |id, model_index| -%>
8
+ <%= class_name %>.create!(<%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : '' %>
9
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
10
+ :<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
11
+ <% end -%>
12
+ <% if !output_attributes.empty? -%>
13
+ <%= model_index == 1 ? ')' : '),' %>
14
+ <% end -%>
15
+ <% end -%>
16
+ ])
17
+ end
18
+
19
+ it "renders a list of <%= ns_table_name %>" do
20
+ render
21
+ <% for attribute in output_attributes -%>
22
+ assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2
23
+ <% end -%>
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ assign(:<%= ns_file_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %>
7
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
8
+ :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
9
+ <% end -%>
10
+ <%= !output_attributes.empty? ? " ))\n end" : " end" %>
11
+
12
+ it "renders new <%= ns_file_name %> form" do
13
+ render
14
+
15
+ assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
16
+ <% for attribute in output_attributes -%>
17
+ <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
18
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
19
+ <% end -%>
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,45 @@
1
+ require "rails_helper"
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
5
+ describe "routing" do
6
+
7
+ <% unless options[:singleton] -%>
8
+ it "routes to #index" do
9
+ expect(:get => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
10
+ end
11
+
12
+ <% end -%>
13
+ it "routes to #new" do
14
+ expect(:get => "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
15
+ end
16
+
17
+ it "routes to #show" do
18
+ expect(:get => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", :id => "1")
19
+ end
20
+
21
+ it "routes to #edit" do
22
+ expect(:get => "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", :id => "1")
23
+ end
24
+
25
+ it "routes to #create" do
26
+ expect(:post => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
27
+ end
28
+
29
+ it "routes to #update via PUT" do
30
+ expect(:put => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
31
+ end
32
+
33
+ <% if Rails::VERSION::STRING > '4' -%>
34
+ it "routes to #update via PATCH" do
35
+ expect(:patch => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
36
+ end
37
+
38
+ <% end -%>
39
+ it "routes to #destroy" do
40
+ expect(:delete => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", :id => "1")
41
+ end
42
+
43
+ end
44
+ end
45
+ <% end -%>
@@ -0,0 +1,21 @@
1
+ require 'rails_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
5
+ before(:each) do
6
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
7
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
8
+ :<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
9
+ <% end -%>
10
+ <% if !output_attributes.empty? -%>
11
+ ))
12
+ <% end -%>
13
+ end
14
+
15
+ it "renders attributes in <p>" do
16
+ render
17
+ <% for attribute in output_attributes -%>
18
+ expect(rendered).to match(/<%= raw_value_for(attribute) %>/)
19
+ <% end -%>
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "<%= file_path %>/<%= @action %>", <%= type_metatag(:view) %> do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genesis_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kelvinst
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-16 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0.10'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0.10'
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: |-
42
56
  This gem is a set of generators, templates and helpers to
43
57
  start a brand new rails project without too many code to
@@ -64,7 +78,13 @@ files:
64
78
  - lib/generators/genesis_rails/install/files/templates/erb/scaffold/index.html.erb
65
79
  - lib/generators/genesis_rails/install/files/templates/erb/scaffold/new.html.erb
66
80
  - lib/generators/genesis_rails/install/files/templates/erb/scaffold/show.html.erb
81
+ - lib/generators/genesis_rails/install/files/templates/rails/responders_controller/controller.rb
67
82
  - lib/generators/genesis_rails/install/files/templates/rspec/scaffold/controller_spec.rb
83
+ - lib/generators/genesis_rails/install/files/templates/rspec/scaffold/edit_spec.rb
84
+ - lib/generators/genesis_rails/install/files/templates/rspec/scaffold/index_spec.rb
85
+ - lib/generators/genesis_rails/install/files/templates/rspec/scaffold/new_spec.rb
86
+ - lib/generators/genesis_rails/install/files/templates/rspec/scaffold/routing_spec.rb
87
+ - lib/generators/genesis_rails/install/files/templates/rspec/scaffold/show_spec.rb
68
88
  - lib/generators/genesis_rails/install/install_generator.rb
69
89
  - lib/genesis_rails.rb
70
90
  - lib/genesis_rails/auto_include_magic_view.rb
@@ -102,6 +122,23 @@ files:
102
122
  - test/dummy/config/locales/en.yml
103
123
  - test/dummy/config/routes.rb
104
124
  - test/dummy/config/secrets.yml
125
+ - test/dummy/lib/templates/rspec/controller/controller_spec.rb
126
+ - test/dummy/lib/templates/rspec/controller/view_spec.rb
127
+ - test/dummy/lib/templates/rspec/helper/helper_spec.rb
128
+ - test/dummy/lib/templates/rspec/integration/request_spec.rb
129
+ - test/dummy/lib/templates/rspec/mailer/fixture
130
+ - test/dummy/lib/templates/rspec/mailer/mailer_spec.rb
131
+ - test/dummy/lib/templates/rspec/mailer/preview.rb
132
+ - test/dummy/lib/templates/rspec/model/fixtures.yml
133
+ - test/dummy/lib/templates/rspec/model/model_spec.rb
134
+ - test/dummy/lib/templates/rspec/observer/observer_spec.rb
135
+ - test/dummy/lib/templates/rspec/scaffold/controller_spec.rb
136
+ - test/dummy/lib/templates/rspec/scaffold/edit_spec.rb
137
+ - test/dummy/lib/templates/rspec/scaffold/index_spec.rb
138
+ - test/dummy/lib/templates/rspec/scaffold/new_spec.rb
139
+ - test/dummy/lib/templates/rspec/scaffold/routing_spec.rb
140
+ - test/dummy/lib/templates/rspec/scaffold/show_spec.rb
141
+ - test/dummy/lib/templates/rspec/view/view_spec.rb
105
142
  - test/dummy/public/404.html
106
143
  - test/dummy/public/422.html
107
144
  - test/dummy/public/500.html
@@ -162,6 +199,23 @@ test_files:
162
199
  - test/dummy/config/routes.rb
163
200
  - test/dummy/config/secrets.yml
164
201
  - test/dummy/config.ru
202
+ - test/dummy/lib/templates/rspec/controller/controller_spec.rb
203
+ - test/dummy/lib/templates/rspec/controller/view_spec.rb
204
+ - test/dummy/lib/templates/rspec/helper/helper_spec.rb
205
+ - test/dummy/lib/templates/rspec/integration/request_spec.rb
206
+ - test/dummy/lib/templates/rspec/mailer/fixture
207
+ - test/dummy/lib/templates/rspec/mailer/mailer_spec.rb
208
+ - test/dummy/lib/templates/rspec/mailer/preview.rb
209
+ - test/dummy/lib/templates/rspec/model/fixtures.yml
210
+ - test/dummy/lib/templates/rspec/model/model_spec.rb
211
+ - test/dummy/lib/templates/rspec/observer/observer_spec.rb
212
+ - test/dummy/lib/templates/rspec/scaffold/controller_spec.rb
213
+ - test/dummy/lib/templates/rspec/scaffold/edit_spec.rb
214
+ - test/dummy/lib/templates/rspec/scaffold/index_spec.rb
215
+ - test/dummy/lib/templates/rspec/scaffold/new_spec.rb
216
+ - test/dummy/lib/templates/rspec/scaffold/routing_spec.rb
217
+ - test/dummy/lib/templates/rspec/scaffold/show_spec.rb
218
+ - test/dummy/lib/templates/rspec/view/view_spec.rb
165
219
  - test/dummy/public/404.html
166
220
  - test/dummy/public/422.html
167
221
  - test/dummy/public/500.html