我似乎无法弄清楚为什么我的PartTransactions测试始终无法更新和创建。我所有的其他测试都成功了,因此,对我来说,我觉得自己的固定装置做错了什么—任何建议将不胜感激!
Running via Spring preloader in process 62590
Started with run options --seed 23873
FAIL["test_should_create_part_transaction", #<Minitest::Reporters::Suite:0x00007f96615c1710 @name="PartTransactionsControllerTest">, 0.644004000001587]
test_should_create_part_transaction#PartTransactionsControllerTest (0.64s)
"PartTransaction.count" didn't change by 1.
Expected: 3
Actual: 2
test/controllers/part_transactions_controller_test.rb:19:in `block in <class:PartTransactionsControllerTest>'
FAIL["test_should_update_part_transaction", #<Minitest::Reporters::Suite:0x00007f966163a548 @name="PartTransactionsControllerTest">, 0.6869309999747202]
test_should_update_part_transaction#PartTransactionsControllerTest (0.69s)
Expected response to be a <3XX: redirect>, but was a <200: OK>
test/controllers/part_transactions_controller_test.rb:38:in `block in <class:PartTransactionsControllerTest>'
21/21: [===========================================================================================================================================================================================================================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.77788s
21 tests, 26 assertions, 2 failures, 0 errors, 0 skips
ActiveRecord::Schema.define(version: 2019_01_30_150153) do
create_table "customers", force: :cascade do |t|
t.string "cust_id"
t.string "cust_name"
t.integer "cust_status"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "part_transactions", force: :cascade do |t|
t.integer "trans_id"
t.datetime "trans_date"
t.decimal "trans_qty", precision: 14, scale: 4
t.string "trans_type"
t.string "invoiced"
t.decimal "cs_trans_qty", precision: 6, scale: 2
t.integer "part_id"
t.integer "customer_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["customer_id"], name: "index_csi_part_transactions_on_customer_id"
t.index ["part_id"], name: "index_csi_part_transactions_on_part_id"
end
create_table "parts", force: :cascade do |t|
t.string "part_id"
t.string "description"
t.decimal "qty_on_hand", precision: 14, scale: 4
t.decimal "order_point", precision: 14, scale: 4
t.decimal "reorder_qty", precision: 14, scale: 4
t.string "part_type"
t.string "status"
t.string "inv_cs"
t.decimal "cs_qty", precision: 3
t.string "cs_status"
t.integer "customer_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["customer_id"], name: "index_csi_parts_on_customer_id"
end
end
class Customer < ApplicationRecord
has_many :parts, :dependent => :destroy
has_many :part_transactions, :dependent => :destroy
end
class Part < ApplicationRecord
belongs_to :customer
has_many :part_transactions, :dependent => :destroy
end
class PartTransaction < ApplicationRecord
belongs_to :part
belongs_to :customer
end
#Customer -------------------------------------------------------------
one:
cust_id: one
cust_name: My Company
cust_status: 3
two:
cust_id: two
cust_name: Other Company
cust_status: 1
#Parts-------------------------------------------------------------
one:
part_id: one
description: TestA
qty_on_hand: 2
order_point: 3
reorder_qty: 1
part_type: TestAPartType
status: F
inv_cs: 2
cs_qty: 3
cs_status: F
customer: one
two:
part_id: two
description: TestB
qty_on_hand: 1
order_point: 3
reorder_qty: 6
part_type: TestBPartType
status: F
inv_cs: 2
cs_qty: 3
cs_status: C
customer: two
#PartTransactions------------------------------------------------------
one:
trans_id: one
trans_date: 2019-01-31
trans_qty: 1
trans_qty: 1
trans_type: 1
invoiced: 1
cs_trans_qty: 1
cs_trans_qty: 1
part_id: one
customer: one
two:
trans_id: 2
trans_date: 2019-01-31
trans_qty: 3
trans_qty: 3
trans_type: 3
invoiced: 1
cs_trans_qty: 1
cs_trans_qty: 1
part_id: two
customer: two
require 'test_helper'
class PartTransactionsControllerTest < ActionDispatch::IntegrationTest
setup do
@part_transaction = part_transactions(:one)
end
test "should get index" do
get part_transactions_url
assert_response :success
end
test "should get new" do
get new_part_transaction_url
assert_response :success
end
test "should create part_transaction" do
assert_difference('PartTransaction.count') do
post part_transactions_url, params: { part_transaction: { cs_trans_qty: @part_transaction.cs_trans_qty, customer_id: @part_transaction.customer_id, invoiced: @part_transaction.invoiced, part_id: @part_transaction.part_id, trans_date: @part_transaction.trans_date, trans_id: @part_transaction.trans_id, trans_qty: @part_transaction.trans_qty, trans_type: @part_transaction.trans_type } }
end
assert_redirected_to part_transaction_url(PartTransaction.last)
end
test "should show part_transaction" do
get part_transaction_url(@part_transaction)
assert_response :success
end
test "should get edit" do
get edit_part_transaction_url(@part_transaction)
assert_response :success
end
test "should update part_transaction" do
patch part_transaction_url(@part_transaction), params: { part_transaction: { cs_trans_qty: @part_transaction.cs_trans_qty, customer_id: @part_transaction.customer_id, invoiced: @part_transaction.invoiced, part_id: @part_transaction.part_id, trans_date: @part_transaction.trans_date, trans_id: @part_transaction.trans_id, trans_qty: @part_transaction.trans_qty, trans_type: @part_transaction.trans_type } }
assert_redirected_to part_transaction_url(@part_transaction)
end
test "should destroy part_transaction" do
assert_difference('PartTransaction.count', -1) do
delete part_transaction_url(@part_transaction)
end
assert_redirected_to part_transactions_url
end
end
class PartTransactionsController < ApplicationController
before_action :set_part_transaction, only: [:show, :edit, :update, :destroy]
# GET /part_transactions
# GET /part_transactions.json
def index
@part_transactions = PartTransaction.all
end
# GET /part_transactions/1
# GET /part_transactions/1.json
def show
end
# GET /part_transactions/new
def new
@part_transaction = PartTransaction.new
end
# GET /part_transactions/1/edit
def edit
end
# POST /part_transactions
# POST /part_transactions.json
def create
@part_transaction = PartTransaction.new(part_transaction_params)
respond_to do |format|
if @part_transaction.save
format.html { redirect_to @part_transaction, notice: 'Part transaction was successfully created.' }
format.json { render :show, status: :created, location: @part_transaction }
else
format.html { render :new }
format.json { render json: @part_transaction.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /part_transactions/1
# PATCH/PUT /part_transactions/1.json
def update
respond_to do |format|
if @part_transaction.update(part_transaction_params)
format.html { redirect_to @part_transaction, notice: 'Part transaction was successfully updated.' }
format.json { render :show, status: :ok, location: @part_transaction }
else
format.html { render :edit }
format.json { render json: @part_transaction.errors, status: :unprocessable_entity }
end
end
end
# DELETE /part_transactions/1
# DELETE /part_transactions/1.json
def destroy
@part_transaction.destroy
respond_to do |format|
format.html { redirect_to part_transactions_url, notice: 'Part transaction was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_part_transaction
@part_transaction = PartTransaction.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def part_transaction_params
params.require(:part_transaction).permit(:trans_id, :trans_date, :trans_qty, :trans_qty, :trans_type, :invoiced, :cs_trans_qty, :cs_trans_qty, :part_id, :customer_id)
end
end
答案 0 :(得分:0)
我不知道我怎么错过了它,但是我发现它是由我的part_transactions固定装置引起的-见下文
我的固定装置中应该有part_id时(*头部有些自鸣得意)
def followUser(tweet):#Follows a user
tweet = api.get_status(tweet.id)
while tweet.user.follow_request_sent == False:
api.create_friendship(tweet.user.id)
followUser(tweet)
break
print("Successful follow")