Skip to content

Instantly share code, notes, and snippets.

Created December 31, 2012 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4418876 to your computer and use it in GitHub Desktop.
Save anonymous/4418876 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe "InvoicePages" do
let(:user) { FactoryGirl.create(:user) }
let(:client) { FactoryGirl.create(:client) }
before(:each) do
visit new_user_session_path
fill_in "user_email", with: user.email
fill_in "user_password", with: user.password
click_button "Sign in"
end
after(:all) do
# User.delete_all
end
subject { page }
describe "index" do
before(:all) { 30.times { FactoryGirl.create(:invoice) } }
before(:each) do
visit invoices_path
end
it { should have_selector('title', text: 'All Invoices') }
it { should have_selector('h1', text: 'All Invoices') }
it { should have_link('New Invoice', href: new_invoice_path) }
describe "lists invoices" do
it "should list each invoice" do
Invoice.all.each do |invoice|
page.should have_selector('li>a', text: invoice.created_at.to_s)
end
end
end
end
describe "invoice creation" do
before(:each) do
visit new_invoice_path
end
it { should have_selector('title', text: 'New Invoice') }
it { should have_selector('h1', text: 'New Invoice') }
describe "with invalid information" do
it "should not create a invoice" do
expect { click_button "Create Invoice" }.not_to change(Invoice, :count)
end
describe "error messages" do
before { click_button "Create Invoice" }
it { should have_content('Error') }
end
end
describe "with valid information" do
FactoryGirl.create(:client, name: "Invoice client")
let(:invoice) { FactoryGirl.create(:invoice) }
before(:each) do
visit new_invoice_path
select "Invoice client", from: "invoice_client_id"
end
after(:all) { Client.delete_all }
it "should create a invoice" do
expect { click_button "Create Invoice" }.to change(Invoice, :count)
end
describe "success messages" do
before { click_button "Create Invoice" }
it { should have_content('created') }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment