guise 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gemfiles/3.1.gemfile.lock +1 -1
- data/gemfiles/3.2.gemfile.lock +1 -1
- data/gemfiles/4.0.gemfile.lock +1 -1
- data/lib/guise/syntax.rb +4 -3
- data/lib/guise/version.rb +1 -1
- data/spec/factories.rb +8 -0
- data/spec/guise_spec.rb +9 -1
- data/spec/spec_helper.rb +20 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 823b5e9bab357ec221cde51785d6c6e8707e7ae2
|
4
|
+
data.tar.gz: 033b80fb3da59c5778ab1f8f566bfa0cf8c37976
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f737e5cfa5dfbd9b7922299a4ec383af710571179d4de71503d92342558f9ac331fe83bb94b129ac1e8f036f37a09ddadd6df41ad13f3b1d215a3a30fe8bd9b
|
7
|
+
data.tar.gz: 961af27e3a10047502402cb1c6c556ab7c0be21365c28aabf6e23b065415f3978640639991efe985800e83502feb46bbde254bfce520896b4d5401fbea70170f
|
data/gemfiles/3.1.gemfile.lock
CHANGED
data/gemfiles/3.2.gemfile.lock
CHANGED
data/gemfiles/4.0.gemfile.lock
CHANGED
data/lib/guise/syntax.rb
CHANGED
@@ -13,6 +13,7 @@ module Guise
|
|
13
13
|
guises = guises.map(&:to_s)
|
14
14
|
association = options.fetch(:association)
|
15
15
|
attribute = options.fetch(:attribute)
|
16
|
+
table_name = options[:table_name] || association
|
16
17
|
|
17
18
|
Guise.registry[self.name] = {
|
18
19
|
names: guises,
|
@@ -22,14 +23,14 @@ module Guise
|
|
22
23
|
|
23
24
|
guises.each do |guise|
|
24
25
|
method_name = guise.underscore
|
25
|
-
scope method_name.pluralize, -> { joins(association).where(
|
26
|
+
scope method_name.pluralize, -> { joins(association).where(table_name => { attribute => guise }) }
|
26
27
|
|
27
28
|
define_method "#{method_name}?" do
|
28
29
|
has_guise?(guise)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
has_many association, options.except(:association, :attribute)
|
33
|
+
has_many association, options.except(:association, :attribute, :table_name)
|
33
34
|
|
34
35
|
if association != :guises
|
35
36
|
association_singular = association.to_s.singularize
|
@@ -66,7 +67,7 @@ module Guise
|
|
66
67
|
association = class_name.to_s.underscore.to_sym
|
67
68
|
guises = guise_options[:names]
|
68
69
|
attribute = guise_options[:attribute]
|
69
|
-
foreign_key = options[:foreign_key] || "#{class_name.underscore}_id"
|
70
|
+
foreign_key = options[:foreign_key] || "#{class_name.to_s.underscore}_id"
|
70
71
|
|
71
72
|
belongs_to association, options.except(:validate)
|
72
73
|
|
data/lib/guise/version.rb
CHANGED
data/spec/factories.rb
CHANGED
data/spec/guise_spec.rb
CHANGED
@@ -22,6 +22,14 @@ describe Guise do
|
|
22
22
|
expect(technicians).not_to include user
|
23
23
|
expect(technicians).not_to include supervisor
|
24
24
|
end
|
25
|
+
|
26
|
+
it 'handles non-standard table names and foreign key attributes' do
|
27
|
+
person = create(:person)
|
28
|
+
create(:permission, person: person)
|
29
|
+
|
30
|
+
expect(person).to have_many :permissions
|
31
|
+
expect(Person.admins).to include person
|
32
|
+
end
|
25
33
|
end
|
26
34
|
|
27
35
|
describe "#has_guise?" do
|
@@ -126,7 +134,7 @@ describe Guise do
|
|
126
134
|
end
|
127
135
|
|
128
136
|
it "unique per resource" do
|
129
|
-
should validate_uniqueness_of(:name).scoped_to(:
|
137
|
+
should validate_uniqueness_of(:name).scoped_to(:user_id)
|
130
138
|
end
|
131
139
|
|
132
140
|
it "is one of the guise names provided" do
|
data/spec/spec_helper.rb
CHANGED
@@ -21,12 +21,20 @@ ActiveRecord::Schema.define do
|
|
21
21
|
|
22
22
|
create_table :user_roles, force: true do |t|
|
23
23
|
t.string :name
|
24
|
-
t.integer :
|
24
|
+
t.integer :user_id
|
25
|
+
end
|
26
|
+
|
27
|
+
create_table :people, force: true do |t|
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table :privileges, force: true do |t|
|
31
|
+
t.integer :employee_id
|
32
|
+
t.string :privilege
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
28
36
|
class User < ActiveRecord::Base
|
29
|
-
has_guises :Technician, :Supervisor, association: :user_roles, attribute: :name
|
37
|
+
has_guises :Technician, :Supervisor, association: :user_roles, attribute: :name
|
30
38
|
end
|
31
39
|
|
32
40
|
class Technician < User
|
@@ -38,14 +46,22 @@ class Supervisor < User
|
|
38
46
|
end
|
39
47
|
|
40
48
|
class UserRole < ActiveRecord::Base
|
41
|
-
guise_for :User
|
42
|
-
foreign_key: :person_id
|
49
|
+
guise_for :User
|
43
50
|
end
|
44
51
|
|
45
52
|
class TechnicianUserRole < UserRole
|
46
53
|
scoped_guise_for :User
|
47
54
|
end
|
48
55
|
|
56
|
+
class Person < ActiveRecord::Base
|
57
|
+
has_guises :Admin, :Manager, :Reviewer, association: :permissions, attribute: :privilege, foreign_key: :employee_id, table_name: :privileges
|
58
|
+
end
|
59
|
+
|
60
|
+
class Permission < ActiveRecord::Base
|
61
|
+
self.table_name = :privileges
|
62
|
+
|
63
|
+
guise_for :Person, foreign_key: :employee_id
|
64
|
+
end
|
49
65
|
|
50
66
|
FactoryGirl.find_definitions
|
51
67
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Gutierrez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|