Last active
August 29, 2015 14:08
-
-
Save mhinton/4fc1328bbe071d7a62ef to your computer and use it in GitHub Desktop.
Namespaced fixtures/models failing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/rails g model admin/player first_name:string last_name:string position:string years_in_league:integer | |
bin/rake db:migrate | |
bin/rake test TEST=test/models/admin/player_test | |
Started with run options --seed 20010 | |
Admin::Player | |
test_0001_must be valid ERROR (0.23s) | |
ActiveRecord::StatementInvalid: ActiveRecord::StatementInvalid: Mysql2::Error: Table 'player_test.players' doesn't exist: SHOW FULL FIELDS FROM `players` | |
config/database.yml | |
# MySQL. Versions 5.0+ are recommended. | |
# | |
# Install the MYSQL driver | |
# gem install mysql2 | |
# | |
# Ensure the MySQL gem is defined in your Gemfile | |
# gem 'mysql2' | |
# | |
# And be sure to use new-style password hashing: | |
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html | |
# | |
default: &default | |
adapter: mysql2 | |
encoding: utf8 | |
pool: 5 | |
username: <%= ENV['DEV_DATABASE_USER'] %> | |
password: <%= ENV['DEV_DATABASE_PASSWORD'] %> | |
host: localhost | |
development: | |
<<: *default | |
database: player_development | |
# Warning: The database defined as "test" will be erased and | |
# re-generated from your development database when you run "rake". | |
# Do not set this db to the same as development or production. | |
test: | |
<<: *default | |
database: player_test | |
app/models/admin.rb | |
module Admin | |
def self.table_name_prefix | |
'admin_' | |
end | |
end | |
app/models/admin/player.rb | |
class Admin::Player < ActiveRecord::Base | |
end | |
test/fixtures/admin/players.yml | |
one: | |
first_name: MyString | |
last_name: MyString | |
position: MyString | |
years_in_league: 1 | |
two: | |
first_name: MyString | |
last_name: MyString | |
position: MyString | |
years_in_league: 1 | |
test/models/admin/player_test.rb | |
require "test_helper" | |
describe Admin::Player do | |
let(:player) { Admin::Player.new } | |
it "must be valid" do | |
player.must_be :valid? | |
end | |
end | |
test/test_helper.rb | |
ENV['RAILS_ENV'] = 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rails/test_help' | |
require 'minitest/rails' | |
require 'minitest/reporters' | |
reporter_options = { color: true } | |
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new(reporter_options)] | |
class ActiveSupport::TestCase | |
ActiveRecord::Migration.check_pending! | |
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. | |
# | |
# Note: You'll currently still have to declare fixtures explicitly in integration tests | |
# -- they do not yet inherit this setting | |
fixtures :all | |
# Add more helper methods to be used by all tests here... | |
extend MiniTest::Spec::DSL | |
register_spec_type self do |desc| | |
desc < ActiveRecord::Base if desc.is_a? Class | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment