I''m probably a bit slow today, and I get the feeling I must be doing
something completely stupid here. Here''s some pretty darn simple code,
using a postgresql connection:
require ''active_record''
class Restaurant < ::ActiveRecord::Base
def self.table_name
self.name.gsub(/.*::/, '''').downcase
end
def self.primary_key
table_name + "_id"
end
end
class TC_Restaurant < Test::Unit::TestCase
def setup
super
::ActiveRecord::Base.establish_connection(
$db_connection_factory.params[''olap''].activerecord_spec)
::ActiveRecord::Base.connection.execute(
"SET search_path TO ''unit_test_tabemo_olap''")
end
def test_load
restaurant = Restaurant.find(42);
assert_not_nil(restaurant)
assert_equal("42", restaurant.id)
assert_equal(''The Test Restaurant'',
restaurant.restaurant_desc)
end
def test_create
restaurant = Restaurant.new(''restaurant_id'' => 43,
''restaurant_desc'' => ''created'')
end
end
Reading works just fine. However, I can''t create a new Restaurant:
1) Error:
test_create(TC_Restaurant):
NoMethodError: undefined method `restaurant_desc='' for
#<Restaurant:0x8523a6c>
/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:817:in
`method_missing''
/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:712:in `send''
/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:712:in
`attributes=''
/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:711:in `each''
/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:711:in
`attributes=''
/u/cjs/tabemo/install/lib/ruby/active_record/base.rb:624:in
`initialize_without_callbacks''
/u/cjs/tabemo/install/lib/ruby/active_record/callbacks.rb:212:in
`initialize''
/u/cjs/tabemo/mobile-website/ruby/lib/tabemo/db/restaurant.rb:37:in
`new''
/u/cjs/tabemo/mobile-website/ruby/lib/tabemo/db/restaurant.rb:37:in
`test_create''
What''s am I doing wrong here?
cjs
--
Curt Sampson <cjs-gHs2Wiolu3leoWH0uzbU5w@public.gmane.org> +81 90 7737
2974 http://www.NetBSD.org
Make up enjoying your city life...produced by BIC CAMERA