make_it_so 0.0.1 → 0.0.2

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: d301c85dbcb436020137a3aa762ba0b12e644247
4
- data.tar.gz: f32477cf05fde180f925743f6aab3b6b094205d4
3
+ metadata.gz: 2e5d493b9a3ce14d3ea060b76894375efb0335d5
4
+ data.tar.gz: 9749d2ca76326f4c092a93b265ef8cc0d6e4aa1c
5
5
  SHA512:
6
- metadata.gz: 57843769cc1bed8f88e31fdcc2c3048ba74e0123648be87128ea090d5285506e450e316cd2c2bb57d84425185417234e59b330420992315e14d1ca90aabc9acc
7
- data.tar.gz: e004da0a24866b66293b529d3cac1d3410107acd7cd2c87339144ea977a65359a88b70a4c2cca329b57f2318c46ee25a43acb10a2572c59d0e19f03725defeff
6
+ metadata.gz: 5428e8af216dfd77669446285f6050d50a18189d02d40234d3df5a18ccae7d3e40082530fab9f18e45daca26ba9e17d9cf3091d0aaff48c9088ed0b5e9ae1b15
7
+ data.tar.gz: 0f3fe01c86f3cdd706a995905ae8c6f65d2edfa241fe8d29564bce6fac85b52b62cb5c850679fea5a5cdec05198948a064691ca09b106d849c7b508a015aeae8
@@ -21,6 +21,17 @@ module MakeItSo
21
21
  default: 'postgresql',
22
22
  desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
23
23
 
24
+ class_option :foundation,
25
+ type: :boolean,
26
+ default: true,
27
+ desc: 'generate foundation support'
28
+
29
+ # turbolinks is the devil
30
+ class_option :skip_turbolinks,
31
+ type: :boolean,
32
+ default: true,
33
+ desc: 'Skip turbolinks gem'
34
+
24
35
  def initialize(*args)
25
36
  super
26
37
  if @options[:rspec]
@@ -32,8 +43,27 @@ module MakeItSo
32
43
 
33
44
  def finish_template
34
45
  super
46
+
47
+ build 'base_stylesheets'
48
+ unless options[:skip_javascript]
49
+ build 'base_javascripts'
50
+ end
51
+
52
+ build 'application_controller'
35
53
  if options[:rspec]
36
54
  build 'rspec_dependency'
55
+ #build 'fix_generators'
56
+ build 'factory_girl_rspec'
57
+ build 'valid_attribute_rspec'
58
+ build 'shoulda_rspec'
59
+ end
60
+
61
+ if options[:devise]
62
+ build 'devise_dependency'
63
+ end
64
+
65
+ if options[:foundation]
66
+ build 'foundation_dependency'
37
67
  end
38
68
  end
39
69
 
@@ -3,15 +3,154 @@ require 'rails/generators/rails/app/app_generator'
3
3
  module MakeItSo
4
4
  module Rails
5
5
  class AppBuilder < ::Rails::AppBuilder
6
+ def application_controller
7
+ inside 'app/controllers' do
8
+ template 'application_controller.rb'
9
+ end
10
+ end
11
+
12
+ def base_javascripts
13
+ inside 'app/assets/javascripts' do
14
+ template 'application.js'
15
+ end
16
+ end
17
+
18
+ def base_stylesheets
19
+ inside 'app/assets/stylesheets' do
20
+ template 'application.css'
21
+ end
22
+ end
23
+
24
+ def fix_generators
25
+ inject_into_class 'config/application.rb', 'Application' do
26
+ snippet('application_generator.rb')
27
+ end
28
+ end
29
+
6
30
  def rspec_dependency
7
31
  self.gem 'rspec-rails', group: [:development, :test]
32
+ self.gem 'capybara', group: [:development, :test]
33
+ self.gem 'launchy', group: [:development, :test]
34
+
8
35
  after_bundle do
9
36
  #stop spring in case it is running - it will hang
10
37
  #https://github.com/rails/rails/issues/13381
11
38
  run 'spring stop'
12
39
  generate 'rspec:install'
40
+ inside 'spec' do
41
+ empty_directory 'support'
42
+ end
43
+
44
+ inside 'spec' do
45
+ insert_into_file 'rails_helper.rb',
46
+ after: rails_helper_insertion_hook do
47
+
48
+ "require 'capybara/rspec'\n"
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ def factory_girl_rspec
55
+ self.gem 'factory_girl', group: [:development, :test]
56
+ after_bundle do
57
+ inside 'spec' do
58
+ insert_into_file 'rails_helper.rb',
59
+ after: rails_helper_insertion_hook do
60
+
61
+ "require File.join(File.dirname(__FILE__), 'support/factory_girl')\n"
62
+ end
63
+
64
+ inside 'support' do
65
+ template 'factory_girl.rb'
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def valid_attribute_rspec
72
+ self.gem 'valid_attribute', group: [:development, :test]
73
+ after_bundle do
74
+ inside 'spec' do
75
+ insert_into_file 'rails_helper.rb',
76
+ after: rails_helper_insertion_hook do
77
+
78
+ "require File.join(File.dirname(__FILE__), 'support/valid_attribute')\n"
79
+ end
80
+
81
+ inside 'support' do
82
+ template 'valid_attribute.rb'
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ def shoulda_rspec
89
+ self.gem 'shoulda-matchers',
90
+ group: [:development, :test],
91
+ require: false
92
+ after_bundle do
93
+ inside 'spec' do
94
+ insert_into_file 'rails_helper.rb',
95
+ after: rails_helper_insertion_hook do
96
+
97
+ "require 'shoulda-matchers'\n"
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ def devise_dependency
104
+ self.gem 'devise'
105
+
106
+ after_bundle do
107
+ generate 'devise:install'
108
+ generate 'devise:views'
109
+ generate 'devise user'
110
+
111
+ if options[:rspec]
112
+ inside 'spec' do
113
+ directory 'features'
114
+
115
+ inside 'support' do
116
+ insert_into_file 'factory_girl.rb',
117
+ after: "FactoryGirl.define do\n" do
118
+
119
+ snippet('user_factory.rb')
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ route "root 'homes\#index'"
126
+ end
127
+ end
128
+
129
+ def foundation_dependency
130
+ self.gem 'foundation-rails'
131
+
132
+ after_bundle do
133
+ generate 'foundation:install foundation'
134
+ # foundation-rails generates an application layout so we
135
+ # must remove it
136
+ # there is a pull request open to skip this:
137
+ # https://github.com/zurb/foundation-rails/pull/108
138
+ remove_file 'app/views/layouts/foundation.html.erb'
13
139
  end
14
140
  end
141
+
142
+ protected
143
+ def rails_helper_insertion_hook
144
+ "require 'rspec/rails'\n"
145
+ end
146
+
147
+ def snippet_path
148
+ File.join(File.dirname(__FILE__), '../../../snippets/rails')
149
+ end
150
+
151
+ def snippet(path)
152
+ File.read(File.join(snippet_path, path))
153
+ end
15
154
  end
16
155
  end
17
156
  end
@@ -1,3 +1,3 @@
1
1
  module MakeItSo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,13 @@
1
+ config.generators do |generate|
2
+ #don't generate noise in the rails stack
3
+ generate.helper false
4
+ generate.stylesheets false
5
+ generate.javascripts false
6
+
7
+ #TODO: figure out how to make this ERB
8
+ generate.test_framework :rspec
9
+
10
+ #don't generate unused spec files
11
+ generate.view_specs false
12
+ generate.controller_specs false
13
+ end
@@ -0,0 +1,5 @@
1
+ factory :user do
2
+ sequence(:email) {|n| "user#{n}@example.com" }
3
+ password 'password'
4
+ password_confirmation 'password'
5
+ end
@@ -9,6 +9,11 @@ feature 'user generates rails app' do
9
9
  join_paths(tmp_path, app_name)
10
10
  end
11
11
 
12
+ let(:css_manifest_path) { join_paths(app_path, 'app/assets/stylesheets/application.css') }
13
+
14
+ let(:gemfile_path) { join_paths(app_path, 'Gemfile')}
15
+ let(:rails_spec_helper) { join_paths(app_path, 'spec/rails_helper.rb')}
16
+
12
17
  before(:all) do
13
18
  make_it_so!("rails #{app_name}")
14
19
  end
@@ -17,6 +22,20 @@ feature 'user generates rails app' do
17
22
  expect(FileTest.exists?(join_paths(app_path, 'app/models'))).to eq(true)
18
23
  end
19
24
 
25
+ scenario 'creates an application.js manifest' do
26
+ js_file = join_paths(app_path, 'app/assets/javascripts/application.js')
27
+ expect(FileTest.exists?(js_file)).to eq(true)
28
+ end
29
+
30
+ scenario 'creates an application.css manifest' do
31
+ expect(FileTest.exists?(css_manifest_path)).to eq(true)
32
+ end
33
+
34
+ scenario 'includes the flash in the layout' do
35
+ app_layout = File.join(app_path, 'app/views/layouts/application.html.erb')
36
+ expect(File.read(app_layout)).to include('flash')
37
+ end
38
+
20
39
  context 'rspec' do
21
40
  it 'eliminates test/unit' do
22
41
  expect(FileTest.exists?(join_paths(app_path, 'test'))).to_not eq(true)
@@ -26,5 +45,104 @@ feature 'user generates rails app' do
26
45
  spec_helper = join_paths(app_path, 'spec/spec_helper.rb')
27
46
  expect(FileTest.exists?(spec_helper)).to eq(true)
28
47
  end
48
+
49
+ context 'capybara' do
50
+ it 'includes capybara as a Gemfile dependency' do
51
+ expect(File.read(gemfile_path)).to include('capybara')
52
+ end
53
+
54
+ it 'includes launch as a Gemfile dependency' do
55
+ expect(File.read(gemfile_path)).to include('launchy')
56
+ end
57
+
58
+ it 'includes capybara in the rails_helper' do
59
+ expect(File.read(rails_spec_helper)).to match(/require \'capybara\/rspec\'/)
60
+ end
61
+ end
62
+
63
+ context 'factory_girl' do
64
+ it 'includes a factory_girl support file' do
65
+ fg_support_path = join_paths(app_path, 'spec/support/factory_girl.rb')
66
+ expect(FileTest.exists?(fg_support_path)).to eq(true)
67
+ end
68
+
69
+ it 'includes the factory_girl gem' do
70
+ expect(File.read(gemfile_path)).to include('factory_girl')
71
+ end
72
+
73
+ it 'requires the factory_girl support file' do
74
+ expect(File.read(rails_spec_helper)).
75
+ to match(/require(.*)support\/factory_girl/)
76
+ end
77
+ end
78
+
79
+ context 'valid_attribute' do
80
+ it 'includes the valid_attribute gem' do
81
+ expect(File.read(gemfile_path)).to include('valid_attribute')
82
+ end
83
+
84
+ it 'creates the valid_attribute support file' do
85
+ support_path = join_paths(app_path, 'spec/support/valid_attribute.rb')
86
+ expect(FileTest.exists?(support_path)).to eq(true)
87
+ end
88
+
89
+ it 'requires the valid_attribute support file' do
90
+ expect(File.read(rails_spec_helper)).
91
+ to match(/require(.*)support\/valid_attribute/)
92
+ end
93
+ end
94
+
95
+ context 'shoulda' do
96
+ it 'includes shoulda-matchers in the gemfile' do
97
+ expect(File.read(gemfile_path)).to include('shoulda-matchers')
98
+ end
99
+
100
+ it 'requires shoulda-matchers in the rails_helper' do
101
+ expect(File.read(rails_spec_helper)).
102
+ to include("require 'shoulda-matchers'")
103
+ end
104
+ end
105
+ end
106
+
107
+ context 'devise' do
108
+ it 'adds devise as a dependency' do
109
+ expect(File.read(gemfile_path)).to include('devise')
110
+ end
111
+
112
+ it 'generates devise' do
113
+ devise_initializer = File.join(app_path, 'config/initializers/devise.rb')
114
+ expect(FileTest.exists?(devise_initializer)).to eq(true)
115
+ end
116
+
117
+ it 'generates devise views' do
118
+ devise_views = File.join(app_path, 'app/views/devise')
119
+ expect(FileTest.exists?(devise_views)).to eq(true)
120
+ end
121
+
122
+ it 'creates a user model' do
123
+ user_model = File.join(app_path, 'app/models/user.rb')
124
+ expect(FileTest.exists?(user_model)).to eq(true)
125
+ end
126
+
127
+ it 'creates a user_signs_up feature spec' do
128
+ feature_spec = File.join(app_path, 'spec/features/user_signs_up_spec.rb')
129
+ expect(FileTest.exists?(feature_spec)).to eq(true)
130
+ end
131
+
132
+ it 'creates a user_signs_in feature spec' do
133
+ feature_spec = File.join(app_path, 'spec/features/user_signs_in_spec.rb')
134
+ expect(FileTest.exists?(feature_spec)).to eq(true)
135
+ end
136
+
137
+ it 'creates a user_signs_out feature spec' do
138
+ feature_spec = File.join(app_path, 'spec/features/user_signs_out_spec.rb')
139
+ expect(FileTest.exists?(feature_spec)).to eq(true)
140
+ end
141
+ end
142
+
143
+ context 'foundation' do
144
+ it 'generates foundation' do
145
+ expect(File.read(css_manifest_path)).to include('foundation_and_overrides')
146
+ end
29
147
  end
30
148
  end
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,4 @@
1
+ class HomesController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ <p>
2
+ Modify me in `app/views/homes/index.html.erb` or change the root directive in
3
+ `config/routes.rb`
4
+ </p>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= camelized %></title>
5
+ <%%= stylesheet_link_tag 'application', media: 'all' %>
6
+ <%%= csrf_meta_tags %>
7
+ </head>
8
+ <body>
9
+ <%- if options.devise? -%>
10
+ <% if options.foundation? %>
11
+ <nav class="top-bar">
12
+ <ul class="title-area">
13
+ <li class="name">
14
+ <h1><a href="/"><%= camelized %></a></h1>
15
+ </li>
16
+ </ul>
17
+
18
+ <section class="top-bar-section">
19
+ <ul class="right">
20
+ <%%- if current_user -%>
21
+ <li><%%= link_to 'Sign Out', destroy_user_session_path, method: :delete %></li>
22
+ <%%- else -%>
23
+ <li><%%= link_to 'Sign Up', new_user_registration_path %></li>
24
+ <li><%%= link_to 'Sign In', new_user_session_path %></li>
25
+ <%%- end -%>
26
+ </ul>
27
+ </section>
28
+ </nav>
29
+ <%- else -%>
30
+ <ul>
31
+ <%%- if current_user -%>
32
+ <li><%%= link_to 'Sign Out', user_session_path(:me), method: :delete %></li>
33
+ <%%- else -%>
34
+ <li><%%= link_to 'Sign Up', new_registration_path %></li>
35
+ <li><%%= link_to 'Sign In', new_user_session_path %></li>
36
+ <%%- end -%>
37
+ </ul>
38
+ <%- end -%>
39
+ <%- end -%>
40
+
41
+ <%%- flash.each do |key, value| -%>
42
+ <div class="flash flash-<%%= key %>">
43
+ <%%= value %>
44
+ </div>
45
+ <%%- end -%>
46
+
47
+ <%%= yield %>
48
+
49
+ <%%= javascript_include_tag 'application' %>
50
+ <%%= javascript_tag do %>
51
+ $(function(){
52
+ $(document).foundation();
53
+ });
54
+ <%% end %>
55
+ <%%= yield :extra_footer %>
56
+ </body>
57
+ </html>
@@ -0,0 +1,29 @@
1
+ require 'rails_helper'
2
+
3
+ feature 'user signs in', %Q{
4
+ As a signed up user
5
+ I want to sign in
6
+ So that I can regain access to my account
7
+ } do
8
+ scenario 'specify valid credentials' do
9
+ user = FactoryGirl.create(:user)
10
+
11
+ visit new_user_session_path
12
+
13
+ fill_in 'Email', with: user.email
14
+ fill_in 'Password', with: user.password
15
+
16
+ click_button 'Log in'
17
+
18
+ expect(page).to have_content('Signed in successfully')
19
+ expect(page).to have_content('Sign Out')
20
+ end
21
+
22
+ scenario 'specify invalid credentials' do
23
+ visit new_user_session_path
24
+
25
+ click_button 'Log in'
26
+ expect(page).to have_content('Invalid email or password')
27
+ expect(page).to_not have_content('Sign Out')
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ require 'rails_helper'
2
+
3
+ feature 'user signs out', %Q{
4
+ As an authenticated user
5
+ I want to sign out
6
+ So that my identity is forgotten about on the machine I'm using
7
+ } do
8
+ # Acceptance Criteria
9
+ # * If I'm signed in, i have an option to sign out
10
+ # * When I opt to sign out, I get a confirmation that my identity has been
11
+ # forgotten on the machine I'm using
12
+
13
+ scenario 'authenticated user signs out' do
14
+ user = FactoryGirl.create(:user)
15
+
16
+ visit new_user_session_path
17
+
18
+ fill_in 'Email', with: user.email
19
+ fill_in 'Password', with: user.password
20
+
21
+ click_button 'Log in'
22
+
23
+ expect(page).to have_content('Signed in successfully')
24
+
25
+ click_link 'Sign Out'
26
+ expect(page).to have_content('Signed out successfully')
27
+ end
28
+
29
+ scenario 'unauthenticated user attempts to sign out' do
30
+ visit '/'
31
+ expect(page).to_not have_content('Sign Out')
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails_helper'
2
+
3
+ feature 'user registers', %Q{
4
+ As a visitor
5
+ I want to register
6
+ So that I can create an account
7
+ } do
8
+
9
+ # Acceptance Criteria:
10
+ # * I must specify a valid email address,
11
+ # password, and password confirmation
12
+ # * If I don't specify the required information, I am presented with
13
+ # an error message
14
+
15
+ scenario 'provide valid registration information' do
16
+ visit new_user_registration_path
17
+
18
+ fill_in 'Email', with: 'john@example.com'
19
+ fill_in 'Password', with: 'password'
20
+ fill_in 'Password confirmation', with: 'password'
21
+
22
+ click_button 'Sign up'
23
+
24
+ expect(page).to have_content('Welcome! You have signed up successfully.')
25
+ expect(page).to have_content('Sign Out')
26
+ end
27
+
28
+ scenario 'provide invalid registration information' do
29
+ visit new_user_registration_path
30
+
31
+ click_button 'Sign up'
32
+ expect(page).to have_content("can't be blank")
33
+ expect(page).to_not have_content('Sign Out')
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+
5
+ end
@@ -0,0 +1 @@
1
+ require 'valid_attribute/rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: make_it_so
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pickett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -116,11 +116,22 @@ files:
116
116
  - lib/make_it_so/rails/app_builder.rb
117
117
  - lib/make_it_so/version.rb
118
118
  - make_it_so.gemspec
119
+ - snippets/rails/application_generator.rb
120
+ - snippets/rails/user_factory.rb
119
121
  - spec/features/user_generates_rails_spec.rb
120
122
  - spec/spec_helper.rb
121
123
  - spec/support/make_it_so_spec_helpers.rb
122
124
  - templates/.gitkeep
123
125
  - templates/rails/.gitkeep
126
+ - templates/rails/app/controllers/application_controller.rb
127
+ - templates/rails/app/controllers/homes_controller.rb
128
+ - templates/rails/app/views/homes/index.html.erb
129
+ - templates/rails/app/views/layouts/application.html.erb.tt
130
+ - templates/rails/spec/features/user_signs_in_spec.rb
131
+ - templates/rails/spec/features/user_signs_out_spec.rb
132
+ - templates/rails/spec/features/user_signs_up_spec.rb
133
+ - templates/rails/spec/support/factory_girl.rb
134
+ - templates/rails/spec/support/valid_attribute.rb
124
135
  homepage: ''
125
136
  licenses:
126
137
  - MIT