Browse files

Merge pull request #4 from JeredOdegard/test-and-alias

Alias acts_as_heir_of and acts_as_predecessor
  • Loading branch information...
2 parents fdf8882 + 0a241d0 commit 8acad527a8a81e93a58160cae733605cd6f34fa6 @dipth committed Dec 23, 2011
View
14 Gemfile.lock
@@ -0,0 +1,14 @@
+PATH
+ remote: .
+ specs:
+ heritage (0.3.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ heritage!
View
1 heritage_demo/.rspec
@@ -0,0 +1 @@
+--colour
View
33 heritage_demo/Gemfile
@@ -6,27 +6,12 @@ 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'
+end
View
35 heritage_demo/Gemfile.lock
@@ -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)
@@ -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)
@@ -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)
@@ -74,6 +100,11 @@ PLATFORMS
ruby
DEPENDENCIES
+ autotest
+ autotest-fsevent
+ autotest-growl
+ factory_girl_rails
heritage!
rails (= 3.0.6)
+ rspec-rails
sqlite3
View
2 heritage_demo/app/models/blog_post.rb
@@ -1,6 +1,6 @@
class BlogPost < ActiveRecord::Base
- acts_as_heir_of :post
+ child_of :post
validates_presence_of :body
validates_presence_of :title
View
6 heritage_demo/app/models/post.rb
@@ -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
View
4 heritage_demo/spec/factories.rb
@@ -0,0 +1,4 @@
+Factory.define :blog_post do |blog_post|
+ blog_post.body "Hey there!"
+ blog_post.title "Hello World"
+end
View
17 heritage_demo/spec/models/blog_post_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe BlogPost do
+ let(:blog_post) { Factory(:blog_post) }
+
+ it "should inherit attributes" 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
View
33 heritage_demo/spec/spec_helper.rb
@@ -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
View
9 heritage_demo/test/fixtures/blog_posts.yml
@@ -1,9 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
- predecessor_id: 1
- body: MyText
-
-two:
- predecessor_id: 1
- body: MyText
View
11 heritage_demo/test/fixtures/categories.yml
@@ -1,11 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-# This model initially had no columns defined. If you add columns to the
-# model remove the '{}' from the fixture names and add the columns immediately
-# below each fixture, per the syntax in the comments below
-#
-one: {}
-# column: value
-#
-two: {}
-# column: value
View
9 heritage_demo/test/fixtures/image_posts.yml
@@ -1,9 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
- predecessor_id: 1
- aspect: 1
-
-two:
- predecessor_id: 1
- aspect: 1
View
11 heritage_demo/test/fixtures/posts.yml
@@ -1,11 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-one:
- heir_id: 1
- heir_type: MyString
- title: MyString
-
-two:
- heir_id: 1
- heir_type: MyString
- title: MyString
View
8 heritage_demo/test/functional/blog_posts_controller_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class BlogPostsControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
8 heritage_demo/test/functional/image_posts_controller_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class ImagePostsControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
8 heritage_demo/test/functional/posts_controller_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class PostsControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
9 heritage_demo/test/performance/browsing_test.rb
@@ -1,9 +0,0 @@
-require 'test_helper'
-require 'rails/performance_test_help'
-
-# Profiling results for each test method are written to tmp/performance.
-class BrowsingTest < ActionDispatch::PerformanceTest
- def test_homepage
- get '/'
- end
-end
View
13 heritage_demo/test/test_helper.rb
@@ -1,13 +0,0 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/test_help'
-
-class ActiveSupport::TestCase
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
- #
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
- # -- they do not yet inherit this setting
- fixtures :all
-
- # Add more helper methods to be used by all tests here...
-end
View
8 heritage_demo/test/unit/blog_post_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class BlogPostTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
8 heritage_demo/test/unit/category_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class CategoryTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
4 heritage_demo/test/unit/helpers/blog_posts_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class BlogPostsHelperTest < ActionView::TestCase
-end
View
4 heritage_demo/test/unit/helpers/image_posts_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class ImagePostsHelperTest < ActionView::TestCase
-end
View
4 heritage_demo/test/unit/helpers/posts_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class PostsHelperTest < ActionView::TestCase
-end
View
8 heritage_demo/test/unit/image_post_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class ImagePostTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
8 heritage_demo/test/unit/post_test.rb
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class PostTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
View
4 lib/heritage/active_record/acts_as_heir.rb
@@ -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
View
4 lib/heritage/active_record/acts_as_predecessor.rb
@@ -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

0 comments on commit 8acad52

Please sign in to comment.