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.
@@ -1,3 +1,7 @@
1
+ 0.0.5 (2009-02-06)
2
+ ------------------
3
+ - BUGFIX: `belongs_to` now takes `:class_name` (see Employer class in Association spec)
4
+
1
5
  0.0.4 (2009-02-04)
2
6
  ------------------
3
7
  - `has_many :through`
@@ -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.4'
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
- name = ::Extlib::Inflection.camelize(parent.to_s)
56
- klass = ::Extlib::Inflection.constantize(name)
57
- parent_id = self["#{parent.to_s}_id"]
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["#{parent.to_s}_id"])
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
- @employee = @account.employees.first
86
- @employee.account.should == @account
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addywaddy-couch_surfer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Groves