Frage

So I'm trying to add a subclass to one of my models and then create a fixture and test for it, but I seem to be running into errors along the way. I don't really know how to describe the problem, but I recreated it with the following steps. If you want me to add something to this question please ask.

Console

$ hobo new lab --setup
$ cd lab
$ hobo g model foo num:integer

IDE

#inserted into app/models/foo.rb
def do_foo
    num*5
end

#create app/models/bar.rb
class Bar < Foo
    def doo_foo
        num*10
    end
end

Console

$ hobo g migration

IDE

#create test/fixtures/bars.yml
bar_one:
  num: 1

#create test/unit/bar_test.rb
require 'test_helper'
class BarTest < ActiveSupport::TestCase
  def test_bar
    puts Bar.first.do_foo
    assert true
  end
end

Console

$ rake test

ERROR

1) Error:
test_bar(BarTest):
ActiveRecord::StatementInvalid: Could not find table 'bars'
War es hilfreich?

Lösung

Take out your fixture. Since Bar is a Subclass of Foo it will use the Foos fixture.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top