Skip to content

Instantly share code, notes, and snippets.

@goleksiak
Created May 14, 2013 13:56
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 goleksiak/5576069 to your computer and use it in GitHub Desktop.
Save goleksiak/5576069 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe Printer do
before { @printer = FactoryGirl.create(:printer) }
it { should have_many(:subscriptions) }
it { should have_many(:users) }
it { should have_many(:jobs) }
it { should validate_numericality_of(:pickup_time) }
it { should ensure_inclusion_of(:pickup_time).in_range(1..90) }
it { should validate_numericality_of(:delivery_time) }
it { should ensure_inclusion_of(:delivery_time).in_range(1..90) }
it { should ensure_inclusion_of(:printer_state).in_array(%w(unregistered ok no_paper overheat fail)) }
describe 'Printer' do
subject { Printer }
it ".available_to_user returns printers that have not been subscribed to by the user" do
user = FactoryGirl.create(:user)
unsubscribed_printer = FactoryGirl.create(:printer)
FactoryGirl.create(:subscription, :user => user, :printer => @printer)
expect(Printer.available_to_user(user)).to eq([unsubscribed_printer])
end
describe 'a Printer' do
subject { @printer }
it "should increment the Job counter cache" do
FactoryGirl.create_list(:job_with_items, 5, :printer => @printer)
@printer.reload
expect(@printer.jobs_count).to eq(5)
end
it "should have a default jobs_count of 0" do
expect(@printer.jobs_count).to eq(0)
end
it "should genereate a key on create" do
expect(@printer.key).to be_present
end
it "should have a default printer_state of 'unregistered'" do
expect(@printer.printer_state).to eq("unregistered")
end
it "should return a formatted printer_state" do
expect(@printer.formatted_printer_state).to eq("Unregistered")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment