Permalink
Browse files

Updated to use new hash syntax.

Changed double-quoted strings without interpolation to use single-quotes.
  • Loading branch information...
1 parent b5bac84 commit 0965e8848fe4c54f012216809b06e99d28d1b088 @jeriko jeriko committed Nov 26, 2011
View
14 lib/generators/active_record/easy_roles_generator.rb
@@ -4,20 +4,20 @@ module ActiveRecord
module Generators
class EasyRolesGenerator < ActiveRecord::Generators::Base
- argument :role_col, :type => :string, :required => false, :default => "roles", :banner => "role column"
+ argument :role_col, type: :string, required: false, default: 'roles', banner: 'role column'
- class_option :use_bitmask_method, :type => :boolean, :required => false, :default => false,
- :desc => "Setup migration for Bitmask method"
+ class_option :use_bitmask_method, type: :boolean, required: false, default: false,
+ desc: 'Setup migration for Bitmask method'
- desc "Internal use by easy_roles generator - use that instead"
+ desc 'Internal use by easy_roles generator - use that instead'
- source_root File.expand_path("../templates", __FILE__)
+ source_root File.expand_path('../templates', __FILE__)
def copy_easy_roles_migration
if options.use_bitmask_method
- migration_template "migration_bitmask.rb", "db/migrate/add_bitmask_roles_to_#{table_name}"
+ migration_template 'migration_bitmask.rb', "db/migrate/add_bitmask_roles_to_#{table_name}"
else
- migration_template "migration_non_bitmask.rb", "db/migrate/add_easy_roles_to_#{table_name}"
+ migration_template 'migration_non_bitmask.rb', "db/migrate/add_easy_roles_to_#{table_name}"
end
end
View
2 lib/generators/active_record/templates/migration_bitmask.rb
@@ -1,6 +1,6 @@
class AddBitmaskRolesTo<%= table_name.camelize %> < ActiveRecord::Migration
def self.up
- add_column :<%= table_name %>, :<%= self.role_col %>, :integer, :default => 0
+ add_column :<%= table_name %>, :<%= self.role_col %>, :integer, default: 0
end
def self.down
View
2 lib/generators/active_record/templates/migration_non_bitmask.rb
@@ -1,6 +1,6 @@
class AddEasyRolesTo<%= table_name.camelize %> < ActiveRecord::Migration
def self.up
- add_column :<%= table_name %>, :<%= self.role_col %>, :string, :default => "--- []"
+ add_column :<%= table_name %>, :<%= self.role_col %>, :string, default: '--- []'
end
def self.down
View
12 lib/generators/easy_roles/easy_roles_generator.rb
@@ -1,21 +1,21 @@
module EasyRoles
module Generators
class EasyRolesGenerator < Rails::Generators::NamedBase
- namespace "easy_roles"
+ namespace 'easy_roles'
- argument :role_col, :type => :string, :required => false, :default => "roles", :banner => "role column"
+ argument :role_col, type: :string, required: false, default: 'roles', banner: 'role column'
- class_option :use_bitmask_method, :type => :boolean, :required => false, :default => false,
- :desc => "Setup migration for Bitmask method"
+ class_option :use_bitmask_method, type: :boolean, required: false, default: false,
+ desc: 'Setup migration for Bitmask method'
- desc "Create ActiveRecord migration for easy_roles on NAME model using [ROLE] column -- defaults to 'roles'"
+ desc 'Create ActiveRecord migration for easy_roles on NAME model using [ROLE] column -- defaults to \'roles\''
source_root File.expand_path('../../templates', __FILE__)
hook_for :orm
def show_readme
- readme "README" if behavior == :invoke
+ readme 'README' if behavior == :invoke
end
end
View
46 spec/easy_roles_spec.rb
@@ -31,17 +31,17 @@
end
it "should return the users role through association" do
- user = BitmaskUser.create(:name => "Bob")
+ user = BitmaskUser.create(name: 'Bob')
user.add_role! "admin"
- membership = Membership.create(:name => "Test Membership", :bitmask_user => user)
+ membership = Membership.create(name: 'Test Membership', bitmask_user: user)
Membership.last.bitmask_user.is_admin?.should be_true
end
it "should get no method error if no easy roles on model" do
begin
- b = Beggar.create(:name => "Ivor")
+ b = Beggar.create(name: 'Ivor')
b.is_admin?
rescue => e
@@ -51,8 +51,8 @@
it "should get no method error if no easy roles on model even through association" do
begin
- b = Beggar.create(:name => "Ivor")
- m = Membership.create(:name => "Beggars club", :beggar => b)
+ b = Beggar.create(name: 'Ivor')
+ m = Membership.create(name: 'Beggars club', beggar: b)
Membership.last.beggar.is_admin?
rescue => e
@@ -62,7 +62,7 @@
describe "normal methods" do
it "should not save to the database if not implicitly saved" do
- user = SerializeUser.create(:name => "Ryan")
+ user = SerializeUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.reload
@@ -71,7 +71,7 @@
end
it "should save to the database if implicity saved" do
- user = SerializeUser.create(:name => "Ryan")
+ user = SerializeUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -81,7 +81,7 @@
end
it "should clear all roles and not save if not implicitly saved" do
- user = SerializeUser.create(:name => "Ryan")
+ user = SerializeUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -96,7 +96,7 @@
end
it "should clear all roles and save if implicitly saved" do
- user = SerializeUser.create(:name => "Ryan")
+ user = SerializeUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -112,7 +112,7 @@
end
it "should remove a role and not save unless implicitly saved" do
- user = SerializeUser.create(:name => "Ryan")
+ user = SerializeUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -127,7 +127,7 @@
end
it "should remove a role and save if implicitly saved" do
- user = SerializeUser.create(:name => "Ryan")
+ user = SerializeUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -145,7 +145,7 @@
describe "bang method" do
it "should save to the database if the bang method is used" do
- user = SerializeUser.create(:name => "Ryan")
+ user = SerializeUser.create(name: 'Ryan')
user.add_role! 'admin'
user.is_admin?.should be_true
user.reload
@@ -154,7 +154,7 @@
end
it "should remove a role and save" do
- user = SerializeUser.create(:name => "Ryan")
+ user = SerializeUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -207,7 +207,7 @@
describe "normal methods" do
it "should not save to the database if not implicitly saved" do
- user = BitmaskUser.create(:name => "Ryan")
+ user = BitmaskUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.reload
@@ -216,7 +216,7 @@
end
it "should save to the database if implicity saved" do
- user = BitmaskUser.create(:name => "Ryan")
+ user = BitmaskUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -226,7 +226,7 @@
end
it "should clear all roles and not save if not implicitly saved" do
- user = BitmaskUser.create(:name => "Ryan")
+ user = BitmaskUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -241,7 +241,7 @@
end
it "should clear all roles and save if implicitly saved" do
- user = BitmaskUser.create(:name => "Ryan")
+ user = BitmaskUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -257,7 +257,7 @@
end
it "should remove a role and not save unless implicitly saved" do
- user = BitmaskUser.create(:name => "Ryan")
+ user = BitmaskUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -272,7 +272,7 @@
end
it "should remove a role and save if implicitly saved" do
- user = BitmaskUser.create(:name => "Ryan")
+ user = BitmaskUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -290,7 +290,7 @@
describe "bang method" do
it "should save to the database if the bang method is used" do
- user = BitmaskUser.create(:name => "Ryan")
+ user = BitmaskUser.create(name: 'Ryan')
user.add_role! 'admin'
user.is_admin?.should be_true
user.reload
@@ -299,7 +299,7 @@
end
it "should remove a role and save" do
- user = BitmaskUser.create(:name => "Ryan")
+ user = BitmaskUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -314,7 +314,7 @@
end
it "should clear all roles and save" do
- user = BitmaskUser.create(:name => "Ryan")
+ user = BitmaskUser.create(name: 'Ryan')
user.add_role 'admin'
user.is_admin?.should be_true
user.save
@@ -329,4 +329,4 @@
end
end
end
-end
+end
View
14 spec/spec_helper.rb
@@ -7,17 +7,17 @@
RSpec.configure do |config|
end
-ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
+ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
def setup_db
- ActiveRecord::Schema.define(:version => 1) do
+ ActiveRecord::Schema.define(version: 1) do
create_table :serialize_users do |t|
t.string :name
- t.string :roles, :default => "--- []"
+ t.string :roles, default: "--- []"
end
create_table :bitmask_users do |t|
t.string :name
- t.integer :roles_mask, :default => 0
+ t.integer :roles_mask, default: 0
end
create_table :memberships do |t|
@@ -41,12 +41,12 @@ def teardown_db
setup_db
class SerializeUser < ActiveRecord::Base
- easy_roles :roles, :method => :serialize
+ easy_roles :roles, method: :serialize
end
class BitmaskUser < ActiveRecord::Base
has_many :memberships
- easy_roles :roles_mask, :method => :bitmask
+ easy_roles :roles_mask, method: :bitmask
ROLES_MASK = %w[admin manager user]
end
@@ -58,4 +58,4 @@ class Membership < ActiveRecord::Base
class Beggar < ActiveRecord::Base
has_many :memberships
-end
+end

0 comments on commit 0965e88

Please sign in to comment.