Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 钢轨试验的异常行为_Ruby On Rails_Model_Tdd - Fatal编程技术网

Ruby on rails 钢轨试验的异常行为

Ruby on rails 钢轨试验的异常行为,ruby-on-rails,model,tdd,Ruby On Rails,Model,Tdd,我有一个叫票的模型,如下所示: ActiveRecord::Schema.define(version: 20151231072055) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "tickets", force: :cascade do |t| t.string "mov

我有一个叫票的模型,如下所示:

ActiveRecord::Schema.define(version: 20151231072055) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"
  create_table "tickets", force: :cascade do |t|
    t.string   "movie_name"
    t.integer  "price"
    t.boolean  "is_3d"
    t.string   "theatre_name"
    t.string   "seller_name"
    t.string   "seller_email"
    t.string   "seller_mobile"
    t.string   "preferred_places"
    t.datetime "created_at",       null: false
    t.datetime "updated_at",       null: false
    t.datetime "date_and_time"
  end

end
我正在尝试验证所有字段的存在,因此我对我的票证模型进行以下测试:

require 'test_helper'

class TicketTest < ActiveSupport::TestCase
    def setup
        @ticket = tickets(:one)
    end

    def teardown
        @ticket = nil
    end

  test 'should not save ticket without movie name' do
    @ticket.movie_name = nil
    assert_not(@ticket.save, 'Saved the ticket without movie name')
  end

  test 'should not save ticket without price' do
    @ticket.price = nil
    assert_not(@ticket.save, 'Saved the ticket without price')
  end

    test 'should not save ticket without theatre name' do
    @ticket.theatre_name = nil
    assert_not(@ticket.save, 'Saved the ticket without theatre name')
  end

    test 'should not save ticket without seller name' do
    @ticket.seller_name = nil
    assert_not(@ticket.save, 'Saved the ticket without seller name')
  end

  test 'should not save ticket without seller email' do
    @ticket.seller_email = nil
    assert_not(@ticket.save, 'Saved the ticket without seller email')
  end

  test 'should not save ticket without seller mobile' do
    @ticket.seller_mobile = nil
    assert_not(@ticket.save, 'Saved the ticket without seller mobile')
  end

  test 'should not save ticket without preferred places' do
    @ticket.preferred_places = nil
    assert_not(@ticket.save, 'Saved the ticket without preferred places')
  end

    test 'should not save ticket without date and time' do
    @ticket.date_and_time = nil
    assert_not(@ticket.save, 'Saved the ticket without date and time')
  end  

  test 'should not save ticket without 3D status' do
    @ticket.is_3d = nil
    assert_not(@ticket.save, 'Saved the ticket without 3D status')
  end

end
需要“测试助手”
类TicketTest
我在我的票证模型中编写了以下代码,以使其中一个通过测试:

class Ticket < ActiveRecord::Base
    validates_presence_of :is_3d
end
classticket

这使得所有测试用例都能通过。我注意到的是,如果我单独检查是否存在
is_3d
,一切都通过(异常),如果我单独检查是否存在任何其他字段,则仅该特定字段的测试通过(正常)。

请参阅与
布尔属性相关的内容。这很有帮助。非常感谢。