Class: Auchandirect::ScrAPI::DummyCart
- Defined in:
- lib/auchandirect/scrAPI/dummy_cart.rb
Overview
A mock for Auchandirect::ScrAPI::Cart It provides a call log as a way of testing
Constant Summary collapse
- @@content =
As the real store, the remote cart outlives the sessions
Hash.new(0)
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Accessors to the login and passwords used to login And to the received messages log.
-
#login ⇒ Object
readonly
Accessors to the login and passwords used to login And to the received messages log.
-
#password ⇒ Object
readonly
Accessors to the login and passwords used to login And to the received messages log.
Class Method Summary collapse
- .login_parameter ⇒ Object
- .login_parameters(login, password) ⇒ Object
- .login_url ⇒ Object
- .logout_url ⇒ Object
- .password_parameter ⇒ Object
- .url ⇒ Object
-
.valid_email ⇒ Object
The valid login to log into this dummy store.
-
.valid_password ⇒ Object
The valid password to log into this dummy store.
Instance Method Summary collapse
- #add_to_cart(quantity, item) ⇒ Object
-
#add_unavailable_item(item) ⇒ Object
Makes an item temporarily unavailable.
-
#available?(item) ⇒ Boolean
Is the given item available at this moment ?.
- #cart_value ⇒ Object
-
#containing?(item, quantity) ⇒ Boolean
Does the cart contain the specified quantity of this item ?.
-
#content ⇒ Object
Collection of all the different items in the cart.
-
#empty? ⇒ Boolean
Is the cart empty ?.
- #empty_the_cart ⇒ Object
-
#initialize(login = nil, password = nil) ⇒ DummyCart
constructor
A new instance of DummyCart.
- #logout ⇒ Object
-
#relog(login, password) ⇒ Object
Resets the session as if a new one was started.
Methods inherited from BaseCart
Constructor Details
#initialize(login = nil, password = nil) ⇒ DummyCart
Returns a new instance of DummyCart.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 66 def initialize(login = nil, password = nil) @log = [] @login = "" @password = "" @unavailable_items = {} if !login.nil? || !password.nil? relog(login, password) end end |
Instance Attribute Details
#log ⇒ Object (readonly)
Accessors to the login and passwords used to login And to the received messages log
61 62 63 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 61 def log @log end |
#login ⇒ Object (readonly)
Accessors to the login and passwords used to login And to the received messages log
61 62 63 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 61 def login @login end |
#password ⇒ Object (readonly)
Accessors to the login and passwords used to login And to the received messages log
61 62 63 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 61 def password @password end |
Class Method Details
.login_parameter ⇒ Object
52 53 54 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 52 def self.login_parameter 'login' end |
.login_parameters(login, password) ⇒ Object
47 48 49 50 51 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 47 def self.login_parameters(login,password) [{'name' => 'session_data', 'value' => 'crypted_data', 'type' => 'hidden'}, {'name' => login_parameter, 'value' => login, 'type' => 'text'}, {'name' => password_parameter, 'value' => password, 'type' => 'password'}] end |
.login_url ⇒ Object
44 45 46 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 44 def self.login_url url+"/login" end |
.logout_url ⇒ Object
41 42 43 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 41 def self.logout_url url+"/logout" end |
.password_parameter ⇒ Object
55 56 57 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 55 def self.password_parameter 'password' end |
.url ⇒ Object
29 30 31 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 29 def self.url "http://www.#{Storexplore::Testing::DummyStoreConstants::NAME}.com" end |
.valid_email ⇒ Object
The valid login to log into this dummy store
33 34 35 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 33 def self.valid_email "[email protected]" end |
.valid_password ⇒ Object
The valid password to log into this dummy store
37 38 39 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 37 def self.valid_password "valid-password" end |
Instance Method Details
#add_to_cart(quantity, item) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 97 def add_to_cart(quantity, item) if available?(item) @log.push(:add_to_cart) @@content[item] += quantity end end |
#add_unavailable_item(item) ⇒ Object
Makes an item temporarily unavailable
131 132 133 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 131 def add_unavailable_item(item) @unavailable_items[item] = true end |
#available?(item) ⇒ Boolean
Is the given item available at this moment ?
136 137 138 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 136 def available?(item) !@unavailable_items[item] end |
#cart_value ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 104 def cart_value @@content.to_a.inject(0.0) do |amount,id_and_quantity| item = id_and_quantity.first quantity = id_and_quantity.last unit_price = item.hash.abs.to_f/1e7 amount + quantity * unit_price end end |
#containing?(item, quantity) ⇒ Boolean
Does the cart contain the specified quantity of this item ?
126 127 128 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 126 def containing?(item, quantity) @@content[item] == quantity end |
#content ⇒ Object
Collection of all the different items in the cart
116 117 118 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 116 def content @@content.keys end |
#empty? ⇒ Boolean
Is the cart empty ?
121 122 123 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 121 def empty? @@content.empty? end |
#empty_the_cart ⇒ Object
92 93 94 95 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 92 def empty_the_cart @log.push(:empty_the_cart) @@content.clear end |
#logout ⇒ Object
88 89 90 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 88 def logout @log.push(:logout) end |
#relog(login, password) ⇒ Object
Resets the session as if a new one was started
78 79 80 81 82 83 84 85 86 |
# File 'lib/auchandirect/scrAPI/dummy_cart.rb', line 78 def relog(login, password) if login != DummyCart.valid_email raise InvalidAccountError.new end @log.push(:login) @login = login @password = password end |