zoo-generators 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/README.rdoc +2 -2
  2. data/Rakefile +1 -1
  3. data/features/zoo_authentication.feature +13 -13
  4. data/lib/generators/zoo/authentication/USAGE +1 -1
  5. data/lib/generators/zoo/authentication/authentication_generator.rb +12 -12
  6. data/lib/generators/zoo/authentication/templates/controller_authentication.rb +2 -2
  7. data/lib/generators/zoo/authentication/templates/sessions_controller.rb +2 -2
  8. data/lib/generators/zoo/authentication/templates/tests/rspec/user.rb +12 -12
  9. data/lib/generators/zoo/authentication/templates/tests/rspec/users_controller.rb +5 -5
  10. data/lib/generators/zoo/authentication/templates/tests/shoulda/user.rb +12 -12
  11. data/lib/generators/zoo/authentication/templates/tests/shoulda/users_controller.rb +5 -5
  12. data/lib/generators/zoo/authentication/templates/tests/testunit/user.rb +12 -12
  13. data/lib/generators/zoo/authentication/templates/tests/testunit/users_controller.rb +5 -5
  14. data/lib/generators/zoo/authentication/templates/user.rb +4 -4
  15. data/lib/generators/zoo/authentication/templates/users_controller.rb +3 -3
  16. data/lib/generators/zoo/config/config_generator.rb +1 -1
  17. data/lib/generators/zoo/layout/layout_generator.rb +1 -1
  18. data/lib/generators/zoo/layout/templates/error_messages_helper.rb +3 -3
  19. data/lib/generators/zoo/layout/templates/layout.html.haml +2 -2
  20. data/lib/generators/zoo/scaffold/scaffold_generator.rb +13 -13
  21. data/lib/generators/zoo/scaffold/templates/actions/create.rb +1 -1
  22. data/lib/generators/zoo/scaffold/templates/actions/destroy.rb +1 -1
  23. data/lib/generators/zoo/scaffold/templates/tests/rspec/actions/destroy.rb +1 -1
  24. data/lib/generators/zoo/scaffold/templates/tests/rspec/actions/edit.rb +1 -1
  25. data/lib/generators/zoo/scaffold/templates/tests/rspec/actions/show.rb +1 -1
  26. data/lib/generators/zoo/scaffold/templates/tests/rspec/actions/update.rb +2 -2
  27. data/lib/generators/zoo/scaffold/templates/tests/shoulda/actions/destroy.rb +1 -1
  28. data/lib/generators/zoo/scaffold/templates/tests/shoulda/actions/edit.rb +1 -1
  29. data/lib/generators/zoo/scaffold/templates/tests/shoulda/actions/show.rb +1 -1
  30. data/lib/generators/zoo/scaffold/templates/tests/shoulda/actions/update.rb +2 -2
  31. data/lib/generators/zoo/scaffold/templates/tests/testunit/actions/destroy.rb +1 -1
  32. data/lib/generators/zoo/scaffold/templates/tests/testunit/actions/edit.rb +1 -1
  33. data/lib/generators/zoo/scaffold/templates/tests/testunit/actions/show.rb +1 -1
  34. data/lib/generators/zoo/scaffold/templates/tests/testunit/actions/update.rb +2 -2
  35. data/lib/generators/zoo/scaffold/templates/views/haml/_form.html.haml +1 -1
  36. data/lib/generators/zoo/scaffold/templates/views/haml/edit.html.haml +1 -1
  37. data/lib/generators/zoo/scaffold/templates/views/haml/index.html.haml +4 -4
  38. data/lib/generators/zoo/scaffold/templates/views/haml/show.html.haml +3 -3
  39. metadata +1 -2
  40. data/lib/generators/zoo/layout/templates/layout.html.erb +0 -19
@@ -9,7 +9,7 @@ A collection of useful Rails generator scripts for scaffolding, layout files, au
9
9
 
10
10
  Add the gem to your Gemfile.
11
11
 
12
- gem "zoo-generators", :group => :development
12
+ gem "zoo-generators", group : :development
13
13
 
14
14
  Then you can run any of the included generators.
15
15
 
@@ -54,7 +54,7 @@ Add the attribute to the attr_accessible line in the model.
54
54
 
55
55
  Some generators default redirecting to the root_url. Set this in your routes.rb file like this (substituting your controller name).
56
56
 
57
- root :to => "home#index"
57
+ root to: "home#index"
58
58
 
59
59
 
60
60
  <b>I get a missing database error.</b>
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Cucumber::Rake::Task.new(:features) do |t|
7
7
  t.cucumber_opts = "features --format progress"
8
8
  end
9
9
 
10
- task :default => :features
10
+ task default : :features
@@ -5,7 +5,7 @@ Feature: Zoo Authentication Generator
5
5
 
6
6
  Scenario: Generate default authentication
7
7
  Given a new Rails app
8
- When I insert "root :to => 'users#new'" into "config/routes.rb" after line 1
8
+ When I insert "root to: 'users#new'" into "config/routes.rb" after line 1
9
9
  And I run "rails g zoo:authentication"
10
10
  Then I should see the following files
11
11
  | app/models/user.rb |
@@ -25,13 +25,13 @@ Feature: Zoo Authentication Generator
25
25
  And I should see the following in file "config/routes.rb"
26
26
  | resources :sessions |
27
27
  | resources :users |
28
- | match 'login' => 'sessions#new', :as => :login |
29
- | match 'logout' => 'sessions#destroy', :as => :logout |
30
- | match 'signup' => 'users#new', :as => :signup |
31
- | match 'user/edit' => 'users#edit', :as => :edit_current_user |
28
+ | match 'login' => 'sessions#new', as : :login |
29
+ | match 'logout' => 'sessions#destroy', as : :logout |
30
+ | match 'signup' => 'users#new', as : :signup |
31
+ | match 'user/edit' => 'users#edit', as : :edit_current_user |
32
32
  And I should see "include ControllerAuthentication" in file "app/controllers/application_controller.rb"
33
- And I should see "gem "mocha", :group => :test" in file "Gemfile"
34
- And I should see "gem "bcrypt-ruby", :require => "bcrypt"" in file "Gemfile"
33
+ And I should see "gem "mocha", group : :test" in file "Gemfile"
34
+ And I should see "gem "bcrypt-ruby", require: "bcrypt"" in file "Gemfile"
35
35
  When I run "rails g zoo:layout -f"
36
36
  And I run "rake db:migrate"
37
37
  And I run "bundle install"
@@ -39,7 +39,7 @@ Feature: Zoo Authentication Generator
39
39
 
40
40
  Scenario: Generate named authentication
41
41
  Given a new Rails app
42
- When I insert "root :to => 'accounts#new'" into "config/routes.rb" after line 1
42
+ When I insert "root to: 'accounts#new'" into "config/routes.rb" after line 1
43
43
  And I run "rails g zoo:authentication Account CurrentSession"
44
44
  Then I should see the following files
45
45
  | app/models/account.rb |
@@ -57,10 +57,10 @@ Feature: Zoo Authentication Generator
57
57
  And I should see the following in file "config/routes.rb"
58
58
  | resources :current_sessions |
59
59
  | resources :accounts |
60
- | match 'login' => 'current_sessions#new', :as => :login |
61
- | match 'logout' => 'current_sessions#destroy', :as => :logout |
62
- | match 'signup' => 'accounts#new', :as => :signup |
63
- | match 'account/edit' => 'accounts#edit', :as => :edit_current_account |
60
+ | match 'login' => 'current_sessions#new', as : :login |
61
+ | match 'logout' => 'current_sessions#destroy', as : :logout |
62
+ | match 'signup' => 'accounts#new', as : :signup |
63
+ | match 'account/edit' => 'accounts#edit', as : :edit_current_account |
64
64
  When I run "rails g zoo:layout -f"
65
65
  And I run "rake db:migrate"
66
66
  And I run "bundle install"
@@ -68,7 +68,7 @@ Feature: Zoo Authentication Generator
68
68
 
69
69
  Scenario: Generate named authentication with rspec
70
70
  Given a new Rails app
71
- When I insert "root :to => 'accounts#new'" into "config/routes.rb" after line 1
71
+ When I insert "root to: 'accounts#new'" into "config/routes.rb" after line 1
72
72
  And I run "rails g zoo:authentication Account CurrentSession --rspec"
73
73
  Then I should see the following files
74
74
  | spec/models/account_spec.rb |
@@ -41,6 +41,6 @@ Methods:
41
41
  You can also restrict unregistered users from accessing a controller using
42
42
  a before filter. For example.
43
43
 
44
- before_filter :login_required, :except => [:index, :show]
44
+ before_filter :login_required, except: [:index, :show]
45
45
 
46
46
  See the generated file lib/authentication.rb for details.
@@ -6,17 +6,17 @@ module Zoo
6
6
  class AuthenticationGenerator < Base
7
7
  include Rails::Generators::Migration
8
8
 
9
- argument :user_name, :type => :string, :default => 'user', :banner => 'user_name'
10
- argument :session_name, :type => :string, :default => 'session', :banner => 'sessions_controller_name'
9
+ argument :user_name, type: :string, default: 'user', banner: 'user_name'
10
+ argument :session_name, type: :string, default: 'session', banner: 'sessions_controller_name'
11
11
 
12
- class_option :testunit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
13
- class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
14
- class_option :shoulda, :desc => 'Use shoulda for test files.', :group => 'Test framework', :type => :boolean
12
+ class_option :testunit, desc: 'Use test/unit for test files.', group: 'Test framework', type: :boolean
13
+ class_option :rspec, desc: 'Use RSpec for test files.', group: 'Test framework', type: :boolean
14
+ class_option :shoulda, desc: 'Use shoulda for test files.', group: 'Test framework', type: :boolean
15
15
 
16
16
  def add_gems
17
17
  add_gem "haml-rails"
18
- add_gem "bcrypt-ruby", :require => "bcrypt"
19
- add_gem "mocha", :group => :test
18
+ add_gem "bcrypt-ruby", require: "bcrypt"
19
+ add_gem "mocha", group: :test
20
20
  end
21
21
 
22
22
  def create_model_files
@@ -47,10 +47,10 @@ module Zoo
47
47
  def create_routes
48
48
  route "resources #{user_plural_name.to_sym.inspect}"
49
49
  route "resources #{session_plural_name.to_sym.inspect}"
50
- route "match 'login' => '#{session_plural_name}#new', :as => :login"
51
- route "match 'logout' => '#{session_plural_name}#destroy', :as => :logout"
52
- route "match 'signup' => '#{user_plural_name}#new', :as => :signup"
53
- route "match '#{user_singular_name}/edit' => '#{user_plural_name}#edit', :as => :edit_current_#{user_singular_name}"
50
+ route "match 'login' => '#{session_plural_name}#new', as : :login"
51
+ route "match 'logout' => '#{session_plural_name}#destroy', as : :logout"
52
+ route "match 'signup' => '#{user_plural_name}#new', as : :signup"
53
+ route "match '#{user_singular_name}/edit' => '#{user_plural_name}#edit', as : :edit_current_#{user_singular_name}"
54
54
  end
55
55
 
56
56
  def create_migration
@@ -129,7 +129,7 @@ module Zoo
129
129
  elsif options.shoulda?
130
130
  return @test_framework = :shoulda
131
131
  else
132
- return @test_framework = File.exist?(destination_path('spec')) ? :rspec : :testunit
132
+ return @test_framework = File.exist?(destination_path('spec')) ? rspec: :testunit
133
133
  end
134
134
  end
135
135
 
@@ -14,7 +14,7 @@
14
14
  # You can also restrict unregistered users from accessing a controller using
15
15
  # a before filter. For example.
16
16
  #
17
- # before_filter :login_required, :except => [:index, :show]
17
+ # before_filter :login_required, except: [:index, :show]
18
18
  module ControllerAuthentication
19
19
  def self.included(controller)
20
20
  controller.send :helper_method, :current_<%= user_singular_name %>, :logged_in?, :redirect_to_target_or_default
@@ -31,7 +31,7 @@ module ControllerAuthentication
31
31
  def login_required
32
32
  unless logged_in?
33
33
  store_target_location
34
- redirect_to login_url, :alert => "You must first log in or sign up before accessing this page."
34
+ redirect_to login_url, alert: "You must first log in or sign up before accessing this page."
35
35
  end
36
36
  end
37
37
 
@@ -6,7 +6,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
6
6
  <%= user_singular_name %> = <%= user_class_name %>.authenticate(params[:login], params[:password])
7
7
  if <%= user_singular_name %>
8
8
  session[:<%= user_singular_name %>_id] = <%= user_singular_name %>.id
9
- redirect_to_target_or_default root_url, :notice => "Logged in successfully."
9
+ redirect_to_target_or_default root_url, notice: "Logged in successfully."
10
10
  else
11
11
  flash.now[:alert] = "Invalid login or password."
12
12
  render :new
@@ -15,6 +15,6 @@ class <%= session_plural_class_name %>Controller < ApplicationController
15
15
 
16
16
  def destroy
17
17
  session[:<%= user_singular_name %>_id] = nil
18
- redirect_to root_url, :notice => "You have been logged out."
18
+ redirect_to root_url, notice: "You have been logged out."
19
19
  end
20
20
  end
@@ -18,33 +18,33 @@ describe <%= user_class_name %> do
18
18
  end
19
19
 
20
20
  it "should require username" do
21
- new_<%= user_singular_name %>(:username => '').should have(1).error_on(:username)
21
+ new_<%= user_singular_name %>(username: '').should have(1).error_on(:username)
22
22
  end
23
23
 
24
24
  it "should require password" do
25
- new_<%= user_singular_name %>(:password => '').should have(1).error_on(:password)
25
+ new_<%= user_singular_name %>(password: '').should have(1).error_on(:password)
26
26
  end
27
27
 
28
28
  it "should require well formed email" do
29
- new_<%= user_singular_name %>(:email => 'foo@bar@example.com').should have(1).error_on(:email)
29
+ new_<%= user_singular_name %>(email: 'foo@bar@example.com').should have(1).error_on(:email)
30
30
  end
31
31
 
32
32
  it "should validate uniqueness of email" do
33
- new_<%= user_singular_name %>(:email => 'bar@example.com').save!
34
- new_<%= user_singular_name %>(:email => 'bar@example.com').should have(1).error_on(:email)
33
+ new_<%= user_singular_name %>(email: 'bar@example.com').save!
34
+ new_<%= user_singular_name %>(email: 'bar@example.com').should have(1).error_on(:email)
35
35
  end
36
36
 
37
37
  it "should validate uniqueness of username" do
38
- new_<%= user_singular_name %>(:username => 'uniquename').save!
39
- new_<%= user_singular_name %>(:username => 'uniquename').should have(1).error_on(:username)
38
+ new_<%= user_singular_name %>(username: 'uniquename').save!
39
+ new_<%= user_singular_name %>(username: 'uniquename').should have(1).error_on(:username)
40
40
  end
41
41
 
42
42
  it "should not allow odd characters in username" do
43
- new_<%= user_singular_name %>(:username => 'odd ^&(@)').should have(1).error_on(:username)
43
+ new_<%= user_singular_name %>(username: 'odd ^&(@)').should have(1).error_on(:username)
44
44
  end
45
45
 
46
46
  it "should validate password is longer than 3 characters" do
47
- new_<%= user_singular_name %>(:password => 'bad').should have(1).error_on(:password)
47
+ new_<%= user_singular_name %>(password: 'bad').should have(1).error_on(:password)
48
48
  end
49
49
 
50
50
  it "should require matching password confirmation" do
@@ -59,13 +59,13 @@ describe <%= user_class_name %> do
59
59
  end
60
60
 
61
61
  it "should authenticate by username" do
62
- <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
62
+ <%= user_singular_name %> = new_<%= user_singular_name %>(username: 'foobar', password: 'secret')
63
63
  <%= user_singular_name %>.save!
64
64
  <%= user_class_name %>.authenticate('foobar', 'secret').should == <%= user_singular_name %>
65
65
  end
66
66
 
67
67
  it "should authenticate by email" do
68
- <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
68
+ <%= user_singular_name %> = new_<%= user_singular_name %>(email: 'foo@bar.com', password: 'secret')
69
69
  <%= user_singular_name %>.save!
70
70
  <%= user_class_name %>.authenticate('foo@bar.com', 'secret').should == <%= user_singular_name %>
71
71
  end
@@ -75,7 +75,7 @@ describe <%= user_class_name %> do
75
75
  end
76
76
 
77
77
  it "should not authenticate bad password" do
78
- new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
78
+ new_<%= user_singular_name %>(username: 'foobar', password: 'secret').save!
79
79
  <%= user_class_name %>.authenticate('foobar', 'badpassword').should be_nil
80
80
  end
81
81
  end
@@ -23,32 +23,32 @@ describe <%= user_plural_class_name %>Controller do
23
23
  end
24
24
 
25
25
  it "edit action should redirect when not logged in" do
26
- get :edit, :id => "ignored"
26
+ get :edit, id: "ignored"
27
27
  response.should redirect_to(login_url)
28
28
  end
29
29
 
30
30
  it "edit action should render edit template" do
31
31
  @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
32
- get :edit, :id => "ignored"
32
+ get :edit, id: "ignored"
33
33
  response.should render_template(:edit)
34
34
  end
35
35
 
36
36
  it "update action should redirect when not logged in" do
37
- put :update, :id => "ignored"
37
+ put :update, id: "ignored"
38
38
  response.should redirect_to(login_url)
39
39
  end
40
40
 
41
41
  it "update action should render edit template when <%= user_singular_name %> is invalid" do
42
42
  @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
43
43
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
44
- put :update, :id => "ignored"
44
+ put :update, id: "ignored"
45
45
  response.should render_template(:edit)
46
46
  end
47
47
 
48
48
  it "update action should redirect when <%= user_singular_name %> is valid" do
49
49
  @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
50
50
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
51
- put :update, :id => "ignored"
51
+ put :update, id: "ignored"
52
52
  response.should redirect_to(root_url)
53
53
  end
54
54
  end
@@ -20,33 +20,33 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
20
20
  end
21
21
 
22
22
  should "require username" do
23
- assert_equal ["can't be blank"], new_<%= user_singular_name %>(:username => '').errors[:username]
23
+ assert_equal ["can't be blank"], new_<%= user_singular_name %>(username: '').errors[:username]
24
24
  end
25
25
 
26
26
  should "require password" do
27
- assert_equal ["can't be blank"], new_<%= user_singular_name %>(:password => '').errors[:password]
27
+ assert_equal ["can't be blank"], new_<%= user_singular_name %>(password: '').errors[:password]
28
28
  end
29
29
 
30
30
  should "require well formed email" do
31
- assert_equal ["is invalid"], new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors[:email]
31
+ assert_equal ["is invalid"], new_<%= user_singular_name %>(email: 'foo@bar@example.com').errors[:email]
32
32
  end
33
33
 
34
34
  should "validate uniqueness of email" do
35
- new_<%= user_singular_name %>(:email => 'bar@example.com').save!
36
- assert_equal ["has already been taken"], new_<%= user_singular_name %>(:email => 'bar@example.com').errors[:email]
35
+ new_<%= user_singular_name %>(email: 'bar@example.com').save!
36
+ assert_equal ["has already been taken"], new_<%= user_singular_name %>(email: 'bar@example.com').errors[:email]
37
37
  end
38
38
 
39
39
  should "validate uniqueness of username" do
40
- new_<%= user_singular_name %>(:username => 'uniquename').save!
41
- assert_equal ["has already been taken"], new_<%= user_singular_name %>(:username => 'uniquename').errors[:username]
40
+ new_<%= user_singular_name %>(username: 'uniquename').save!
41
+ assert_equal ["has already been taken"], new_<%= user_singular_name %>(username: 'uniquename').errors[:username]
42
42
  end
43
43
 
44
44
  should "not allow odd characters in username" do
45
- assert_equal ["should only contain letters, numbers, or .-_@"], new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors[:username]
45
+ assert_equal ["should only contain letters, numbers, or .-_@"], new_<%= user_singular_name %>(username: 'odd ^&(@)').errors[:username]
46
46
  end
47
47
 
48
48
  should "validate password is longer than 3 characters" do
49
- assert_equal ["is too short (minimum is 4 characters)"], new_<%= user_singular_name %>(:password => 'bad').errors[:password]
49
+ assert_equal ["is too short (minimum is 4 characters)"], new_<%= user_singular_name %>(password: 'bad').errors[:password]
50
50
  end
51
51
 
52
52
  should "require matching password confirmation" do
@@ -61,13 +61,13 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
61
61
  end
62
62
 
63
63
  should "authenticate by username" do
64
- <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
64
+ <%= user_singular_name %> = new_<%= user_singular_name %>(username: 'foobar', password: 'secret')
65
65
  <%= user_singular_name %>.save!
66
66
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
67
67
  end
68
68
 
69
69
  should "authenticate by email" do
70
- <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
70
+ <%= user_singular_name %> = new_<%= user_singular_name %>(email: 'foo@bar.com', password: 'secret')
71
71
  <%= user_singular_name %>.save!
72
72
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
73
73
  end
@@ -77,7 +77,7 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
77
77
  end
78
78
 
79
79
  should "not authenticate bad password" do
80
- new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
80
+ new_<%= user_singular_name %>(username: 'foobar', password: 'secret').save!
81
81
  assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
82
82
  end
83
83
  end
@@ -25,34 +25,34 @@ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
25
25
 
26
26
  context "edit action" do
27
27
  should "redirect when not logged in" do
28
- get :edit, :id => "ignored"
28
+ get :edit, id: "ignored"
29
29
  assert_redirected_to login_url
30
30
  end
31
31
 
32
32
  should "render edit template" do
33
33
  @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
34
- get :edit, :id => "ignored"
34
+ get :edit, id: "ignored"
35
35
  assert_template 'edit'
36
36
  end
37
37
  end
38
38
 
39
39
  context "update action" do
40
40
  should "redirect when not logged in" do
41
- put :update, :id => "ignored"
41
+ put :update, id: "ignored"
42
42
  assert_redirected_to login_url
43
43
  end
44
44
 
45
45
  should "render edit template when <%= user_singular_name %> is invalid" do
46
46
  @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
47
47
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
48
- put :update, :id => "ignored"
48
+ put :update, id: "ignored"
49
49
  assert_template 'edit'
50
50
  end
51
51
 
52
52
  should "redirect when <%= user_singular_name %> is valid" do
53
53
  @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
54
54
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
55
- put :update, :id => "ignored"
55
+ put :update, id: "ignored"
56
56
  assert_redirected_to root_url
57
57
  end
58
58
  end
@@ -21,33 +21,33 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
21
21
  end
22
22
 
23
23
  def test_require_username
24
- assert_equal ["can't be blank"], new_<%= user_singular_name %>(:username => '').errors[:username]
24
+ assert_equal ["can't be blank"], new_<%= user_singular_name %>(username: '').errors[:username]
25
25
  end
26
26
 
27
27
  def test_require_password
28
- assert_equal ["can't be blank"], new_<%= user_singular_name %>(:password => '').errors[:password]
28
+ assert_equal ["can't be blank"], new_<%= user_singular_name %>(password: '').errors[:password]
29
29
  end
30
30
 
31
31
  def test_require_well_formed_email
32
- assert_equal ["is invalid"], new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors[:email]
32
+ assert_equal ["is invalid"], new_<%= user_singular_name %>(email: 'foo@bar@example.com').errors[:email]
33
33
  end
34
34
 
35
35
  def test_validate_uniqueness_of_email
36
- new_<%= user_singular_name %>(:email => 'bar@example.com').save!
37
- assert_equal ["has already been taken"], new_<%= user_singular_name %>(:email => 'bar@example.com').errors[:email]
36
+ new_<%= user_singular_name %>(email: 'bar@example.com').save!
37
+ assert_equal ["has already been taken"], new_<%= user_singular_name %>(email: 'bar@example.com').errors[:email]
38
38
  end
39
39
 
40
40
  def test_validate_uniqueness_of_username
41
- new_<%= user_singular_name %>(:username => 'uniquename').save!
42
- assert_equal ["has already been taken"], new_<%= user_singular_name %>(:username => 'uniquename').errors[:username]
41
+ new_<%= user_singular_name %>(username: 'uniquename').save!
42
+ assert_equal ["has already been taken"], new_<%= user_singular_name %>(username: 'uniquename').errors[:username]
43
43
  end
44
44
 
45
45
  def test_validate_odd_characters_in_username
46
- assert_equal ["should only contain letters, numbers, or .-_@"], new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors[:username]
46
+ assert_equal ["should only contain letters, numbers, or .-_@"], new_<%= user_singular_name %>(username: 'odd ^&(@)').errors[:username]
47
47
  end
48
48
 
49
49
  def test_validate_password_length
50
- assert_equal ["is too short (minimum is 4 characters)"], new_<%= user_singular_name %>(:password => 'bad').errors[:password]
50
+ assert_equal ["is too short (minimum is 4 characters)"], new_<%= user_singular_name %>(password: 'bad').errors[:password]
51
51
  end
52
52
 
53
53
  def test_require_matching_password_confirmation
@@ -63,14 +63,14 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
63
63
 
64
64
  def test_authenticate_by_username
65
65
  <%= user_class_name %>.delete_all
66
- <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
66
+ <%= user_singular_name %> = new_<%= user_singular_name %>(username: 'foobar', password: 'secret')
67
67
  <%= user_singular_name %>.save!
68
68
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
69
69
  end
70
70
 
71
71
  def test_authenticate_by_email
72
72
  <%= user_class_name %>.delete_all
73
- <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
73
+ <%= user_singular_name %> = new_<%= user_singular_name %>(email: 'foo@bar.com', password: 'secret')
74
74
  <%= user_singular_name %>.save!
75
75
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
76
76
  end
@@ -81,7 +81,7 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
81
81
 
82
82
  def test_authenticate_bad_password
83
83
  <%= user_class_name %>.delete_all
84
- new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
84
+ new_<%= user_singular_name %>(username: 'foobar', password: 'secret').save!
85
85
  assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
86
86
  end
87
87
  end
@@ -20,32 +20,32 @@ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
20
20
  end
21
21
 
22
22
  def test_edit_without_user
23
- get :edit, :id => "ignored"
23
+ get :edit, id: "ignored"
24
24
  assert_redirected_to login_url
25
25
  end
26
26
 
27
27
  def test_edit
28
28
  @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
29
- get :edit, :id => "ignored"
29
+ get :edit, id: "ignored"
30
30
  assert_template 'edit'
31
31
  end
32
32
 
33
33
  def test_update_without_user
34
- put :update, :id => "ignored"
34
+ put :update, id: "ignored"
35
35
  assert_redirected_to login_url
36
36
  end
37
37
 
38
38
  def test_update_invalid
39
39
  @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
40
40
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
41
- put :update, :id => "ignored"
41
+ put :update, id: "ignored"
42
42
  assert_template 'edit'
43
43
  end
44
44
 
45
45
  def test_update_valid
46
46
  @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
47
47
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
48
- put :update, :id => "ignored"
48
+ put :update, id: "ignored"
49
49
  assert_redirected_to root_url
50
50
  end
51
51
  end
@@ -8,11 +8,11 @@ class <%= user_class_name %> < ActiveRecord::Base
8
8
 
9
9
  validates_presence_of :username
10
10
  validates_uniqueness_of :username, :email, :allow_blank => true
11
- validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@"
12
- validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
13
- validates_presence_of :password, :on => :create
11
+ validates_format_of :username, with: /^[-\w\._@]+$/i, :allow_blank => true, message: "should only contain letters, numbers, or .-_@"
12
+ validates_format_of :email, with: /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
13
+ validates_presence_of password, on: :create
14
14
  validates_confirmation_of :password
15
- validates_length_of :password, :minimum => 4, :allow_blank => true
15
+ validates_length_of :password, minimum: 4, :allow_blank => true
16
16
 
17
17
  # login can be either username or email address
18
18
  def self.authenticate(login, pass)
@@ -1,5 +1,5 @@
1
1
  class <%= user_plural_class_name %>Controller < ApplicationController
2
- before_filter :login_required, :except => [:new, :create]
2
+ before_filter :login_required, except: [:new, :create]
3
3
 
4
4
  def new
5
5
  @<%= user_singular_name %> = <%= user_class_name %>.new
@@ -9,7 +9,7 @@ class <%= user_plural_class_name %>Controller < ApplicationController
9
9
  @<%= user_singular_name %> = <%= user_class_name %>.new(params[:<%= user_singular_name %>])
10
10
  if @<%= user_singular_name %>.save
11
11
  session[:<%= user_singular_name %>_id] = @<%= user_singular_name %>.id
12
- redirect_to root_url, :notice => "Thank you for signing up! You are now logged in."
12
+ redirect_to root_url, notice: "Thank you for signing up! You are now logged in."
13
13
  else
14
14
  render :new
15
15
  end
@@ -22,7 +22,7 @@ class <%= user_plural_class_name %>Controller < ApplicationController
22
22
  def update
23
23
  @<%= user_singular_name %> = current_<%= user_singular_name %>
24
24
  if @<%= user_singular_name %>.update_attributes(params[:<%= user_singular_name %>])
25
- redirect_to root_url, :notice => "Your profile has been updated."
25
+ redirect_to root_url, notice: "Your profile has been updated."
26
26
  else
27
27
  render :edit
28
28
  end
@@ -3,7 +3,7 @@ require 'generators/zoo'
3
3
  module Zoo
4
4
  module Generators
5
5
  class ConfigGenerator < Base
6
- argument :config_name, :type => :string, :default => 'app', :banner => 'config_name'
6
+ argument config_name, type: :string, default: 'app', banner: 'config_name'
7
7
 
8
8
  def create_config
9
9
  template "load_config.rb", "config/initializers/load_#{file_name}_config.rb"
@@ -3,7 +3,7 @@ require 'generators/zoo'
3
3
  module Zoo
4
4
  module Generators
5
5
  class LayoutGenerator < Base
6
- argument :layout_name, :type => :string, :default => 'application', :banner => 'layout_name'
6
+ argument :layout_name, type: :string, default: 'application', banner: 'layout_name'
7
7
 
8
8
  # def add_gems
9
9
  # add_gem "haml-rails"
@@ -2,11 +2,11 @@ module ErrorMessagesHelper
2
2
  # Render error messages for the given objects. The :message and :header_message options are allowed.
3
3
  def error_messages_for(*objects)
4
4
  options = objects.extract_options!
5
- options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
6
- options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
5
+ options[:header_message] ||= I18n.t(:"activerecord.errors.header", default: "Invalid Fields")
6
+ options[:message] ||= I18n.t(:"activerecord.errors.message", default: "Correct the following errors and try again.")
7
7
  messages = objects.compact.map { |o| o.errors.full_messages }.flatten
8
8
  unless messages.empty?
9
- content_tag(:div, :class => "error_messages") do
9
+ content_tag(:div, class: "error_messages") do
10
10
  list_items = messages.map { |msg| content_tag(:li, msg.html_safe) }
11
11
  content_tag(:h2, options[:header_message].html_safe) + content_tag(:p, options[:message].html_safe) + content_tag(:ul, list_items.join.html_safe)
12
12
  end
@@ -4,7 +4,7 @@
4
4
  %head
5
5
  %title
6
6
  = yield(:title) || "Untitled"
7
- %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
7
+ %meta{"http-equiv"=>"Content-Type", content: "text/html; charset=utf-8"}/
8
8
  = stylesheet_link_tag "<%= file_name %>"
9
9
  = javascript_include_tag :defaults
10
10
  = csrf_meta_tag
@@ -13,7 +13,7 @@
13
13
  %body
14
14
  #container
15
15
  - flash.each do |name, msg|
16
- = content_tag :div, msg, :id => "flash_#{name}"
16
+ = content_tag :div, msg, id: "flash_#{name}"
17
17
 
18
18
  - if show_title?
19
19
  %h1= yield(:title)
@@ -8,18 +8,18 @@ module Zoo
8
8
  include Rails::Generators::Migration
9
9
  no_tasks { attr_accessor :scaffold_name, :model_attributes, :controller_actions }
10
10
 
11
- argument :scaffold_name, :type => :string, :required => true, :banner => 'ModelName'
12
- argument :args_for_c_m, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
13
-
14
- class_option :skip_model, :desc => 'Don\'t generate a model or migration file.', :type => :boolean
15
- class_option :skip_migration, :desc => 'Dont generate migration file for model.', :type => :boolean
16
- class_option :skip_timestamps, :desc => 'Don\'t add timestamps to migration file.', :type => :boolean
17
- class_option :skip_controller, :desc => 'Don\'t generate controller, helper, or views.', :type => :boolean
18
- class_option :invert, :desc => 'Generate all controller actions except these mentioned.', :type => :boolean
19
- class_option :namespace_model, :desc => 'If the resource is namespaced, include the model in the namespace.', :type => :boolean
20
- class_option :testunit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
21
- class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
22
- class_option :shoulda, :desc => 'Use shoulda for test files.', :group => 'Test framework', :type => :boolean
11
+ argument :scaffold_name, type: :string, required: true, banner: 'ModelName'
12
+ argument :args_for_c_m, type: :array, default: [], banner: 'controller_actions and model:attributes'
13
+
14
+ class_option :skip_model, desc: 'Don\'t generate a model or migration file.', type: :boolean
15
+ class_option :skip_migration, desc: 'Dont generate migration file for model.', type: :boolean
16
+ class_option :skip_timestamps, desc: 'Don\'t add timestamps to migration file.', type: :boolean
17
+ class_option :skip_controller, desc: 'Don\'t generate controller, helper, or views.', type: :boolean
18
+ class_option :invert, desc: 'Generate all controller actions except these mentioned.', type: :boolean
19
+ class_option :namespace_model, desc: 'If the resource is namespaced, include the model in the namespace.', type: :boolean
20
+ class_option :testunit, desc: 'Use test/unit for test files.', group: 'Test framework', type: :boolean
21
+ class_option :rspec, desc: 'Use RSpec for test files.', group: 'Test framework', type: :boolean
22
+ class_option :shoulda, desc: 'Use shoulda for test files.', group: 'Test framework', type: :boolean
23
23
 
24
24
  def initialize(*args, &block)
25
25
  super
@@ -66,7 +66,7 @@ module Zoo
66
66
  def add_gems
67
67
  add_gem "haml-rails"
68
68
  add_gem "formtastic"
69
- add_gem "mocha", :group => :test
69
+ add_gem "mocha", group: :test
70
70
  end
71
71
 
72
72
  def create_model
@@ -1,7 +1,7 @@
1
1
  def create
2
2
  @<%= instance_name %> = <%= class_name %>.new(params[:<%= instance_name %>])
3
3
  if @<%= instance_name %>.save
4
- redirect_to <%= item_url %>, :notice => "Successfully created <%= class_name.underscore.humanize.downcase %>."
4
+ redirect_to <%= item_url %>, notice: "Successfully created <%= class_name.underscore.humanize.downcase %>."
5
5
  else
6
6
  render :new
7
7
  end
@@ -1,5 +1,5 @@
1
1
  def destroy
2
2
  @<%= instance_name %> = <%= class_name %>.find(params[:id])
3
3
  @<%= instance_name %>.destroy
4
- redirect_to <%= items_url %>, :notice => "Successfully destroyed <%= class_name.underscore.humanize.downcase %>."
4
+ redirect_to <%= items_url %>, notice: "Successfully destroyed <%= class_name.underscore.humanize.downcase %>."
5
5
  end
@@ -1,6 +1,6 @@
1
1
  it "destroy action should destroy model and redirect to index action" do
2
2
  <%= instance_name %> = <%= class_name %>.first
3
- delete :destroy, :id => <%= instance_name %>
3
+ delete :destroy, id: <%= instance_name %>
4
4
  response.should redirect_to(<%= items_url %>)
5
5
  <%= class_name %>.exists?(<%= instance_name %>.id).should be_false
6
6
  end
@@ -1,4 +1,4 @@
1
1
  it "edit action should render edit template" do
2
- get :edit, :id => <%= class_name %>.first
2
+ get :edit, id: <%= class_name %>.first
3
3
  response.should render_template(:edit)
4
4
  end
@@ -1,4 +1,4 @@
1
1
  it "show action should render show template" do
2
- get :show, :id => <%= class_name %>.first
2
+ get :show, id: <%= class_name %>.first
3
3
  response.should render_template(:show)
4
4
  end
@@ -1,11 +1,11 @@
1
1
  it "update action should render edit template when model is invalid" do
2
2
  <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
- put :update, :id => <%= class_name %>.first
3
+ put :update, id: <%= class_name %>.first
4
4
  response.should render_template(:edit)
5
5
  end
6
6
 
7
7
  it "update action should redirect when model is valid" do
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
- put :update, :id => <%= class_name %>.first
9
+ put :update, id: <%= class_name %>.first
10
10
  response.should redirect_to(<%= item_path_for_spec('url') %>)
11
11
  end
@@ -1,7 +1,7 @@
1
1
  context "destroy action" do
2
2
  should "destroy model and redirect to index action" do
3
3
  <%= instance_name %> = <%= class_name %>.first
4
- delete :destroy, :id => <%= instance_name %>
4
+ delete :destroy, id: <%= instance_name %>
5
5
  assert_redirected_to <%= items_url %>
6
6
  assert !<%= class_name %>.exists?(<%= instance_name %>.id)
7
7
  end
@@ -1,6 +1,6 @@
1
1
  context "edit action" do
2
2
  should "render edit template" do
3
- get :edit, :id => <%= class_name %>.first
3
+ get :edit, id: <%= class_name %>.first
4
4
  assert_template 'edit'
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  context "show action" do
2
2
  should "render show template" do
3
- get :show, :id => <%= class_name %>.first
3
+ get :show, id: <%= class_name %>.first
4
4
  assert_template 'show'
5
5
  end
6
6
  end
@@ -1,13 +1,13 @@
1
1
  context "update action" do
2
2
  should "render edit template when model is invalid" do
3
3
  <%= class_name %>.any_instance.stubs(:valid?).returns(false)
4
- put :update, :id => <%= class_name %>.first
4
+ put :update, id: <%= class_name %>.first
5
5
  assert_template 'edit'
6
6
  end
7
7
 
8
8
  should "redirect when model is valid" do
9
9
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
- put :update, :id => <%= class_name %>.first
10
+ put :update, id: <%= class_name %>.first
11
11
  assert_redirected_to <%= item_path_for_test('url') %>
12
12
  end
13
13
  end
@@ -1,6 +1,6 @@
1
1
  def test_destroy
2
2
  <%= instance_name %> = <%= class_name %>.first
3
- delete :destroy, :id => <%= instance_name %>
3
+ delete :destroy, id: <%= instance_name %>
4
4
  assert_redirected_to <%= items_url %>
5
5
  assert !<%= class_name %>.exists?(<%= instance_name %>.id)
6
6
  end
@@ -1,4 +1,4 @@
1
1
  def test_edit
2
- get :edit, :id => <%= class_name %>.first
2
+ get :edit, id: <%= class_name %>.first
3
3
  assert_template 'edit'
4
4
  end
@@ -1,4 +1,4 @@
1
1
  def test_show
2
- get :show, :id => <%= class_name %>.first
2
+ get :show, id: <%= class_name %>.first
3
3
  assert_template 'show'
4
4
  end
@@ -1,11 +1,11 @@
1
1
  def test_update_invalid
2
2
  <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
- put :update, :id => <%= class_name %>.first
3
+ put :update, id: <%= class_name %>.first
4
4
  assert_template 'edit'
5
5
  end
6
6
 
7
7
  def test_update_valid
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
- put :update, :id => <%= class_name %>.first
9
+ put :update, id: <%= class_name %>.first
10
10
  assert_redirected_to <%= item_path_for_test('url') %>
11
11
  end
@@ -1,4 +1,4 @@
1
- = semantic_form_for <%= item_path :instance_variable => true %> do |f|
1
+ = semantic_form_for <%= item_path instance_variable: true %> do |f|
2
2
  = f.error_messages
3
3
  <%- for attribute in model_attributes -%>
4
4
  .field
@@ -5,7 +5,7 @@
5
5
  <%- if actions? :show, :index -%>
6
6
  %p
7
7
  <%- if action? :show -%>
8
- = link_to "Show", <%= item_path :instance_variable => true %>
8
+ = link_to "Show", <%= item_path instance_variable: true %>
9
9
  |
10
10
  <%- end -%>
11
11
  <%- if action? :index -%>
@@ -14,12 +14,12 @@
14
14
  %td= link_to 'Show', <%= item_path %>
15
15
  <%- end -%>
16
16
  <%- if action? :edit -%>
17
- %td= link_to 'Edit', <%= item_path :action => :edit %>
17
+ %td= link_to 'Edit', <%= item_path action: :edit %>
18
18
  <%- end -%>
19
19
  <%- if action? :destroy -%>
20
- %td= link_to 'Destroy', <%= item_path %>, :confirm => 'Are you sure?', :method => :delete
20
+ %td= link_to 'Destroy', <%= item_path %>, confirm: 'Are you sure?', method: :delete
21
21
  <%- end -%>
22
22
 
23
- <%- if actions? :new -%>
24
- %p= link_to "New <%= singular_name.titleize %>", <%= item_path :action => :new %>
23
+ <%- if action? :new -%>
24
+ %p= link_to "New <%= singular_name.titleize %>", <%= item_path action: :new %>
25
25
  <%- end -%>
@@ -2,17 +2,17 @@
2
2
 
3
3
  <%- for attribute in model_attributes -%>
4
4
  %p
5
- %strong <%= attribute.human_name.titleize %>:
5
+ %strong <%= attribute.human_name.titleize %>
6
6
  = @<%= instance_name %>.<%= attribute.name %>
7
7
  <%- end -%>
8
8
 
9
9
  %p
10
10
  <%- if action? :edit -%>
11
- = link_to "Edit", <%= item_path :action => :edit, :instance_variable => true %>
11
+ = link_to "Edit", <%= item_path action: :edit, instance_variable: true %>
12
12
  |
13
13
  <%- end -%>
14
14
  <%- if action? :destroy -%>
15
- = link_to "Destroy", <%= item_path :instance_variable => true %>, :confirm => 'Are you sure?', :method => :delete
15
+ = link_to "Destroy", <%= item_path instance_variable: true %>, confirm: 'Are you sure?', method: :delete
16
16
  |
17
17
  <%- end -%>
18
18
  <%- if action? :index -%>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: zoo-generators
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mikael Henriksson
@@ -144,7 +144,6 @@ files:
144
144
  - lib/generators/zoo/config/USAGE
145
145
  - lib/generators/zoo/layout/layout_generator.rb
146
146
  - lib/generators/zoo/layout/templates/error_messages_helper.rb
147
- - lib/generators/zoo/layout/templates/layout.html.erb
148
147
  - lib/generators/zoo/layout/templates/layout.html.haml
149
148
  - lib/generators/zoo/layout/templates/layout_helper.rb
150
149
  - lib/generators/zoo/layout/templates/stylesheet.css
@@ -1,19 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title><%%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
5
- <%%= stylesheet_link_tag "<%= file_name %>" %>
6
- <%%= javascript_include_tag :defaults %>
7
- <%%= csrf_meta_tag %>
8
- <%%= yield(:head) %>
9
- </head>
10
- <body>
11
- <div id="container">
12
- <%% flash.each do |name, msg| %>
13
- <%%= content_tag :div, msg, :id => "flash_#{name}" %>
14
- <%% end %>
15
- <%%= content_tag :h1, yield(:title) if show_title? %>
16
- <%%= yield %>
17
- </div>
18
- </body>
19
- </html>