prologue 0.1.0
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.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +110 -0
- data/LICENSE +21 -0
- data/README.md +65 -0
- data/Rakefile +2 -0
- data/bin/prologue +3 -0
- data/features/new.feature +44 -0
- data/features/support/setup.rb +1 -0
- data/lib/prologue/cli.rb +71 -0
- data/lib/prologue/version.rb +3 -0
- data/lib/prologue.rb +3 -0
- data/prologue.gemspec +27 -0
- data/templates/admin/dashboard_spec.rb +22 -0
- data/templates/admin/layout.rb +75 -0
- data/templates/admin/sass.rb +140 -0
- data/templates/admin/users.rb +140 -0
- data/templates/admin/users_spec.rb +29 -0
- data/templates/admin.rb +28 -0
- data/templates/application_layout.rb +71 -0
- data/templates/bootstrap.rb +91 -0
- data/templates/cancan.rb +104 -0
- data/templates/clean_routes.rb +8 -0
- data/templates/db.rb +1 -0
- data/templates/db_seed.rb +1 -0
- data/templates/devise/cucumber.rb +91 -0
- data/templates/devise.rb +94 -0
- data/templates/dynamic_form.rb +1 -0
- data/templates/friendly_id.rb +1 -0
- data/templates/gemfile.rb +32 -0
- data/templates/haml_generator.rb +7 -0
- data/templates/home_controller.rb +13 -0
- data/templates/jammit.rb +13 -0
- data/templates/js.rb +10 -0
- data/templates/rails_clean.rb +7 -0
- data/templates/rspec_clean.rb +3 -0
- data/templates/sass.rb +142 -0
- data/templates/sorter_lib.rb +97 -0
- data/templates/test_suite.rb +11 -0
- metadata +190 -0
@@ -0,0 +1,140 @@
|
|
1
|
+
generate(:controller, "admin/users index new create edit update destroy")
|
2
|
+
|
3
|
+
inject_into_file 'config/routes.rb', :after => "devise_for :users\n" do
|
4
|
+
<<-'FILE'
|
5
|
+
namespace "admin" do
|
6
|
+
resources :users
|
7
|
+
end
|
8
|
+
FILE
|
9
|
+
end
|
10
|
+
|
11
|
+
inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def index\n" do
|
12
|
+
<<-'FILE'
|
13
|
+
@sortable = SortIndex::Sortable.new(params, INDEX_SORT)
|
14
|
+
@users = User.paginate :page => params[:page], :order => @sortable.order, :per_page => 2
|
15
|
+
FILE
|
16
|
+
end
|
17
|
+
|
18
|
+
inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def new\n" do
|
19
|
+
<<-'FILE'
|
20
|
+
@user = User.new
|
21
|
+
FILE
|
22
|
+
end
|
23
|
+
|
24
|
+
inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def create\n" do
|
25
|
+
<<-'FILE'
|
26
|
+
@user = User.new(params[:user])
|
27
|
+
if @user.save
|
28
|
+
flash[:notice] = "User created!"
|
29
|
+
redirect_to admin_users_url
|
30
|
+
else
|
31
|
+
render :action => 'new'
|
32
|
+
end
|
33
|
+
FILE
|
34
|
+
end
|
35
|
+
|
36
|
+
inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def update\n" do
|
37
|
+
<<-'FILE'
|
38
|
+
if @user.update_attributes(params[:user])
|
39
|
+
flash[:notice] = "Successfully updated #{@user.name}."
|
40
|
+
redirect_to admin_users_url
|
41
|
+
else
|
42
|
+
render :action => 'edit'
|
43
|
+
end
|
44
|
+
FILE
|
45
|
+
end
|
46
|
+
|
47
|
+
inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def destroy\n" do
|
48
|
+
<<-'FILE'
|
49
|
+
@user.destroy
|
50
|
+
flash[:notice] = "User deleted."
|
51
|
+
redirect_to admin_users_url
|
52
|
+
FILE
|
53
|
+
end
|
54
|
+
|
55
|
+
gsub_file 'app/controllers/admin/users_controller.rb', /ApplicationController/, 'Admin::BaseController'
|
56
|
+
|
57
|
+
inject_into_file 'app/controllers/admin/users_controller.rb', :after => "class Admin::UsersController < Admin::BaseController\n" do
|
58
|
+
<<-'FILE'
|
59
|
+
before_filter :find_user, :only => [:edit, :update, :destroy]
|
60
|
+
|
61
|
+
INDEX_SORT = SortIndex::Config.new(
|
62
|
+
{'name' => 'name'},
|
63
|
+
{
|
64
|
+
'email' => 'email',
|
65
|
+
'login' => 'login',
|
66
|
+
'roles_mask' => 'roles_mask',
|
67
|
+
'last_login_at' => 'last_login_at'
|
68
|
+
}
|
69
|
+
#, optionally SortIndex::SORT_KEY_ASC
|
70
|
+
)
|
71
|
+
|
72
|
+
def find_user
|
73
|
+
@user = User.find(params[:id])
|
74
|
+
end
|
75
|
+
|
76
|
+
FILE
|
77
|
+
end
|
78
|
+
|
79
|
+
create_file 'app/views/admin/users/_form.html.haml' do
|
80
|
+
<<-'FILE'
|
81
|
+
- form_for([:admin, @user]) do |f|
|
82
|
+
.form_errors
|
83
|
+
= f.error_messages
|
84
|
+
%fieldset#user_form
|
85
|
+
.form_row
|
86
|
+
= f.label :name
|
87
|
+
= f.text_field :name
|
88
|
+
.form_row
|
89
|
+
= f.label :email
|
90
|
+
= f.text_field :email
|
91
|
+
.form_row
|
92
|
+
= f.label :password
|
93
|
+
= f.password_field :password
|
94
|
+
.form_row
|
95
|
+
= f.label :password_confirmation
|
96
|
+
= f.password_field :password_confirmation
|
97
|
+
.form_row.form_row_button
|
98
|
+
= f.submit "Save"
|
99
|
+
FILE
|
100
|
+
end
|
101
|
+
|
102
|
+
create_file 'app/views/admin/users/edit.html.haml' do
|
103
|
+
<<-'FILE'
|
104
|
+
= render :partial => "form"
|
105
|
+
FILE
|
106
|
+
end
|
107
|
+
|
108
|
+
create_file 'app/views/admin/users/new.html.haml' do
|
109
|
+
<<-'FILE'
|
110
|
+
= render :partial => "form"
|
111
|
+
FILE
|
112
|
+
end
|
113
|
+
|
114
|
+
create_file 'app/views/admin/users/index.html.haml' do
|
115
|
+
<<-FILE
|
116
|
+
- if !@users.blank?
|
117
|
+
%table
|
118
|
+
%thead
|
119
|
+
%tr
|
120
|
+
%th= @sortable.header_link('name', 'Name')
|
121
|
+
%th= @sortable.header_link('email', 'Email')
|
122
|
+
%th
|
123
|
+
%th
|
124
|
+
%tbody
|
125
|
+
- for user in @users
|
126
|
+
%tr
|
127
|
+
%td= user.name
|
128
|
+
%td= user.email
|
129
|
+
%td= link_to "Edit", edit_admin_user_path(user), :class => 'edit_link'
|
130
|
+
%td
|
131
|
+
- if user.id != current_user.id
|
132
|
+
= link_to "Delete", admin_user_path(user), :confirm => t('forms.confirm'), :method => :delete, :class => 'delete_link'
|
133
|
+
- else
|
134
|
+
That's you!
|
135
|
+
= will_paginate @users
|
136
|
+
- else
|
137
|
+
%p No users
|
138
|
+
FILE
|
139
|
+
end
|
140
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
create_file 'spec/controllers/admin/users_controller_spec.rb' do
|
2
|
+
<<-'FILE'
|
3
|
+
require 'spec_helper'
|
4
|
+
include Devise::TestHelpers
|
5
|
+
|
6
|
+
describe Admin::UsersController do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@user = @user ||=Factory.create(:admin)
|
10
|
+
sign_in @user
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "GET 'index'" do
|
14
|
+
it "should be successful" do
|
15
|
+
get 'index'
|
16
|
+
response.should be_success
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "GET 'new'" do
|
21
|
+
it "should be successful" do
|
22
|
+
get 'new'
|
23
|
+
response.should be_success
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
FILE
|
29
|
+
end
|
data/templates/admin.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
say "Building admin"
|
2
|
+
generate(:controller, "admin/dashboard index")
|
3
|
+
|
4
|
+
inject_into_file 'config/routes.rb', :after => "devise_for :users\n" do
|
5
|
+
<<-RUBY
|
6
|
+
match 'admin' => 'admin/dashboard#index'
|
7
|
+
RUBY
|
8
|
+
end
|
9
|
+
|
10
|
+
# Do layout and SASS stuff
|
11
|
+
apply File.expand_path("../admin/sass.rb", __FILE__)
|
12
|
+
apply File.expand_path("../admin/layout.rb", __FILE__)
|
13
|
+
|
14
|
+
create_file 'app/controllers/admin/base_controller.rb' do
|
15
|
+
<<-RUBY
|
16
|
+
class Admin::BaseController < ApplicationController
|
17
|
+
layout 'admin'
|
18
|
+
before_filter :authenticate_user!
|
19
|
+
end
|
20
|
+
RUBY
|
21
|
+
end
|
22
|
+
|
23
|
+
gsub_file 'app/controllers/admin/dashboard_controller.rb', /ApplicationController/, 'Admin::BaseController'
|
24
|
+
|
25
|
+
# make a user admin
|
26
|
+
apply File.expand_path("../admin/users.rb", __FILE__)
|
27
|
+
apply File.expand_path("../admin/dashboard_spec.rb", __FILE__)
|
28
|
+
apply File.expand_path("../admin/users_spec.rb", __FILE__)
|
@@ -0,0 +1,71 @@
|
|
1
|
+
run 'mkdir app/views/shared'
|
2
|
+
|
3
|
+
create_file 'app/views/shared/_header.html.haml' do
|
4
|
+
<<-FILE
|
5
|
+
%header#main_header
|
6
|
+
%h1= link_to '#{app_name.humanize}', root_path
|
7
|
+
= render 'shared/messages'
|
8
|
+
%nav#main_nav
|
9
|
+
%ul
|
10
|
+
%li= link_to 'Home', root_path
|
11
|
+
FILE
|
12
|
+
end
|
13
|
+
|
14
|
+
create_file 'app/views/shared/_messages.html.haml' do
|
15
|
+
<<-FILE
|
16
|
+
- if flash[:notice]
|
17
|
+
%div#messenger{:class => "flasher"}= flash[:notice]
|
18
|
+
- if flash[:error]
|
19
|
+
%div#error{:class => "flasher"}= flash[:error]
|
20
|
+
FILE
|
21
|
+
end
|
22
|
+
|
23
|
+
create_file 'app/views/shared/_footer.html.haml' do
|
24
|
+
<<-FILE
|
25
|
+
%footer#main_footer
|
26
|
+
%a{:href => "http://quickleft.com"}
|
27
|
+
#{app_name.humanize}
|
28
|
+
FILE
|
29
|
+
end
|
30
|
+
|
31
|
+
create_file 'app/views/shared/_end_scripts.html.haml' do
|
32
|
+
<<-FILE
|
33
|
+
= javascript_include_tag :defaults
|
34
|
+
FILE
|
35
|
+
end
|
36
|
+
|
37
|
+
run 'rm app/views/layouts/application.html.erb'
|
38
|
+
create_file 'app/views/layouts/application.html.haml' do
|
39
|
+
<<-FILE
|
40
|
+
!!! 5
|
41
|
+
%html
|
42
|
+
%head
|
43
|
+
%meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
|
44
|
+
%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
|
45
|
+
%title
|
46
|
+
#{app_name.humanize}
|
47
|
+
= yield(:title)
|
48
|
+
%meta{:name => 'description', :content => ''}
|
49
|
+
%meta{:name => 'author', :content => ''}
|
50
|
+
%meta{:name => 'viewport', :content => 'width=device-width; initial-scale=1.0'}
|
51
|
+
= csrf_meta_tag
|
52
|
+
%link{:rel => "shortcut icon", :href => "/images/favicon.ico", :type => "image/x-icon"}
|
53
|
+
%link{:rel => "apple-touch-icon", :href => "/images/ati.png"}
|
54
|
+
/[if lt IE 9]
|
55
|
+
%script{:type => "text/javascript", :src => "/javascripts/shiv.js"}
|
56
|
+
= stylesheet_link_tag :all
|
57
|
+
= yield(:head)
|
58
|
+
/[if IE 7]
|
59
|
+
= stylesheet_link_tag 'ie7', :media => 'all'
|
60
|
+
/[if IE 8]
|
61
|
+
= stylesheet_link_tag 'ie8', :media => 'all'
|
62
|
+
%body
|
63
|
+
#container
|
64
|
+
= render :partial => "shared/header"
|
65
|
+
%section#content
|
66
|
+
= yield
|
67
|
+
#pusher
|
68
|
+
= render :partial => "shared/footer"
|
69
|
+
= render :partial => "shared/end_scripts"
|
70
|
+
FILE
|
71
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
say "Building Application with Prologue..."
|
2
|
+
|
3
|
+
append_file '.gitignore' do
|
4
|
+
'.DS_Store'
|
5
|
+
'log/*.log'
|
6
|
+
'tmp/**/*'
|
7
|
+
'config/database.yml'
|
8
|
+
'db/*.sqlite3'
|
9
|
+
'public/system/**/**/**/*'
|
10
|
+
'.idea/*'
|
11
|
+
end
|
12
|
+
|
13
|
+
git :init
|
14
|
+
|
15
|
+
# Apply Gemfile
|
16
|
+
apply File.expand_path("../gemfile.rb", __FILE__)
|
17
|
+
|
18
|
+
# Apply Jammit
|
19
|
+
apply File.expand_path("../jammit.rb", __FILE__)
|
20
|
+
|
21
|
+
# Apply HAML generator
|
22
|
+
apply File.expand_path("../haml_generator.rb", __FILE__)
|
23
|
+
|
24
|
+
# Apply rails clean up
|
25
|
+
apply File.expand_path("../rails_clean.rb", __FILE__)
|
26
|
+
|
27
|
+
# Apply js
|
28
|
+
apply File.expand_path("../js.rb", __FILE__)
|
29
|
+
|
30
|
+
# Apply HTML5 Layout
|
31
|
+
apply File.expand_path("../application_layout.rb", __FILE__)
|
32
|
+
|
33
|
+
# Apply SASS
|
34
|
+
apply File.expand_path("../sass.rb", __FILE__)
|
35
|
+
|
36
|
+
# Apply Test Suite
|
37
|
+
apply File.expand_path("../test_suite.rb", __FILE__)
|
38
|
+
|
39
|
+
# Apply Friendly Id
|
40
|
+
apply File.expand_path("../friendly_id.rb", __FILE__)
|
41
|
+
|
42
|
+
# Apply Devise?
|
43
|
+
apply File.expand_path("../devise.rb", __FILE__) if ENV['PROLOGUE_AUTH']
|
44
|
+
|
45
|
+
# Apply sorter helper
|
46
|
+
apply File.expand_path("../sorter_lib.rb", __FILE__)
|
47
|
+
|
48
|
+
# Apply admin
|
49
|
+
apply File.expand_path("../admin.rb", __FILE__) if ENV['PROLOGUE_ADMIN']
|
50
|
+
|
51
|
+
# Apply cancan
|
52
|
+
apply File.expand_path("../cancan.rb", __FILE__) if ENV['PROLOGUE_ROLES']
|
53
|
+
|
54
|
+
# Apply db create and migrations
|
55
|
+
apply File.expand_path("../db.rb", __FILE__)
|
56
|
+
|
57
|
+
# Apply db seeds
|
58
|
+
apply File.expand_path("../db_seed.rb", __FILE__)
|
59
|
+
|
60
|
+
# Make a home controller
|
61
|
+
apply File.expand_path("../home_controller.rb", __FILE__)
|
62
|
+
|
63
|
+
# Clean up generated routes
|
64
|
+
apply File.expand_path("../clean_routes.rb", __FILE__)
|
65
|
+
|
66
|
+
# Remove RSpec stuff we are not gonna use right away
|
67
|
+
apply File.expand_path("../rspec_clean.rb", __FILE__)
|
68
|
+
|
69
|
+
# Make the form errors work like they did in 2.3.8
|
70
|
+
apply File.expand_path("../dynamic_form.rb", __FILE__)
|
71
|
+
|
72
|
+
login_msg = (ENV['PROLOGUE_ADMIN']) ? "Login to admin with email #{ENV['PROLOGUE_USER_EMAIL']} and password #{ENV['PROLOGUE_USER_PASSWORD']}" : ""
|
73
|
+
|
74
|
+
say <<-D
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
########################################################################
|
80
|
+
|
81
|
+
Prologue just added like 6 hours to your life.
|
82
|
+
|
83
|
+
Next run...
|
84
|
+
rake spec
|
85
|
+
rake cucumber
|
86
|
+
rails s
|
87
|
+
|
88
|
+
#{login_msg}
|
89
|
+
|
90
|
+
########################################################################
|
91
|
+
D
|
data/templates/cancan.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
say "Building roles"
|
2
|
+
generate(:model, "role name:string")
|
3
|
+
generate(:migration, "UsersHaveAndBelongToManyRoles")
|
4
|
+
habtm_roles = Dir['db/migrate/*_users_have_and_belong_to_many_roles.rb'].first
|
5
|
+
inject_into_file habtm_roles, :after => "def self.up\n" do
|
6
|
+
<<-RUBY
|
7
|
+
create_table :roles_users, :id => false do |t|
|
8
|
+
t.references :role, :user
|
9
|
+
end
|
10
|
+
RUBY
|
11
|
+
end
|
12
|
+
|
13
|
+
inject_into_file habtm_roles, :after => "def self.down\n" do
|
14
|
+
<<-RUBY
|
15
|
+
drop_table :roles_users
|
16
|
+
RUBY
|
17
|
+
end
|
18
|
+
|
19
|
+
inject_into_file 'app/models/user.rb', :after => "class User < ActiveRecord::Base\n" do
|
20
|
+
<<-RUBY
|
21
|
+
has_and_belongs_to_many :roles
|
22
|
+
RUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
inject_into_file 'app/models/role.rb', :after => "class Role < ActiveRecord::Base\n" do
|
26
|
+
<<-RUBY
|
27
|
+
has_and_belongs_to_many :users
|
28
|
+
RUBY
|
29
|
+
end
|
30
|
+
|
31
|
+
create_file 'app/models/ability.rb' do
|
32
|
+
<<-RUBY
|
33
|
+
class Ability
|
34
|
+
include CanCan::Ability
|
35
|
+
|
36
|
+
def initialize(user)
|
37
|
+
user ||= User.new # guest user
|
38
|
+
|
39
|
+
if user.role? :admin
|
40
|
+
can :manage, :all
|
41
|
+
# elsif user.role? :writter
|
42
|
+
# can :manage, [Post, Asset]
|
43
|
+
# elsif user.role? :memeber
|
44
|
+
# can :read, [MemberPost, Asset]
|
45
|
+
# # manage posts, assets user owns
|
46
|
+
# can :manage, Post do |p|
|
47
|
+
# p.try(:owner) == user
|
48
|
+
# end
|
49
|
+
# can :manage, Asset do |a|
|
50
|
+
# a.try(:owner) == user
|
51
|
+
# end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
RUBY
|
56
|
+
end
|
57
|
+
|
58
|
+
inject_into_file 'app/models/user.rb', :before => "end\n" do
|
59
|
+
<<-RUBY
|
60
|
+
|
61
|
+
def role?(role)
|
62
|
+
return !!self.roles.find_by_name(role.to_s.camelize)
|
63
|
+
end
|
64
|
+
RUBY
|
65
|
+
end
|
66
|
+
|
67
|
+
inject_into_file 'app/controllers/application_controller.rb', :before => "end\n" do
|
68
|
+
<<-RUBY
|
69
|
+
|
70
|
+
rescue_from CanCan::AccessDenied do |exception|
|
71
|
+
flash[:error] = "Access Denied"
|
72
|
+
redirect_to root_url
|
73
|
+
end
|
74
|
+
RUBY
|
75
|
+
end
|
76
|
+
|
77
|
+
if ENV['PROLOGUE_ADMIN']
|
78
|
+
inject_into_file 'app/views/admin/users/_form.html.haml', :after => "= f.password_field :password_confirmation\n" do
|
79
|
+
<<-RUBY
|
80
|
+
.form_row
|
81
|
+
- for role in Role.find(:all, :order => "name")
|
82
|
+
.check_box_item
|
83
|
+
= check_box_tag "user[role_ids][]", role.id, @user.roles.include?(role)
|
84
|
+
= role.name.humanize
|
85
|
+
RUBY
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
append_file 'db/seeds.rb' do
|
90
|
+
<<-FILE
|
91
|
+
Role.create! :name => 'Admin'.camelize
|
92
|
+
Role.create! :name => 'Member'.camelize
|
93
|
+
|
94
|
+
user1 = User.find_by_email('#{ENV['PROLOGUE_USER_EMAIL']}')
|
95
|
+
user1.role_ids = [1,2]
|
96
|
+
user1.save
|
97
|
+
FILE
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
gsub_file 'config/routes.rb', /get \"home\/index\"/, ''
|
2
|
+
gsub_file 'config/routes.rb', /get \"users\/index\"/, ''
|
3
|
+
gsub_file 'config/routes.rb', /get \"users\/new\"/, ''
|
4
|
+
gsub_file 'config/routes.rb', /get \"users\/create\"/, ''
|
5
|
+
gsub_file 'config/routes.rb', /get \"users\/edit\"/, ''
|
6
|
+
gsub_file 'config/routes.rb', /get \"users\/update\"/, ''
|
7
|
+
gsub_file 'config/routes.rb', /get \"users\/destroy\"/, ''
|
8
|
+
gsub_file 'config/routes.rb', /get \"dashboard\/index\"/, ''
|
data/templates/db.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
run 'rake db:migrate'
|
@@ -0,0 +1 @@
|
|
1
|
+
run 'rake db:seed'
|
@@ -0,0 +1,91 @@
|
|
1
|
+
create_file 'features/authentication.feature' do
|
2
|
+
<<-'FILE'
|
3
|
+
Feature: User admin authentication
|
4
|
+
As an administrator
|
5
|
+
I want to manage the application
|
6
|
+
So that I can have full control over the site
|
7
|
+
|
8
|
+
Scenario: Login as an admin
|
9
|
+
Given a logged in admin user
|
10
|
+
When I am on the admin
|
11
|
+
Then I should see "Admin"
|
12
|
+
FILE
|
13
|
+
end
|
14
|
+
|
15
|
+
create_file 'spec/factories/user.rb' do
|
16
|
+
<<-'FILE'
|
17
|
+
Factory.define :user do |u|
|
18
|
+
u.sequence(:name) { |n| "Quick #{n}" }
|
19
|
+
u.sequence(:email) { |n| "info.#{n}@quickleft.com" }
|
20
|
+
u.password "password"
|
21
|
+
u.confirmed_at Time.new.to_s
|
22
|
+
u.confirmation_sent_at Time.new.to_s
|
23
|
+
u.password_confirmation { |u| u.password }
|
24
|
+
end
|
25
|
+
|
26
|
+
Factory.define :admin, :parent => :user do |admin|
|
27
|
+
admin.email "quickleft@quickleft.com"
|
28
|
+
admin.password "password"
|
29
|
+
admin.roles { [ Factory(:role, :name => 'admin') ] }
|
30
|
+
end
|
31
|
+
|
32
|
+
Factory.define :member, :parent => :user do |member|
|
33
|
+
member.email "member@quickleft.com"
|
34
|
+
member.password "password"
|
35
|
+
member.roles { [ Factory(:role, :name => 'member') ] }
|
36
|
+
end
|
37
|
+
|
38
|
+
Factory.define :role do |role|
|
39
|
+
role.sequence(:name) { |n| "Quick #{n}".camelize }
|
40
|
+
end
|
41
|
+
FILE
|
42
|
+
end
|
43
|
+
|
44
|
+
create_file 'features/step_definitions/devise_steps.rb' do
|
45
|
+
<<-'FILE'
|
46
|
+
When /^I log in as "([^\"]*)" with password "([^\"]*)"$/ do |email, password|
|
47
|
+
visit(new_user_session_path)
|
48
|
+
fill_in("user[email]", :with => email)
|
49
|
+
fill_in("user[password]", :with => password)
|
50
|
+
click_button("Sign in")
|
51
|
+
end
|
52
|
+
|
53
|
+
Given /^a logged in admin user$/ do
|
54
|
+
Factory.create(:admin)
|
55
|
+
visit(new_user_session_path)
|
56
|
+
fill_in("user[email]", :with => "quickleft@quickleft.com")
|
57
|
+
fill_in("user[password]", :with => "password")
|
58
|
+
click_button("Sign in")
|
59
|
+
end
|
60
|
+
|
61
|
+
Given /^a logged in member user$/ do
|
62
|
+
Factory.create(:member)
|
63
|
+
visit(new_user_session_path)
|
64
|
+
fill_in("user[email]", :with => "member@quickleft.com")
|
65
|
+
fill_in("user[password]", :with => "password")
|
66
|
+
click_button("Sign in")
|
67
|
+
end
|
68
|
+
|
69
|
+
When /^I log out$/ do
|
70
|
+
visit(destroy_user_session_path)
|
71
|
+
end
|
72
|
+
|
73
|
+
Given /^a user "([^\"]*)"$/ do |email|
|
74
|
+
Factory.create(:user, :email => email)
|
75
|
+
end
|
76
|
+
FILE
|
77
|
+
end
|
78
|
+
|
79
|
+
inject_into_file 'features/support/paths.rb', :after => "case page_name\n" do
|
80
|
+
<<-'FILE'
|
81
|
+
|
82
|
+
when /the admin/
|
83
|
+
'/admin'
|
84
|
+
|
85
|
+
when /logout/
|
86
|
+
'/users/sign_out'
|
87
|
+
|
88
|
+
when /login/
|
89
|
+
'/users/sign_in'
|
90
|
+
FILE
|
91
|
+
end
|
data/templates/devise.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
say "Building authentication"
|
2
|
+
gsub_file 'config/application.rb', /:password/, ':password, :password_confirmation'
|
3
|
+
|
4
|
+
run 'rails generate devise:install'
|
5
|
+
run 'rails generate devise:views'
|
6
|
+
|
7
|
+
gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '### ActionMailer Config'
|
8
|
+
|
9
|
+
gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
|
10
|
+
<<-RUBY
|
11
|
+
config.action_mailer.default_url_options = { :host => '0.0.0.0:3000' }
|
12
|
+
# A dummy setup for development - no deliveries, but logged
|
13
|
+
config.action_mailer.delivery_method = :smtp
|
14
|
+
config.action_mailer.perform_deliveries = false
|
15
|
+
config.action_mailer.raise_delivery_errors = true
|
16
|
+
config.action_mailer.default :charset => "utf-8"
|
17
|
+
RUBY
|
18
|
+
end
|
19
|
+
|
20
|
+
inject_into_file 'config/environments/test.rb', :after => "config.action_controller.allow_forgery_protection = false\n" do
|
21
|
+
<<-RUBY
|
22
|
+
config.action_mailer.default_url_options = { :host => '0.0.0.0:3000' }
|
23
|
+
RUBY
|
24
|
+
end
|
25
|
+
|
26
|
+
gsub_file 'config/environments/production.rb', /config.i18n.fallbacks = true/ do
|
27
|
+
<<-RUBY
|
28
|
+
config.i18n.fallbacks = true
|
29
|
+
config.action_mailer.default_url_options = { :host => 'yourhost.com' }
|
30
|
+
### ActionMailer Config
|
31
|
+
# Setup for production - deliveries, no errors raised
|
32
|
+
config.action_mailer.delivery_method = :smtp
|
33
|
+
config.action_mailer.perform_deliveries = true
|
34
|
+
config.action_mailer.raise_delivery_errors = false
|
35
|
+
config.action_mailer.default :charset => "utf-8"
|
36
|
+
RUBY
|
37
|
+
end
|
38
|
+
|
39
|
+
run 'rails generate devise User'
|
40
|
+
run 'rm app/models/user.rb'
|
41
|
+
|
42
|
+
create_file 'app/models/user.rb' do
|
43
|
+
<<-RUBY
|
44
|
+
class User < ActiveRecord::Base
|
45
|
+
devise :database_authenticatable, :token_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
|
46
|
+
validates_presence_of :name
|
47
|
+
validates_uniqueness_of :name, :email, :case_sensitive => false
|
48
|
+
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
|
49
|
+
has_friendly_id :name, :use_slug => true, :strip_non_ascii => true
|
50
|
+
end
|
51
|
+
RUBY
|
52
|
+
end
|
53
|
+
|
54
|
+
generate(:migration, "AddNameToUsers name:string")
|
55
|
+
generate(:migration, "AddCachedSlugToUsers cached_slug:string")
|
56
|
+
|
57
|
+
create_file 'app/views/devise/menu/_login_items.html.haml' do
|
58
|
+
<<-'FILE'
|
59
|
+
- if user_signed_in?
|
60
|
+
%li
|
61
|
+
= link_to('Logout', destroy_user_session_path)
|
62
|
+
- else
|
63
|
+
%li
|
64
|
+
= link_to('Login', new_user_session_path)
|
65
|
+
%li
|
66
|
+
User:
|
67
|
+
- if current_user
|
68
|
+
= current_user.name
|
69
|
+
- else
|
70
|
+
(not logged in)
|
71
|
+
FILE
|
72
|
+
end
|
73
|
+
|
74
|
+
append_file 'app/views/shared/_header.html.haml' do
|
75
|
+
<<-'FILE'
|
76
|
+
%ul#user_nav
|
77
|
+
= render 'devise/menu/login_items'
|
78
|
+
FILE
|
79
|
+
end
|
80
|
+
|
81
|
+
devise_migration = Dir['db/migrate/*_devise_create_users.rb'].first
|
82
|
+
|
83
|
+
gsub_file devise_migration, /# t.confirmable/, 't.confirmable'
|
84
|
+
gsub_file devise_migration, /# t.token_authenticatable/, 't.token_authenticatable'
|
85
|
+
gsub_file devise_migration, /# add_index :users, :confirmation_token, :unique => true/, 'add_index :users, :confirmation_token, :unique => true'
|
86
|
+
|
87
|
+
append_file 'db/seeds.rb' do
|
88
|
+
<<-FILE
|
89
|
+
User.create! :name => '#{ENV['PROLOGUE_USER_NAME']}', :email => '#{ENV['PROLOGUE_USER_EMAIL']}', :password => '#{ENV['PROLOGUE_USER_PASSWORD']}', :password_confirmation => '#{ENV['PROLOGUE_USER_PASSWORD']}'
|
90
|
+
FILE
|
91
|
+
end
|
92
|
+
|
93
|
+
# make cukes and websteps for devise
|
94
|
+
apply File.expand_path("../devise/cucumber.rb", __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
run 'rails plugin install git://github.com/rails/dynamic_form.git'
|
@@ -0,0 +1 @@
|
|
1
|
+
run 'rails generate friendly_id'
|