Skip to content

Commit

Permalink
taxonomies now have post associations
Browse files Browse the repository at this point in the history
  • Loading branch information
robwilliams committed Sep 7, 2011
1 parent 03e86bc commit f48e71a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions Guardfile
@@ -1,6 +1,7 @@
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^spec/factories/.+\.rb$}) { "spec/" }
watch(%r{^spec/support/.+\.rb$}) { "spec/" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec/" }
watch('spec/test_schema.rb') { "spec/" }
Expand Down
3 changes: 2 additions & 1 deletion lib/active_press/taxonomy.rb
Expand Up @@ -8,7 +8,8 @@ def self.included(base)

belongs_to :term, :foreign_key => "term_id"
has_many :term_relationships, :foreign_key => "term_taxonomy_id"

has_many :posts, :through => :term_relationships

delegate :name, :to => :term
delegate :slug, :to => :term
end
Expand Down
3 changes: 1 addition & 2 deletions spec/models/category_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'

describe ActivePress::Category do
it { should belong_to(:term) }
it { should have_many(:term_relationships) }
it_should_behave_like "a Taxonomy"
end
3 changes: 1 addition & 2 deletions spec/models/tag_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'

describe ActivePress::Tag do
it { should belong_to(:term) }
it { should have_many(:term_relationships) }
it_should_behave_like "a Taxonomy"
end
25 changes: 14 additions & 11 deletions spec/models/term_taxonomy_spec.rb
Expand Up @@ -2,19 +2,22 @@

describe ActivePress::TermTaxonomy do

before(:all) {@term_taxonomy = FactoryGirl.build(:term_taxonomy, :term => FactoryGirl.build(:term))}
subject {@term_taxonomy}

it { should belong_to(:term) }
it { should have_many(:term_relationships) }

describe :name do
subject {@term_taxonomy.name}
specify { should eql(@term_taxonomy.term.name) }
end

describe :slug do
subject {@term_taxonomy.slug}
specify { should eql(@term_taxonomy.term.slug) }
context "with a term" do

before(:all) {@term_taxonomy = FactoryGirl.build(:term_taxonomy, :term => FactoryGirl.build(:term))}
subject {@term_taxonomy}

describe :name do
subject {@term_taxonomy.name}
specify { should eql(@term_taxonomy.term.name) }
end

describe :slug do
subject {@term_taxonomy.slug}
specify { should eql(@term_taxonomy.term.slug) }
end
end
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -3,6 +3,9 @@
require 'shoulda/matchers'
require 'factory_girl'


Dir.glob(File.dirname(__FILE__) + '/support/*') {|file| require file}

#ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ":memory:")
ActiveRecord::Migration.verbose = false
Expand Down
5 changes: 5 additions & 0 deletions spec/support/taxonomy_shared_example.rb
@@ -0,0 +1,5 @@
shared_examples_for "a Taxonomy" do
it { should belong_to(:term) }
it { should have_many(:term_relationships) }
it { should have_many(:posts).through(:term_relationships) }
end

0 comments on commit f48e71a

Please sign in to comment.