Skip to content

Commit

Permalink
Fix up associations in plugin, and tweak application to work with the…
Browse files Browse the repository at this point in the history
…m properly. I think bugs are squashed now. [#44]
  • Loading branch information
marnen committed Oct 23, 2009
1 parent 135039d commit f0d0a68
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
1 change: 0 additions & 1 deletion app/models/event.rb
Expand Up @@ -3,7 +3,6 @@ class Event < ActiveRecord::Base
include GeocodingUtilities

belongs_to :created_by, :class_name => "User"
belongs_to :state, :include => :country
belongs_to :calendar
has_many :commitments
has_many :users, :through => :commitments
Expand Down
1 change: 0 additions & 1 deletion app/models/user.rb
Expand Up @@ -8,7 +8,6 @@ class User < ActiveRecord::Base
include GeocodingUtilities
cattr_accessor :current_user

belongs_to :state
has_many :commitments
has_many :events, :through => :commitments
has_many :permissions
Expand Down
8 changes: 5 additions & 3 deletions spec/models/event_spec.rb
Expand Up @@ -13,9 +13,11 @@
end

it "should belong to a Country" do
opts = Event.reflect_on_association(:state).options
opts.should have_key(:include)
opts[:include].should == :country
pending ":include doesn't seem to be a good idea at all -- must investigate" do
opts = Event.reflect_on_association(:state).options
opts.should have_key(:include)
opts[:include].should == :country
end
end

it "should belong to a Calendar" do
Expand Down
3 changes: 2 additions & 1 deletion vendor/plugins/acts_as_addressed/lib/acts_as_addressed.rb
Expand Up @@ -9,7 +9,8 @@ def self.included(base)
module SingletonMethods
# Includes the acts_as_addressed structure in the model it's called on.
def acts_as_addressed
composed_of :address, :mapping => %w(street street2 city state_id zip coords).collect{|x| [x, x.gsub(/_id$/, '')]}
belongs_to :state, :class_name => "Acts::Addressed::State"
composed_of :address, :class_name => "Acts::Addressed::Address", :mapping => %w(street street2 city state_id zip coords).collect{|x| [x, x.gsub(/_id$/, '')]}
include InstanceMethods
end
end
Expand Down
23 changes: 14 additions & 9 deletions vendor/plugins/acts_as_addressed/spec/acts_as_addressed_spec.rb
Expand Up @@ -2,7 +2,7 @@

describe Acts::Addressed, "inclusion" do
it "should extend SingletonMethods when module is included" do
@active_record = Class.new
@active_record = ActiveRecord::Base
@active_record.should_receive(:extend).with(Acts::Addressed::SingletonMethods)
@active_record.send :include, Acts::Addressed
end
Expand All @@ -16,20 +16,26 @@

describe "effects on model" do
before :each do
@active_record = Class.new
@active_record = ActiveRecord::Base
@active_record.send :include, Acts::Addressed
@model = Class.new @active_record
@model.stub!(:composed_of)
end

it "should create a State association" do
@model.should_receive(:belongs_to).with(:state, :class_name => "Acts::Addressed::State")
end

it "should create an Address aggregation" do
@model.should_receive(:composed_of).with(:address, :mapping => %w(street street2 city state_id zip coords).collect{|x| [x, x.gsub(/_id$/, '')]})
@model.acts_as_addressed
@model.should_receive(:composed_of).with(:address, :class_name => "Acts::Addressed::Address", :mapping => %w(street street2 city state_id zip coords).collect{|x| [x, x.gsub(/_id$/, '')]})
end

it "should include InstanceMethods in the model" do
im = Acts::Addressed::InstanceMethods
@model.should_receive(:include).with(im)

end

after :each do
@model.acts_as_addressed
end
end
Expand All @@ -38,10 +44,9 @@

describe Acts::Addressed::InstanceMethods do
before :each do
@active_record = Class.new
@active_record.send :include, Acts::Addressed
@model = Class.new @active_record
@model.stub!(:composed_of)
ActiveRecord::Base.send :include, Acts::Addressed
@model = Class.new ActiveRecord::Base
@model.set_table_name 'dummies'
@model.acts_as_addressed
@instance = @model.new
end
Expand Down
5 changes: 5 additions & 0 deletions vendor/plugins/acts_as_addressed/spec/spec_helper.rb
Expand Up @@ -52,6 +52,11 @@ def setup_db
t.column "code", :string, :limit => 10, :null => false
t.column "name", :string, :null => false
end

create_table "dummies", :force => true do |t|
# so we have something to use for dummy classes
t.column 'fake', :string
end
end
end
end
Expand Down

0 comments on commit f0d0a68

Please sign in to comment.