bear 0.0.2 → 0.0.3
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/lib/bear/version.rb +1 -1
- data/templates/admin/cucumber.rb +29 -10
- data/templates/admin/users.rb +2 -0
- data/templates/bootstrap.rb +5 -0
- data/templates/cancan.rb +91 -0
- data/templates/gemfile.rb +2 -1
- data/templates/jammit.rb +1 -1
- data/templates/js.rb +0 -2
- metadata +4 -3
data/lib/bear/version.rb
CHANGED
data/templates/admin/cucumber.rb
CHANGED
@@ -9,6 +9,20 @@ inject_into_file 'features/support/paths.rb', :after => "case page_name\n" do
|
|
9
9
|
FILE
|
10
10
|
end
|
11
11
|
|
12
|
+
create_file 'features/admin.feature' do
|
13
|
+
<<-'FILE'
|
14
|
+
Feature: Admin dashboard
|
15
|
+
As an administrator
|
16
|
+
I want to manage the application
|
17
|
+
So that I can have full control over the site
|
18
|
+
|
19
|
+
Scenario: Login as an admin
|
20
|
+
Given a logged in admin user
|
21
|
+
When I am on the admin
|
22
|
+
Then I should see "Admin"
|
23
|
+
FILE
|
24
|
+
end
|
25
|
+
|
12
26
|
create_file 'features/user_admin.feature' do
|
13
27
|
<<-'FILE'
|
14
28
|
Feature: Administer users
|
@@ -16,25 +30,30 @@ Feature: Administer users
|
|
16
30
|
I want to manage the users
|
17
31
|
So that I can provide support for them
|
18
32
|
|
33
|
+
Background:
|
34
|
+
Given the following role records
|
35
|
+
| name |
|
36
|
+
| Member |
|
37
|
+
|
19
38
|
Scenario: Create, update, delete a user in the admin
|
20
39
|
Given a logged in admin user
|
21
40
|
When I am on the add user page
|
22
|
-
And I fill in "
|
23
|
-
And I fill in "
|
24
|
-
And I fill in "
|
25
|
-
And I fill in "
|
41
|
+
And I fill in "user_name" with "Big Boi"
|
42
|
+
And I fill in "user_email" with "big@yoursite.com"
|
43
|
+
And I fill in "user_password" with "Ch!coDusty$"
|
44
|
+
And I fill in "user_password_confirmation" with "Ch!coDusty$"
|
26
45
|
And I press "Create User"
|
27
46
|
Then I should see "User created!"
|
28
47
|
And I should see "Big Boi"
|
29
48
|
|
30
49
|
When I follow "Big Boi"
|
31
|
-
Then the "
|
32
|
-
And the "
|
50
|
+
Then the "user_name" field should contain "Big Boi"
|
51
|
+
And the "user_email" field should contain "big@yoursite.com"
|
33
52
|
|
34
|
-
|
35
|
-
|
36
|
-
And
|
37
|
-
Then I
|
53
|
+
When I follow "Bigger Boi"
|
54
|
+
Then the "user_name" field should contain "Bigger Boi"
|
55
|
+
And the "user_email" field should contain "bigger@yoursite.com"
|
56
|
+
Then I press "Update User"
|
38
57
|
|
39
58
|
Then I follow "Delete"
|
40
59
|
Then I should see "User deleted."
|
data/templates/admin/users.rb
CHANGED
@@ -23,6 +23,7 @@ end
|
|
23
23
|
inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def create\n" do
|
24
24
|
<<-'FILE'
|
25
25
|
@user = User.new
|
26
|
+
# attr_accessor logic here
|
26
27
|
@user.attributes = params[:user]
|
27
28
|
if @user.save
|
28
29
|
flash[:notice] = "User created!"
|
@@ -37,6 +38,7 @@ inject_into_file 'app/controllers/admin/users_controller.rb', :after => "def upd
|
|
37
38
|
<<-'FILE'
|
38
39
|
params[:user].delete(:password) if params[:user][:password].blank?
|
39
40
|
params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
|
41
|
+
# attr_accessor logic here
|
40
42
|
if @user.update_attributes(params[:user])
|
41
43
|
flash[:notice] = "Successfully updated #{@user.name}."
|
42
44
|
redirect_to(admin_users_url)
|
data/templates/bootstrap.rb
CHANGED
@@ -21,6 +21,8 @@ append_file ".gitignore" do
|
|
21
21
|
".bundle"
|
22
22
|
"capybara-*.html"
|
23
23
|
"config/database.yml"
|
24
|
+
"coverage.data"
|
25
|
+
"coverage/**/*"
|
24
26
|
"log/*.log"
|
25
27
|
"public/stylesheets/compiled/"
|
26
28
|
"public/system/**/**/**/*"
|
@@ -63,6 +65,9 @@ apply File.expand_path("../devise.rb", __FILE__) if ENV["BEAR_AUTH"]
|
|
63
65
|
# Apply admin
|
64
66
|
apply File.expand_path("../admin.rb", __FILE__) if ENV["BEAR_ADMIN"]
|
65
67
|
|
68
|
+
# Apply cancan
|
69
|
+
apply File.expand_path("../cancan.rb", __FILE__) if ENV['BEAR_ROLES']
|
70
|
+
|
66
71
|
# Apply db create and migrations
|
67
72
|
apply File.expand_path("../db.rb", __FILE__)
|
68
73
|
|
data/templates/cancan.rb
ADDED
@@ -0,0 +1,91 @@
|
|
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
|
+
|
29
|
+
def self.sanitize role
|
30
|
+
role.to_s.humanize.split(" ").each{ |word| word.capitalize! }.join(" ")
|
31
|
+
end
|
32
|
+
RUBY
|
33
|
+
end
|
34
|
+
|
35
|
+
create_file 'app/models/ability.rb' do
|
36
|
+
<<-RUBY
|
37
|
+
class Ability
|
38
|
+
include CanCan::Ability
|
39
|
+
|
40
|
+
def initialize(user)
|
41
|
+
user ||= User.new # guest user
|
42
|
+
|
43
|
+
if user.role?(:admin)
|
44
|
+
can :manage, :all
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
RUBY
|
49
|
+
end
|
50
|
+
|
51
|
+
inject_into_file 'app/models/user.rb', :before => "def destroy\n" do
|
52
|
+
<<-RUBY
|
53
|
+
|
54
|
+
def role?(role)
|
55
|
+
return !!self.roles.find_by_name(Role.sanitize(role))
|
56
|
+
end
|
57
|
+
|
58
|
+
RUBY
|
59
|
+
end
|
60
|
+
|
61
|
+
inject_into_file 'app/controllers/application_controller.rb', :before => "end\n" do
|
62
|
+
<<-RUBY
|
63
|
+
|
64
|
+
rescue_from(CanCan::AccessDenied) do |exception|
|
65
|
+
flash[:error] = "Access Denied"
|
66
|
+
redirect_to(root_url)
|
67
|
+
end
|
68
|
+
RUBY
|
69
|
+
end
|
70
|
+
|
71
|
+
if ENV['BEAR_ADMIN']
|
72
|
+
inject_into_file 'app/views/admin/users/_form.html.haml', :after => "= f.inputs(:name, :email, :password, :password_confirmation)\n" do
|
73
|
+
<<-'RUBY'
|
74
|
+
= f.input(:role_ids, :as => :check_boxes, :collection => Role.order(:name))
|
75
|
+
= hidden_field_tag("user[role_ids][]", "")
|
76
|
+
RUBY
|
77
|
+
end
|
78
|
+
|
79
|
+
gsub_file "app/controllers/admin/users_controller.rb", /# attr_accessor logic here/, "@user.accessible = [ :role_ids ] if current_user.role?(:admin)"
|
80
|
+
end
|
81
|
+
|
82
|
+
append_file 'db/seeds.rb' do
|
83
|
+
<<-FILE
|
84
|
+
Role.create!(:name => "Admin")
|
85
|
+
Role.create!(:name => "Member")
|
86
|
+
|
87
|
+
user1 = User.find_by_email("#{ENV['BEAR_USER_EMAIL']}")
|
88
|
+
user1.role_ids = [ 1, 2 ]
|
89
|
+
user1.save!
|
90
|
+
FILE
|
91
|
+
end
|
data/templates/gemfile.rb
CHANGED
@@ -6,9 +6,10 @@ gem "rails", "~> 3.0.0"
|
|
6
6
|
gem "autotest", :group => [ :test ]
|
7
7
|
gem "autotest-rails", :group => [ :test ]
|
8
8
|
gem "bistro_car"
|
9
|
+
gem "cancan" if ENV["BEAR_ROLES"]
|
9
10
|
gem "capybara", "0.4.0", :group => [ :cucumber ]
|
10
11
|
gem "carrierwave", "0.5.0"
|
11
|
-
gem "cover_me", ">= 1.0.0.
|
12
|
+
gem "cover_me", ">= 1.0.0.rc4", :group => [ :test ]
|
12
13
|
gem "css_sprite", "1.4.10"
|
13
14
|
gem "cucumber", :group => [ :cucumber ]
|
14
15
|
gem "cucumber-rails", :group => [ :cucumber ]
|
data/templates/jammit.rb
CHANGED
data/templates/js.rb
CHANGED
@@ -1,4 +1,2 @@
|
|
1
1
|
get "http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js", "public/javascripts/jquery.js"
|
2
2
|
get_remote_https_file "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails.js"
|
3
|
-
get "http://html5shiv.googlecode.com/svn/trunk/html5.js", "public/javascripts/shiv.js"
|
4
|
-
run "rm public/javascripts/application.js"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Russ Smith
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- templates/admin/users_spec.rb
|
133
133
|
- templates/application_layout.rb
|
134
134
|
- templates/bootstrap.rb
|
135
|
+
- templates/cancan.rb
|
135
136
|
- templates/clean_routes.rb
|
136
137
|
- templates/db.rb
|
137
138
|
- templates/db_seed.rb
|
@@ -180,6 +181,6 @@ rubyforge_project: bear
|
|
180
181
|
rubygems_version: 1.3.7
|
181
182
|
signing_key:
|
182
183
|
specification_version: 3
|
183
|
-
summary: bear-0.0.
|
184
|
+
summary: bear-0.0.3
|
184
185
|
test_files: []
|
185
186
|
|