addywaddy-couch_surfer 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/couch_surfer.rb +1 -1
- data/lib/couch_surfer/associations.rb +6 -5
- data/spec/lib/associations_spec.rb +6 -3
- metadata +1 -1
data/CHANGELOG.md
CHANGED
data/lib/couch_surfer.rb
CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module CouchSurfer
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.5'
|
6
6
|
autoload :Model, 'couch_surfer/model'
|
7
7
|
autoload :Validations, 'couch_surfer/validations'
|
8
8
|
autoload :Associations, 'couch_surfer/associations'
|
@@ -35,7 +35,7 @@ module CouchSurfer
|
|
35
35
|
if options[:through]
|
36
36
|
define_method_for_children(options[:through], options)
|
37
37
|
define_method children do
|
38
|
-
name = options[:class_name] || children.to_s.singular
|
38
|
+
name = (options[:class_name] || children).to_s.singular
|
39
39
|
class_name = ::Extlib::Inflection.camelize(name)
|
40
40
|
klass = ::Extlib::Inflection.constantize(class_name)
|
41
41
|
through_items = self.send("#{options[:through]}")
|
@@ -51,12 +51,13 @@ module CouchSurfer
|
|
51
51
|
def belongs_to *args
|
52
52
|
options = extract_options!(args)
|
53
53
|
parent = args.first
|
54
|
+
parent_name = (options[:class_name] || parent).to_s
|
54
55
|
define_method parent do
|
55
|
-
|
56
|
-
klass = ::Extlib::Inflection.constantize(
|
57
|
-
parent_id = self["#{
|
56
|
+
class_name = ::Extlib::Inflection.camelize(parent_name)
|
57
|
+
klass = ::Extlib::Inflection.constantize(class_name)
|
58
|
+
parent_id = self["#{parent_name}_id"]
|
58
59
|
if parent_id
|
59
|
-
klass.send(:get, self["#{
|
60
|
+
klass.send(:get, self["#{parent_name}_id"])
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
@@ -50,7 +50,7 @@ class Employee
|
|
50
50
|
|
51
51
|
key_accessor :email, :account_id, :role
|
52
52
|
|
53
|
-
belongs_to :account
|
53
|
+
belongs_to :employer, :class_name => :account
|
54
54
|
has_many :shirts, :inline => true
|
55
55
|
has_many :projects, :through => :memberships
|
56
56
|
|
@@ -82,8 +82,11 @@ describe CouchSurfer::Associations do
|
|
82
82
|
|
83
83
|
describe "belongs_to" do
|
84
84
|
it "should return it's parent" do
|
85
|
-
@
|
86
|
-
|
85
|
+
@project.account.should == @account
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should take the class_name into consideration" do
|
89
|
+
@employee.employer.should == @account
|
87
90
|
end
|
88
91
|
end
|
89
92
|
|