ini specnya klupaan di paste
saya cuma bwt spec model nya aja
# /spec/fixtures/
# books.yml
one:
title: Buku Satu
available: true
two:
title: Buku Dua
available: false
three:
title: Buku Tiga
available: true
four:
title: Buku Empat
available: false
five:
title: Buku Lima
available: true
# book_spec.rb
# /spec/models/
require File.dirname(__FILE__) + '/../spec_helper'
describe Book do
fixtures :books
#before(:each) do
# @book = books(:one)
#end
it "should be valid" do
book = books(:one)
book.should be_valid
book.title.should == "Buku Satu"
end
it "should contains 5 books" do
Book.find(:all).size.should == 5
end
it "should list available books" do
books = Book.find_all_available(true)
books.size.should == 3
books.each do |book|
book.available.should be_true
end
end
it "should list unavailable books" do
books = Book.find_all_available(false)
books.size.should == 2
books.each do |book|
book.available.should be_false
end
end
it "harus mengubah buku dgn id-id berikut menjadi stok habis" do
ids = Book.find_all_available(true).collect(&:id).join(',')
Book.stok_habis_utk_buku_ini(ids)
Book.find_all_available(true).size.should == 0
end
end
[Non-text portions of this message have been removed]