Skip to content
This repository has been archived by the owner on Feb 9, 2019. It is now read-only.

Commit

Permalink
Added 'aliases' for acts_as_heir_of and acts_as_predecessor and tests…
Browse files Browse the repository at this point in the history
… in the demo
  • Loading branch information
Jered Odegard committed Dec 2, 2011
1 parent fdf8882 commit ffe2ec2
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 28 deletions.
1 change: 1 addition & 0 deletions heritage_demo/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--colour
34 changes: 10 additions & 24 deletions heritage_demo/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,13 @@ gem 'rails', '3.0.6'
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'
gem "heritage", :path => "~/Projects/benjamin/heritage"

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
gem "heritage", :path => '../'

group :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'autotest'
gem 'autotest-fsevent'
gem 'autotest-growl'
gem "heritage", :path => '../'
end
35 changes: 33 additions & 2 deletions heritage_demo/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
PATH
remote: ~/Projects/benjamin/heritage
remote: ../
specs:
heritage (0.3.0)
heritage (0.3.1)

GEM
remote: http://rubygems.org/
specs:
ZenTest (4.6.2)
abstract (1.0.0)
actionmailer (3.0.6)
actionpack (= 3.0.6)
Expand Down Expand Up @@ -34,9 +35,20 @@ GEM
activesupport (= 3.0.6)
activesupport (3.0.6)
arel (2.0.9)
autotest (4.4.6)
ZenTest (>= 4.4.1)
autotest-fsevent (0.2.7)
sys-uname
autotest-growl (0.2.16)
builder (2.1.2)
diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
factory_girl (2.3.2)
activesupport
factory_girl_rails (1.4.0)
factory_girl (~> 2.3.0)
railties (>= 3.0.0)
i18n (0.5.0)
mail (2.2.15)
activesupport (>= 2.3.6)
Expand Down Expand Up @@ -64,7 +76,21 @@ GEM
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)
rspec-rails (2.7.0)
actionpack (~> 3.0)
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.7.0)
sqlite3 (1.3.3)
sys-uname (0.8.6)
thor (0.14.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
Expand All @@ -74,6 +100,11 @@ PLATFORMS
ruby

DEPENDENCIES
autotest
autotest-fsevent
autotest-growl
factory_girl_rails
heritage!
rails (= 3.0.6)
rspec-rails
sqlite3
2 changes: 1 addition & 1 deletion heritage_demo/app/models/blog_post.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class BlogPost < ActiveRecord::Base

acts_as_heir_of :post
child_of :post

validates_presence_of :body
validates_presence_of :title
Expand Down
6 changes: 5 additions & 1 deletion heritage_demo/app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
class Post < ActiveRecord::Base

acts_as_predecessor :exposes => :hello
parent_model :exposes => :hello

belongs_to :category

def hello
"Hi there!"
end

def hidden_hello
"Oh no!"
end

end
4 changes: 4 additions & 0 deletions heritage_demo/spec/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Factory.define :blog_post do |blog_post|
blog_post.body "Hey there!"
blog_post.title "Hello World"
end
17 changes: 17 additions & 0 deletions heritage_demo/spec/models/blog_post_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe BlogPost do
let(:blog_post) { Factory(:blog_post) }

it "should inherit title attribute" do
blog_post.should respond_to :title
end

it "should inherit exposed methods" do
blog_post.should respond_to :hello
end

it "should not inherit non-exposed methods" do
blog_post.should_not respond_to :hidden_hello
end
end
33 changes: 33 additions & 0 deletions heritage_demo/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
end
4 changes: 4 additions & 0 deletions lib/heritage/active_record/acts_as_heir.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Heritage
module ActiveRecord
module ActsAsHeir

def child_of(parent_symbol)
acts_as_heir_of(parent_symbol)
end

def acts_as_heir_of(predecessor_symbol)
extend ClassMethods
Expand Down
4 changes: 4 additions & 0 deletions lib/heritage/active_record/acts_as_predecessor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Heritage
module ActiveRecord
module ActsAsPredecessor

def parent_model(options = {})
acts_as_predecessor(options)
end

def acts_as_predecessor(options = {})
extend ClassMethods
Expand Down

0 comments on commit ffe2ec2

Please sign in to comment.