Skip to content

Instantly share code, notes, and snippets.

@neaf
Created March 9, 2011 19:45
Show Gist options
  • Save neaf/862843 to your computer and use it in GitHub Desktop.
Save neaf/862843 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe Court do
context "in general" do
[:name, :timespace_end_date].each do |f|
it "has #{ f } column" do
subject.should have_column f
end
end
it "has many cells" do
subject.should have_many :cells
end
it "has and belongs to many price criteria" do
subject.should have_and_belong_to_many :price_criteria
end
it "validates name" do
Court.create!({
:name => "Test",
})
subject.should validate_presence_of :name
subject.should validate_uniqueness_of :name
end
end
describe "#expand_timespace" do
before(:each) do
@start_date = Date.new(2011, 3, 1)
@end_date = @start_date + 5
@opening_hour = 7
@closing_hour = 22
@court = Factory(:court, :timespace_end_date => @start_date)
Setting.stub!(:for).with(:opening_hour).and_return(7)
Setting.stub!(:for).with(:closing_hour).and_return(22)
end
it "fetches last day of current timespace" do
@court.should_receive(:time_space_end_date).and_return(@start_date)
@court.expand_timespace(@end_date)
end
it "creates cells for specified time range" do
(@start_date..@end_date).each do |d|
(@opening_hour..@closing_hour).each do |h|
Cell.should_receive(:create).with(:time => DateTime.new(d.year, d.month, d.day, h), :court => @court)
end
end
@court.expand_timespace(@end_date)
end
it "updates court timespace end date" do
@court.expand_timespace(@end_date)
@court.timespace_end_date.should eql(@end_date)
end
it "saves court instance" do
@court.should_receive(:save).and_return(true)
@court.expand_timespace(@end_date)
end
end
end
require 'spec_helper'
feature "Allocation management" do
scenario "display allocation list" do
3.times { Factory(:allocation) }
visit "/administration/allocations"
within("table.object-list tbody") do
page.should have_selector("tr", :count => 3)
end
end
scenario "create new allocation" do
@courts = 3.times.map { Factory(:court_with_cells) }
visit "/administration/allocations"
click_link "New allocation"
within("form#new-allocation") do
@courts.first.cells.first(4).each do |c|
find("*[data-cell-id=%d]" % c.id).click
end
@courts.first(2).each do |c|
click_on c.name
end
fill_in "Description", :with => "Maintenance"
click_on "Create"
end
page.should have_content("Allocation created successfully.")
find("table.object-list").should have_content("Maintenance")
Allocation.find_by_description("Maintenance").cells.should have(4).items
end
scenario "edit allocation" do
@allocation = Factory(:allocation, :description => "Maintenance")
visit "/administration/allocations"
find("table.object-list tr", :text => "Maintenance").click_on("Edit")
within("form#edit-allocation") do
@allocation.cells.first(2).each do |c|
find("*[data-cell-id=%d]" % c.id).click
end
@allocation.courts.first.cells.last(3).each do |c|
find("*[data-cell-id=%d]" % c.id).click
end
fill_in "Description", :with => "Net maintenance"
click_on "Update"
end
page.should have_content("Allocation updated successfully.")
find("table.object-list").should_not have_content("Maintenance")
find("table.object-list").should have_content("Net maintenance")
Allocation.find_by_description("Net maintenance").cells.should have(5).items
end
scenario "delete allocation" do
@allocation = Factory(:allocation, :description => "Maintenance")
visit "/administration/allocations"
find("table.object-list tr", :text => "Maintenance").click_on("Delete")
page.should have_content("Allocation deleted successfully.")
find("table.object-list").should have_content("Maintenance")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment