저는 현재 매우 오래된 Rails 1.x 플러그인을 Rails4 호환 보석으로 변환하려고합니다. 나는 코드를 다시 작성 관리하고, 프레임 워크 및 실행을 얻었으나, 테스트는 현재 다음과 같은 오류로 실패했습니다 : 나는 나에게 꽤 많은 일을했다오래된 소스의 보석을 테스트하십시오.
ActiveRecord::RecordNotFound: Couldn't find all Pages with 'id': (first, {:conditions=>["url_slug = ? and parent_id IS NULL", "original-page"]}) (found 0 results, but was looking for 2)
하지만 오류가있는 코드를 던지고 여기에 : 나는 액티브/지원에서의 TestCase를 사용하여 기본 설정으로 테스트를 실행하고 SQLite는 실행 메모리 데이터베이스에이있어
acts_as_slugable_class.transaction do
while existing != nil
existing = acts_as_slugable_class.find(:first, conditions: ["#{slug_column} = ? and #{slug_scope_condition}", proposed_slug + suffix])
if existing
if suffix.empty?
suffix = "-0"
else
suffix.succ!
end
end
end
end
. database.yml을 파일 : 나는 기존의 문장의 끝에 구조 전무를 추가
test:
adapter: sqlite3
database: ":memory:"
, 모든 테스트는 고유성 검사를 제외하고 전달합니다. 이처럼 내 test_helper.rb 파일이 모습입니다 : 그것은 해킹의 약간의
# Configure Rails Environment
$:.unshift(File.dirname(__FILE__) + '/../lib')
ENV['RAILS_ENV'] = 'test'
require 'rails'
require 'rails/test_help'
require 'active_record'
require 'active_support'
require 'yaml'
require 'acts_as_slugable'
Rails.backtrace_cleaner.remove_silencers!
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
# Load fixtures from the engine
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
end
# run the database migrations
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
ActiveRecord::Base.establish_connection(config[ENV['RAILS_ENV']])
load(File.dirname(__FILE__) + '/schema.rb')
, 그러나 나는 또한 나의 GitHub의에 소스 코드를 업로드했습니다. 사람이 그것으로 수리를하고 아무것도 DB로 간다 왜 나를 도와하고자하는 경우 :
https://github.com/NekoNova/acts_as_slugable
이것을 테스트하십시오. 여전히 오래된 Syntax가 많이 있습니다.이 작업을 수행하기 위해 단계별로 작업하고 있습니다. –
그것은 굉장하다. 감사합니다. 동위 원소 :) –
매우 환영합니다 :) – TomDunning