Closed squidgetx closed 10 years ago
require 'spec_helper'
describe Cart do
context "General validations" do
it { should validate_presence_of(:reserver_id) }
it { should validate_presence_of(:start_date) }
it { should validate_presence_of(:due_date) }
it "should validate that start date is < due date"
end
describe ".initialize" do
it "has no items"
it "starts today "
it "is due tomorrow"
it "has no reserver"
end
describe "Item handling" do
describe ".add_item" do
it "adds an item to the array"
end
describe ".remove_item" do
it "removes an item from array"
end
end
describe ".empty?" do
it "is true when there are no items in cart"
it "is false when there are some items in cart"
end
describe ".prepare_all" do
it "returns an array of reservations"
describe "reservations in array returned" do
it "inherits the cart start date"
it "inherits the cart end date"
it "inherits the cart reserver"
it "inherits the cart items"
end
end
describe ".purge_all" do
it "empties the cart"
end
describe ".models_with_quantities" do
it "returns a hash of models as keys and quantities as values"
#do we really need this?
end
describe ".check_availability" do
context "items are good to go" do
it "sets the flash to success"
end
context "items are not good to go" do
it "sets the flash to detailed error message"
end
end
end
Add to Cart
button sends a PUT
request to /add_to_cart/:id
/add_to_cart/:id
is a custom route that goes to catalog#add_to_cart
catalog#add_to_cart
calls catalog#change_cart(:add_to_cart, :equipment_model)
validateSet
is called on the cartlist_items_in_cart
is refreshed with $('#list_items_in_cart').replaceWith('<%= escape_javascript(render :partial => 'reservations/list_items_in_cart') %>');
validateSet
removing is similar
Useful links, perhaps
Note of caution: the only thing that ReservationsController#create
takes from in-database CartReservations is equipment-model IDs. It takes start date and due date from params[:reservation], which is a hidden field on the submission page. As this is expected behavior in the refactoring, I just wanted to document it here.
What if we simply split up the validations between the fields that they're relevant to?
If we remove cart reservations and write custom methods to check these validations (that take arrays of equipment model id's or something as arguments instead of reservation objects) I think it has a chance at being fast enough.
Update cart spec and model are on branch 587_fix_cart_latency
new
controller action to use cart.prepareAll
and validateSet
At this point we should have a working, fast cart that doesn't autosubmit its data fields for validation. Discussion of what options from here should go in #586.
These three options really aren't mutually exclusive, though I think that if we implement 2, both 1 and 3 are unnecessary, and similarly if we implement 1 we don't need 3 (and vice versa)
Discuss here. (@shippy, @dgoerger @mnquintana @orenyk ).
using some js timestamps created at points when the cart would pause and resume we can actually benchmark which parts of the cart updating takes so long (ActiveAdmin routes disabled)
(note in the above scenarios the user has 0 other reservations)
Since we made such great progress in #628, I don't think we need to implement such drastic changes. After we finish #574 and #573 I think we'll be good to go on the cart.
PROPOSED WORKFLOW