Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
made the has_role method case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Dec 10, 2013
1 parent 390ae2f commit 5cfdba6
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def admin_instructions
private
def signed_in_with_role_admin
authenticate_user!
redirect_to new_user_session_path, notice: "You are not an admin user" \
unless current_user.has_role?("Admin")
redirect_to root_path, notice: "You are not an admin user" \
unless current_user.has_role?("admin")
end

end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def unset_role(role)
end

def has_role?(*roles)
roles.each { |role| role = role.downcase }
roles.map! { |role| role.downcase }
self.roles.where(name: roles).present?
end

Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20131203170434_create_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ def change

t.timestamps
end
add_index :roles, :names
add_index :roles, :name
end
end
1 change: 0 additions & 1 deletion db/migrate/20131209151725_create_wishes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class CreateWishes < ActiveRecord::Migration
def change
drop_table :wishes
create_table :wishes do |t|
t.datetime :fromtime
t.datetime :totime
Expand Down
2 changes: 2 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
t.datetime "updated_at"
end

add_index "roles", ["name"], name: "index_roles_on_name", using: :btree

create_table "roles_users", force: true do |t|
t.integer "user_id"
t.integer "role_id"
Expand Down
2 changes: 0 additions & 2 deletions spec/views/roles/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
describe "roles/new.html.erb" do
let(:user) { FactoryGirl.create(:user, :admin)}
before do
user.confirmed_at = Time.now
user.save!
sign_in user
visit new_role_path
end
Expand Down

0 comments on commit 5cfdba6

Please sign in to comment.