Skip to content

Commit

Permalink
I want to be able to have ActiveHash classes ending with an 's' (such…
Browse files Browse the repository at this point in the history
… as 'SchoolStatus'). String#classify do not handles singular names correctly (see http://apidock.com/rails/String/classify)
  • Loading branch information
jmonteiro committed Oct 6, 2012
1 parent 7d1f6ae commit 451ae23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/associations/associations.rb
Expand Up @@ -5,7 +5,7 @@ module ActiveRecordExtensions

def belongs_to_active_hash(association_id, options = {})
options = {
:class_name => association_id.to_s.classify,
:class_name => association_id.to_s.camelize,
:foreign_key => association_id.to_s.foreign_key
}.merge(options)

Expand Down
10 changes: 10 additions & 0 deletions spec/associations/associations_spec.rb
Expand Up @@ -26,6 +26,9 @@ class Author < ActiveHash::Base
include ActiveHash::Associations
end

class SchoolStatus < ActiveHash::Base
end

class Book < ActiveRecord::Base
establish_connection :adapter => "sqlite3", :database => ":memory:"
connection.create_table(:books, :force => true) do |t|
Expand Down Expand Up @@ -133,6 +136,13 @@ class Book < ActiveRecord::Base
association.should_not be_nil
association.klass.name.should == City.name
end

it "handles classes ending with an 's'" do
School.belongs_to_active_hash :school_status
association = School.reflect_on_association(:school_status)
association.should_not be_nil
association.klass.name.should == SchoolStatus.name
end
end
end

Expand Down

0 comments on commit 451ae23

Please sign in to comment.