barcode model test

This commit is contained in:
benji 2015-10-28 21:54:55 +01:00
parent 8906ca7e39
commit 539b65b75f
3 changed files with 9 additions and 1 deletions

View file

@ -1,6 +1,7 @@
class BarcodesController < ApplicationController
load_and_authorize_resource :product, only: :create
load_and_authorize_resource :barcode, through: :product, shallow: true
def create
@barcode.save
redirect_to barcode_products_path, notice: "Barcode successfully linked!"

View file

@ -15,6 +15,6 @@ class Barcode < ActiveRecord::Base
belongs_to :product
# validates :product, presence: true
validates :product, presence: true
validates :code, presence: true, uniqueness: true
end

View file

@ -23,5 +23,12 @@ describe Barcode do
expect(barcode).to_not be_valid
end
end
describe 'product' do
it 'should be present' do
@barcode.product = nil
expect(@barcode).to_not be_valid
end
end
end
end