forked from aiwilliams/dataset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug where sti finder names would not be generated correctly
- Loading branch information
1 parent
488874c
commit 47691cc
Showing
10 changed files
with
130 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
:patch: 1 | ||
:patch: 2 | ||
:major: 1 | ||
:minor: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,11 @@ | |
|
||
Gem::Specification.new do |s| | ||
s.name = %q{dataset} | ||
s.version = "1.3.1" | ||
s.version = "1.3.2" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["Adam Williams"] | ||
s.date = %q{2009-12-22} | ||
s.date = %q{2009-12-29} | ||
s.description = %q{A simple API for creating and finding sets of data in your database, built on ActiveRecord.} | ||
s.email = %q{[email protected]} | ||
s.extra_rdoc_files = [ | ||
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s| | |
"lib/dataset/instance_methods.rb", | ||
"lib/dataset/load.rb", | ||
"lib/dataset/record/fixture.rb", | ||
"lib/dataset/record/heirarchy.rb", | ||
"lib/dataset/record/meta.rb", | ||
"lib/dataset/record/model.rb", | ||
"lib/dataset/resolver.rb", | ||
|
@@ -54,7 +55,7 @@ Gem::Specification.new do |s| | |
s.test_files = [ | ||
"spec/dataset/cucumber_spec.rb", | ||
"spec/dataset/database/base_spec.rb", | ||
"spec/dataset/record/meta_spec.rb", | ||
"spec/dataset/record/heirarchy_spec.rb", | ||
"spec/dataset/resolver_spec.rb", | ||
"spec/dataset/rspec_spec.rb", | ||
"spec/dataset/session_binding_spec.rb", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Dataset | ||
module Record # :nodoc: | ||
|
||
class Heirarchy # :nodoc: | ||
attr_reader :base_class, :class_name, :columns, :table_name | ||
|
||
delegate :inheritance_column, :to => :base_class | ||
|
||
def initialize(base_class) | ||
@base_class = base_class | ||
@class_name = base_class.name | ||
@table_name = base_class.table_name | ||
@columns = base_class.columns | ||
end | ||
|
||
def id_cache_key | ||
@id_cache_key ||= table_name | ||
end | ||
|
||
def id_finder_names | ||
@id_finder_names ||= [id_finder_name(base_class)] | ||
end | ||
|
||
def model_finder_names | ||
@model_finder_names ||= [model_finder_name(base_class)] | ||
end | ||
|
||
def to_s | ||
"#<Heirarchy: #{table_name}>" | ||
end | ||
|
||
def update(record_class) | ||
record_class.ancestors.each do |c| | ||
finder_name = model_finder_name(c) | ||
unless model_finder_names.include?(finder_name) | ||
model_finder_names << finder_name | ||
id_finder_names << id_finder_name(c) | ||
end | ||
end | ||
end | ||
|
||
def finder_name(klass) | ||
klass.name.underscore.gsub('/', '_').sub(/^(\w)_/, '\1').gsub(/_(\w)_/, '_\1') | ||
end | ||
|
||
def id_finder_name(klass) | ||
"#{finder_name(klass)}_id".to_sym | ||
end | ||
|
||
def model_finder_name(klass) | ||
finder_name(klass).pluralize.to_sym | ||
end | ||
|
||
def timestamp_columns | ||
@timestamp_columns ||= begin | ||
timestamps = %w(created_at created_on updated_at updated_on) | ||
columns.select do |column| | ||
timestamps.include?(column.name) | ||
end | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') | ||
|
||
class MThingy | ||
class NThingy | ||
end | ||
end | ||
|
||
describe Dataset::Record::Heirarchy, 'finder name' do | ||
it 'should collapse single character followed by underscore to just the single character' do | ||
@heirarchy = Dataset::Record::Heirarchy.new(Place) | ||
@heirarchy.finder_name(MThingy).should == 'mthingy' | ||
@heirarchy.finder_name(MThingy::NThingy).should == 'mthingy_nthingy' | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters