Tôi đang cố gắng trích xuất một tập hợp các mô hình từ ứng dụng Rails 3.2.3 thành đá quý để chúng có thể được sử dụng như một giao diện được chia sẻ giữa các ứng dụng.Thử nghiệm các mô hình ActiveRecord bên trong một viên ngọc?
Tôi di chuyển các mô hình thành một mô-đun và đặt nó trong thư mục lib/invite_interface/invite.rb
module InviteInterface
class Invite < ActiveRecord::Base
belongs_to :user
end
def to_json; end;
def from_json; end;
end
tôi ngồi phịch rspec vào gemfile, đã nhận nó chạy thành công, tạo spec sau:
require 'spec_helper'
describe InviteInterface::EncounterSurvey do
it 'should belong to user' do
subject.should respond_to(:user)
end
end
Thật không may, tôi không thể thực thi rspec trên mô hình, vì bản ghi hoạt động/rspec muốn kết nối đang hoạt động.
1) InviteInterface::Invite should belong to encounter survey set
Failure/Error: subject.should respond_to(:user)
ActiveRecord::ConnectionNotEstablished:
ActiveRecord::ConnectionNotEstablished
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `retrieve_connection'
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/model_schema.rb:228:in `columns'
# /Users/justin/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/model_schema.rb:243:in `column_defaults'
Làm cách nào để ngăn ActiveRecord tìm kiếm kết nối DB?
Cảm ơn Yuri, điều này cuối cùng đã làm việc cho tôi (mặc dù tôi đã phải di chuyển đến minitest từ rspec do các vấn đề sqlite3 đau đớn) –
Điều này là tuyệt vời, đặc biệt. với tùy chọn từ bên dưới: database => ': memory:' – ghayes
@juwiley bạn có thể tư vấn cho tôi nên sử dụng minitest hay rspec dựa trên kinh nghiệm của bạn không. –