2013-01-16 24 views
7

Tôi mới để dưa leo và tôi đang học BDDlỗi sql không thể bắt đầu một giao dịch trong một giao dịch trong khi thử nghiệm với dưa chuột

Khi tôi đang cố gắng để điền vào một mẫu đơn và tạo một bản ghi lỗi sql này được thể hiện , mặc dù không có lỗi khi tôi thử mã thủ công trong trình duyệt của mình.

Tôi đang sử dụng đường ray 4.

đây là mã điều khiển của tôi

class Admin::ItemsController < ApplicationController 
    def index 
     @items=Item.all 
    end 

    def new 
     @item=Item.new 
    end 

    def create 
     @item=Item.new items_params 
      respond_to do |format| 
       if @item.save 
        format.html { redirect_to admin_items_path } 
       else 
        format.html { redirect_to new_admin_items_path } 
       end 
      end 
    end 

private 
    def items_params 
     params.require(:item).permit(:name,:price)  
    end 
end 

đây là tập tin Feature tôi

Feature: Manage Items 
    In order to make a store 
    As an admin 
    I want to create and manage items 

    Scenario: Items List 
    Given I go to the new admin item page 
    And I fill in "Name" with "Shampoo" 
    And I fill in "Price" with "50" 
    When I press "Create" 
    Then I should be on the admin items page 
    And I should see "Shampoo" 

và định nghĩa bước

require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) 

Given /^I go to the (.+)$/ do |page_name| 
    visit path_to(page_name) 
end 

And /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value| 
    fill_in(field.gsub(' ', '_'), :with => value) 
end 

When /^I press "([^\"]*)"$/ do |button| 
    click_button(button) 
end 

Then /^I should be on the (.+)$/ do |page_name| 
    current_path.should == path_to(page_name) 
end 

And /^I should see "(.*?)"$/ do |arg1| 
    page.should have_content(arg1) 
end 

này lỗi là sh riêng trong bước 4, tức là khi nút tạo được nhấp và khi tạo mụC#.

Tôi không biết mã nào sai với hy vọng ai đó có thể trợ giúp.

UPDATE:

Tôi đoán vấn đề là với một deprecation trong dưa chuột-ray https://github.com/cucumber/cucumber-rails/issues/231

Full dấu vết:

Using the default profile... 
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.9.0 
DEPRECATION WARNING: ActionController::Integration is deprecated and will be removed, use ActionDispatch::Integration instead. (called from <module:Rails> at /home/phanindra/.gem/ruby/1.9.1/gems/cucumber-rails-1.3.0/lib/cucumber/rails/world.rb:9) 
DEPRECATION WARNING: ActionController::IntegrationTest is deprecated and will be removed, use ActionDispatch::IntegrationTest instead. (called from <module:Rails> at /home/phanindra/.gem/ruby/1.9.1/gems/cucumber-rails-1.3.0/lib/cucumber/rails/world.rb:9) 
Feature: Manage Items 
    In order to make a store 
    As an admin 
    I want to create and manage items 

    Scenario: Items List      # features/manage_items.feature:6 
DEPRECATION WARNING: #increment_open_transactions is deprecated and has no effect. (called from start at /home/phanindra/.gem/ruby/1.9.1/gems/database_cleaner-0.9.1/lib/database_cleaner/active_record/transaction.rb:11) 
    Given I go to the new admin item page # features/step_definitions/item_steps.rb:3 
    And I fill in "Name" with "Shampoo"  # features/step_definitions/item_steps.rb:7 
    And I fill in "Price" with "50"   # features/step_definitions/item_steps.rb:7 
    When I press "Create"     # features/step_definitions/item_steps.rb:11 
     SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction (ActiveRecord::StatementInvalid) 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:353:in `block in begin_db_transaction' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:305:in `block in log' 
     /home/phanindra/rails/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:300:in `log' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:353:in `begin_db_transaction' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:129:in `initialize' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:17:in `new' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb:17:in `begin' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:231:in `begin_transaction' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:208:in `within_new_transaction' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction' 
     /home/phanindra/rails/activerecord/lib/active_record/transactions.rb:209:in `transaction' 
     /home/phanindra/rails/activerecord/lib/active_record/transactions.rb:319:in `with_transaction_returning_status' 
     /home/phanindra/rails/activerecord/lib/active_record/transactions.rb:269:in `block in save' 
     /home/phanindra/rails/activerecord/lib/active_record/transactions.rb:280:in `rollback_active_record_state!' 
     /home/phanindra/rails/activerecord/lib/active_record/transactions.rb:268:in `save' 
     /home/phanindra/rails/activerecord/lib/active_record/persistence.rb:37:in `create' 
     ./app/controllers/admin/items_controller.rb:11:in `create' 
     /home/phanindra/rails/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
     /home/phanindra/rails/actionpack/lib/abstract_controller/base.rb:189:in `process_action' 
     /home/phanindra/rails/actionpack/lib/action_controller/metal/rendering.rb:10:in `process_action' 
     /home/phanindra/rails/actionpack/lib/abstract_controller/callbacks.rb:18:in `block in process_action' 
     /home/phanindra/rails/activesupport/lib/active_support/callbacks.rb:393:in `_run__143383953690284082__process_action__callbacks' 
     /home/phanindra/rails/activesupport/lib/active_support/callbacks.rb:78:in `run_callbacks' 
     /home/phanindra/rails/actionpack/lib/abstract_controller/callbacks.rb:17:in `process_action' 
     /home/phanindra/rails/actionpack/lib/action_controller/metal/rescue.rb:29:in `process_action' 
     /home/phanindra/rails/actionpack/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action' 
     /home/phanindra/rails/activesupport/lib/active_support/notifications.rb:158:in `block in instrument' 
     /home/phanindra/rails/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
     /home/phanindra/rails/activesupport/lib/active_support/notifications.rb:158:in `instrument' 
     /home/phanindra/rails/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `process_action' 
     /home/phanindra/rails/actionpack/lib/action_controller/metal/params_wrapper.rb:245:in `process_action' 
     /home/phanindra/rails/activerecord/lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
     /home/phanindra/rails/actionpack/lib/abstract_controller/base.rb:136:in `process' 
     /home/phanindra/rails/actionpack/lib/abstract_controller/rendering.rb:44:in `process' 
     /home/phanindra/rails/actionpack/lib/action_controller/metal.rb:195:in `dispatch' 
     /home/phanindra/rails/actionpack/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch' 
     /home/phanindra/rails/actionpack/lib/action_controller/metal.rb:231:in `block in action' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/routing/route_set.rb:77:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/routing/route_set.rb:77:in `dispatch' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/routing/route_set.rb:45:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/journey/router.rb:69:in `block in call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/journey/router.rb:57:in `each' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/journey/router.rb:57:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/routing/route_set.rb:614:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/params_parser.rb:30:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/flash.rb:233:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/cookies.rb:443:in `call' 
     /home/phanindra/rails/activerecord/lib/active_record/query_cache.rb:36:in `call' 
     /home/phanindra/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:632:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
     /home/phanindra/rails/activesupport/lib/active_support/callbacks.rb:373:in `_run__2084705409073281596__call__callbacks' 
     /home/phanindra/rails/activesupport/lib/active_support/callbacks.rb:78:in `run_callbacks' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/remote_ip.rb:76:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb:18:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' 
     /home/phanindra/rails/railties/lib/rails/rack/logger.rb:32:in `call_app' 
     /home/phanindra/rails/railties/lib/rails/rack/logger.rb:16:in `block in call' 
     /home/phanindra/rails/activesupport/lib/active_support/tagged_logging.rb:67:in `block in tagged' 
     /home/phanindra/rails/activesupport/lib/active_support/tagged_logging.rb:25:in `tagged' 
     /home/phanindra/rails/activesupport/lib/active_support/tagged_logging.rb:67:in `tagged' 
     /home/phanindra/rails/railties/lib/rails/rack/logger.rb:16:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/request_id.rb:21:in `call' 
     /home/phanindra/rails/activesupport/lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
     /home/phanindra/rails/actionpack/lib/action_dispatch/middleware/static.rb:63:in `call' 
     /home/phanindra/rails/railties/lib/rails/engine.rb:508:in `call' 
     /home/phanindra/rails/railties/lib/rails/application.rb:95:in `call' 
     ./features/step_definitions/item_steps.rb:12:in `/^I press "([^\"]*)"$/' 
     features/manage_items.feature:10:in `When I press "Create"' 
    Then I should be on the admin items page # features/step_definitions/item_steps.rb:15 
    And I should see "Shampoo"    # features/step_definitions/item_steps.rb:19 

Failing Scenarios: 
cucumber features/manage_items.feature:6 # Scenario: Items List 

1 scenario (1 failed) 
6 steps (1 failed, 2 skipped, 3 passed) 
0m3.476s 
+0

Bản cập nhật có khắc phục được sự cố của bạn không? Nếu có, vui lòng trả lời câu hỏi của bạn! Ngoài ra, vui lòng cung cấp lỗi đầy đủ mà bạn đang nhận được, có thể với dấu vết ngăn xếp? – Dan

+0

no it didnt khắc phục vấn đề – pahnin

Trả lời

5

Dường như bạn đang sử dụng DatabaseCleaner, mà theo mặc định chạy từng tính năng của bạn trong một giao dịch. Trong khi đó, ActiveRecord tự khởi động một giao dịch khi nó lưu mục. Thật không may, SQLite không hỗ trợ các giao dịch lồng nhau.

Nếu bạn change your DatabaseCleaner strategy đến :truncation thì nên tránh lỗi này. Ngoài ra, bạn có thể thử nghiệm dựa trên cơ sở dữ liệu có khả năng hơn như PostgreSQL.

+0

Cảm ơn câu trả lời của bạn, nhưng bây giờ tôi nhận được lỗi này, vì vậy có thể không thực sự ngay bây giờ nếu thay đổi cơ sở dữ liệu stratagey_leaner đang làm việc! :( – pahnin

+0

Xin lỗi, lỗi mới mà bạn nhận được là gì? Cảnh báo không dùng nữa sẽ không ngăn bạn tạo bản ghi, chúng chỉ là cảnh báo chứ không phải lỗi. –

+0

lỗi này https://github.com/bmabey/database_cleaner/pull/153 – pahnin

3

Điều này phù hợp với tôi. Chỉnh sửa Gemfile của bạn để kéo từ nguồn cuối cùng trên github, như Andy H đã đề xuất.

gem 'database_cleaner', github: 'bmabey/database_cleaner' 
Các vấn đề liên quan