Skip to content

Commit

Permalink
Fixed a bug with a class name that contains 'Page'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert Hajee authored and Bert Hajee committed Jun 25, 2013
1 parent d6ff039 commit fcc11a8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
page_record (0.2.0)
page_record (0.2.1)
activesupport
capybara (~> 2.1.0)

Expand Down
11 changes: 8 additions & 3 deletions lib/page_record/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ def self.add_attributes(extra_attributes)

# @private
def self.set_type_name(base)
@host_name = base.to_s.gsub('Page', '')
@type = @host_name.underscore
@host_class = @host_name.constantize
begin
@host_name = base.to_s.gsub('Page', '')
@type = @host_name.underscore
@host_class = @host_name.constantize
rescue NameError
@host_name = ''
@host_class = ''
end
end

# @private
Expand Down
2 changes: 1 addition & 1 deletion lib/page_record/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PageRecord
VERSION = "0.2.0"
VERSION = "0.2.1"
end
23 changes: 22 additions & 1 deletion spec/page_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ def self.attribute_names
[ 'id' , 'name', 'points', 'ranking', 'goals']
end
end
class CamelCasePage < PageRecord::Base; end
end

after do
Object.send(:remove_const, :CamelCasePage)
end


context "no type given" do

before do
class CamelCasePage < PageRecord::Base; end
end

it "returns the internal type of the class " do
expect( CamelCasePage.type).to eq "camel_case"
end
Expand Down Expand Up @@ -537,5 +545,18 @@ class FunnyRecord < PageRecord::Base
pending
end

describe "found bugs" do

describe "class name contains word page but doens't exist" do

it "doesn'throw exception" do
expect { class RubbishPage < PageRecord::Base; end }.not_to raise_error
end

end


end


end

0 comments on commit fcc11a8

Please sign in to comment.