Forum: Ruby on Rails looking for help with NoMethodError: undefined method `key?' for #<String:0x4795488>

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D74cc7f3b588c1933e5417b99bb1ed59?d=identicon&s=25 Chris (Guest)
on 2009-02-02 13:44
(Received via mailing list)
Hi all,

Any help with this would be appreciated. I'm using instant rails,
updated to 2.2.2, on Windows XP.

I've created my DB and scaffolded a few things and put some fixtures
into place, and when I run the tests I get many errors that look like
this:

 ---------------------------------

  1) Error:
test_the_truth(EntityTest):
NoMethodError: undefined method `key?' for #<String:0x4795488>
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:584:in `insert_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:583:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:583:in `insert_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:577:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:577:in `insert_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:520:in `create_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:520:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:520:in `create_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/connection_adapters/abstract/database_statements.rb:
66:in `transaction'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:518:in `create_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/connection_adapters/mysql_adapter.rb:254:in
`disable_referential_integrity'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:509:in `create_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/base.rb:1398:in `silence'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:508:in `create_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:964:in `load_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/
active_record/fixtures.rb:930:in `setup_fixtures'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/callbacks.rb:178:in `send'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/callbacks.rb:178:in `evaluate_method'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/callbacks.rb:166:in `call'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/callbacks.rb:90:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/callbacks.rb:90:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/callbacks.rb:90:in `send'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/callbacks.rb:90:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/callbacks.rb:277:in `run_callbacks'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/
lib/active_support/testing/setup_and_teardown.rb:58:in `run'

 ---------------------------------

My entity model is dead simple at the moment-
class Entity < ActiveRecord::Base
end

My DB table (entities) has these fields-
id
created_at
updated_at
taxa_order
taxa_family
taxa_genus
taxa_species
common_name
short_description
description

it was created using this migration code-
    create_table :entities do |t|
      t.timestamps
      t.column "taxa_order",        :string, :limit => 127,   :default
=> "", :null => false
      t.column "taxa_family",       :string, :limit => 127,   :default
=> "", :null => false
      t.column "taxa_genus",        :string, :limit => 127,   :default
=> "", :null => false
      t.column "taxa_species",      :string, :limit => 127,   :default
=> "", :null => false
      t.column "common_name",       :string, :limit => 127,   :default
=> "", :null => false
      t.column "short_description", :string, :limit => 255,   :default
=> "", :null => false
      t.column "description", :text,                          :default
=> "", :null => false
    end
    add_index "entities", ["taxa_order"], :name => "taxa_order"
    add_index "entities", ["taxa_family"], :name => "taxa_family"
    add_index "entities", ["taxa_genus"], :name => "taxa_genus"
    add_index "entities", ["taxa_species"], :name => "taxa_species"
    add_index "entities", ["common_name"], :name => "common_name"

and my entities.yml fixture file looks like this-
one:
  taxa_order:testorder
  taxa_family:testfamily
  taxa_genus:testgenus
  taxa_species:testspecies
  common_name:testcommonname
  short_description:this is a short description
  description:this is a longer description, it just goes on and on and
on and on and on and on and on and on and on and on and on and on and
on and on

I suspect the error has something to do with the timestamp stuff
(fixtures.rb:584 seems to refer to time stamp fields), but I have no
idea what exactly is causing the problem, nor how to go about fixing
it. Anyone have any ideas? Thanks!

  -Chris Warren
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-02 13:47
(Received via mailing list)
On 2 Feb 2009, at 03:47, Chris wrote:

>
> Hi all,
>
> Any help with this would be appreciated. I'm using instant rails,
> updated to 2.2.2, on Windows XP.
>
> I've created my DB and scaffolded a few things and put some fixtures
> into place, and when I run the tests I get many errors that look like
> this:

i'd guess it's one of your fixtures (the yml files) that isn't
indented properly

Fred
D74cc7f3b588c1933e5417b99bb1ed59?d=identicon&s=25 Chris Warren (Guest)
on 2009-02-03 02:36
(Received via mailing list)
Thanks! Turned out not to be indenting, but that was the clue I needed
to take a closer look at my fixture syntax. I'd accidentally removed
the space after the : in name value pairs in one of my files. I hadn't
realized how format sensitive yaml is. Now on to the fun stuff...

-Chris



On Mon, Feb 2, 2009 at 7:46 AM, Frederick Cheung
This topic is locked and can not be replied to.