dugway 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +1 -1
  6. data/LICENSE.txt +22 -0
  7. data/dugway.gemspec +3 -0
  8. data/lib/dugway/cart.rb +8 -12
  9. data/lib/dugway/cli/templates/Gemfile.tt +1 -1
  10. data/lib/dugway/cli/templates/gitignore.tt +1 -0
  11. data/lib/dugway/cli/templates/source/product.html +5 -3
  12. data/lib/dugway/cli/templates/source/stylesheets/cart.css.sass +8 -0
  13. data/lib/dugway/cli/templates/source/stylesheets/product.css.sass +32 -0
  14. data/lib/dugway/liquid/drops/cart_item_drop.rb +4 -0
  15. data/lib/dugway/liquid/drops/product_drop.rb +10 -6
  16. data/lib/dugway/liquid/drops/product_option_drop.rb +1 -1
  17. data/lib/dugway/liquid/drops/shipping_option_drop.rb +2 -0
  18. data/lib/dugway/liquid/tags/checkout_form.rb +1 -1
  19. data/lib/dugway/version.rb +1 -1
  20. data/spec/features/contact_form_spec.rb +43 -0
  21. data/spec/features/page_rendering_spec.rb +69 -0
  22. data/spec/features/shopping_spec.rb +38 -0
  23. data/spec/fixtures/store/products.js +1 -1
  24. data/spec/fixtures/store/store.js +1 -1
  25. data/spec/fixtures/theme/cart.html +22 -7
  26. data/spec/fixtures/theme/contact.html +37 -37
  27. data/spec/fixtures/theme/layout.html +8 -0
  28. data/spec/fixtures/theme/settings.json +1 -0
  29. data/spec/fixtures/theme/styles.css +2 -2
  30. data/spec/spec_helper.rb +8 -0
  31. data/spec/units/dugway/cart_spec.rb +204 -0
  32. data/spec/units/dugway/liquid/drops/account_drop_spec.rb +54 -0
  33. data/spec/units/dugway/liquid/drops/artist_drop_spec.rb +40 -0
  34. data/spec/units/dugway/liquid/drops/artists_drop_spec.rb +41 -0
  35. data/spec/units/dugway/liquid/drops/cart_drop_spec.rb +81 -0
  36. data/spec/units/dugway/liquid/drops/cart_item_drop_spec.rb +72 -0
  37. data/spec/units/dugway/liquid/drops/categories_drop_spec.rb +41 -0
  38. data/spec/units/dugway/liquid/drops/category_drop_spec.rb +40 -0
  39. data/spec/units/dugway/liquid/drops/contact_drop_spec.rb +124 -0
  40. data/spec/units/dugway/liquid/drops/country_drop_spec.rb +17 -0
  41. data/spec/units/dugway/liquid/drops/image_drop_spec.rb +23 -0
  42. data/spec/units/dugway/liquid/drops/page_drop_spec.rb +70 -0
  43. data/spec/units/dugway/liquid/drops/pages_drop_spec.rb +29 -0
  44. data/spec/units/dugway/liquid/drops/product_drop_spec.rb +269 -0
  45. data/spec/units/dugway/liquid/drops/product_option_drop_spec.rb +86 -0
  46. data/spec/units/dugway/liquid/drops/products_drop_spec.rb +127 -0
  47. data/spec/units/dugway/liquid/drops/shipping_option_drop_spec.rb +26 -0
  48. data/spec/units/dugway/liquid/drops/theme_drop_spec.rb +68 -0
  49. data/spec/units/dugway/store_spec.rb +27 -27
  50. data/spec/units/dugway/template_spec.rb +12 -0
  51. data/spec/units/dugway/theme_spec.rb +198 -0
  52. metadata +95 -57
  53. data/spec/units/dugway_spec.rb +0 -9
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Drops::ArtistsDrop do
4
+ let(:artists) { Dugway::Drops::ArtistsDrop.new(Dugway.store.artists.map { |a| Dugway::Drops::ArtistDrop.new(a) }) }
5
+
6
+ describe "#all" do
7
+ it "should return an array of all artists" do
8
+ all = artists.all
9
+ all.should be_an_instance_of(Array)
10
+ all.size.should == 3
11
+
12
+ artist = all.first
13
+ artist.should be_an_instance_of(Dugway::Drops::ArtistDrop)
14
+ artist.name.should == 'Artist One'
15
+ end
16
+ end
17
+
18
+ describe "#active" do
19
+ it "should return an array of all active artists" do
20
+ active = artists.active
21
+ active.should be_an_instance_of(Array)
22
+ active.size.should == 2
23
+
24
+ artist = active.first
25
+ artist.should be_an_instance_of(Dugway::Drops::ArtistDrop)
26
+ artist.name.should == 'Artist One'
27
+ end
28
+ end
29
+
30
+ describe "#permalink" do
31
+ it "should return the artist by permalink" do
32
+ artist = artists.threezer
33
+ artist.should be_an_instance_of(Dugway::Drops::ArtistDrop)
34
+ artist.name.should == 'Threezer'
35
+ end
36
+
37
+ it "should return the nil for an invalid permalink" do
38
+ artists.blah.should be_nil
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Drops::CartDrop do
4
+ let(:cart) {
5
+ Dugway::Drops::CartDrop.new(
6
+ Dugway::Cart.new.tap { |cart|
7
+ product_option = Dugway.store.products.first['options'].first
8
+ product_option_2 = Dugway.store.products.last['options'].first
9
+ cart.update(adds: [{ id: product_option['id'] }, { id: product_option_2['id'], quantity: 2 }])
10
+ }
11
+ )
12
+ }
13
+
14
+ describe "#item_count" do
15
+ it "should return the number of items times quantity" do
16
+ cart.item_count.should == 3
17
+ end
18
+ end
19
+
20
+ describe "#price" do
21
+ it "should return nil, since it's deprecated" do
22
+ cart.price.should be_nil
23
+ end
24
+ end
25
+
26
+ describe "#subtotal" do
27
+ it "should the cart's subtotal" do
28
+ cart.subtotal.should == 50.0
29
+ end
30
+ end
31
+
32
+ describe "#total" do
33
+ it "should the cart's total" do
34
+ cart.total.should == 50.0
35
+ end
36
+ end
37
+
38
+ describe "#items" do
39
+ it "should return an array of the items" do
40
+ items = cart.items
41
+ items.should be_an_instance_of(Array)
42
+ items.size.should == 2
43
+
44
+ item = items.first
45
+ item.should be_an_instance_of(Dugway::Drops::CartItemDrop)
46
+ item.name.should == 'My Product - Small'
47
+ end
48
+ end
49
+
50
+ describe "#country" do
51
+ it "should return nil, since it's disabled" do
52
+ cart.country.should be_nil
53
+ end
54
+ end
55
+
56
+ describe "#shipping" do
57
+ it "should return a hash of values" do
58
+ shipping = cart.shipping
59
+ shipping['enabled'].should be(false)
60
+ shipping['strict'].should be(false)
61
+ shipping['pending'].should be(false)
62
+ shipping['amount'].should == 0.0
63
+ end
64
+ end
65
+
66
+ describe "#discount" do
67
+ it "should return a hash of values" do
68
+ discount = cart.discount
69
+ discount['enabled'].should be(false)
70
+ discount['pending'].should be(false)
71
+ discount['name'].should be(nil)
72
+ discount['amount'].should == 0.0
73
+ discount['code'].should be(nil)
74
+ discount['type'].should be(nil)
75
+ discount['percent_discount'].should be(nil)
76
+ discount['flat_rate_discount'].should be(nil)
77
+ discount['free_shipping'].should be(nil)
78
+ discount['percent'].should be(nil)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Drops::CartItemDrop do
4
+ let(:cart) {
5
+ Dugway::Drops::CartDrop.new(
6
+ Dugway::Cart.new.tap { |cart|
7
+ product_option = Dugway.store.products.first['options'].first
8
+ cart.update(add: { id: product_option['id'], quantity: 2 })
9
+ }
10
+ )
11
+ }
12
+
13
+ let(:cart_item) { cart.items.first }
14
+
15
+ describe "#id" do
16
+ it "should return the id of the item" do
17
+ cart_item.id.should == 1
18
+ end
19
+ end
20
+
21
+ describe "#name" do
22
+ it "should return the name of the item's product + option name" do
23
+ cart_item.name.should == 'My Product - Small'
24
+ end
25
+ end
26
+
27
+ describe "#price" do
28
+ it "should return the price of the item times its quantity" do
29
+ cart_item.price.should == 20.0
30
+ end
31
+ end
32
+
33
+ describe "#unit_price" do
34
+ it "should return the price of the item" do
35
+ cart_item.unit_price.should == 10.0
36
+ end
37
+ end
38
+
39
+ describe "#shipping" do
40
+ it "should return 0.0 because it's disabled" do
41
+ cart_item.shipping.should == 0.0
42
+ end
43
+ end
44
+
45
+ describe "#total" do
46
+ it "should return the total of the item times its quantity plus shipping" do
47
+ cart_item.total.should == 20.0
48
+ end
49
+ end
50
+
51
+ describe "#quantity" do
52
+ it "should return the quantity of the item" do
53
+ cart_item.quantity.should == 2
54
+ end
55
+ end
56
+
57
+ describe "#product" do
58
+ it "should return a ProductDrop of the item's product" do
59
+ product = cart_item.product
60
+ product.should be_an_instance_of(Dugway::Drops::ProductDrop)
61
+ product.name.should == 'My Product'
62
+ end
63
+ end
64
+
65
+ describe "#option" do
66
+ it "should return a ProductOptionDrop of the item's option" do
67
+ option = cart_item.option
68
+ option.should be_an_instance_of(Dugway::Drops::ProductOptionDrop)
69
+ option.name.should == 'Small'
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Drops::CategoriesDrop do
4
+ let(:categories) { Dugway::Drops::CategoriesDrop.new(Dugway.store.categories.map { |c| Dugway::Drops::CategoryDrop.new(c) }) }
5
+
6
+ describe "#all" do
7
+ it "should return an array of all categories" do
8
+ all = categories.all
9
+ all.should be_an_instance_of(Array)
10
+ all.size.should == 4
11
+
12
+ category = all.first
13
+ category.should be_an_instance_of(Dugway::Drops::CategoryDrop)
14
+ category.name.should == 'CDs'
15
+ end
16
+ end
17
+
18
+ describe "#active" do
19
+ it "should return an array of all active categories" do
20
+ active = categories.active
21
+ active.should be_an_instance_of(Array)
22
+ active.size.should == 2
23
+
24
+ category = active.first
25
+ category.should be_an_instance_of(Dugway::Drops::CategoryDrop)
26
+ category.name.should == 'Prints'
27
+ end
28
+ end
29
+
30
+ describe "#permalink" do
31
+ it "should return the category by permalink" do
32
+ category = categories.prints
33
+ category.should be_an_instance_of(Dugway::Drops::CategoryDrop)
34
+ category.name.should == 'Prints'
35
+ end
36
+
37
+ it "should return the nil for an invalid permalink" do
38
+ categories.blah.should be_nil
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Drops::CategoryDrop do
4
+ let(:category) { Dugway::Drops::CategoryDrop.new(Dugway.store.categories.last) }
5
+
6
+ describe "#id" do
7
+ it "should return the category's id" do
8
+ category.id.should == 4615193
9
+ end
10
+ end
11
+
12
+ describe "#name" do
13
+ it "should return the category's name" do
14
+ category.name.should == 'Tees'
15
+ end
16
+ end
17
+
18
+ describe "#permalink" do
19
+ it "should return the category's permalink" do
20
+ category.permalink.should == 'tees'
21
+ end
22
+ end
23
+
24
+ describe "#url" do
25
+ it "should return the category's url" do
26
+ category.url.should == '/category/tees'
27
+ end
28
+ end
29
+
30
+ describe "#products" do
31
+ it "should return the category's products" do
32
+ products = category.products
33
+ products.should be_an_instance_of(Array)
34
+
35
+ product = products.first
36
+ product.should be_an_instance_of(Dugway::Drops::ProductDrop)
37
+ product.name.should == 'My Product'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Drops::ContactDrop do
4
+ let(:params) {{
5
+ :name => 'Joe',
6
+ :email => 'joe@example.com',
7
+ :subject => 'Testing',
8
+ :message => 'Hi there',
9
+ :captcha => 'rQ9pC'
10
+ }}
11
+
12
+ let(:env) {
13
+ Rack::MockRequest::DEFAULT_ENV.update({
14
+ 'PATH_INFO' => '/contact'
15
+ })}
16
+
17
+ let(:request) { Dugway::Request.new(env) }
18
+
19
+ let(:errors) {
20
+ []
21
+ }
22
+
23
+ let(:contact) {
24
+ Dugway::Drops::ContactDrop.new.tap { |drop|
25
+ drop.context = Liquid::Context.new([{}, { 'errors' => errors }], {}, { :params => params, :errors => errors, :request => request })
26
+ }
27
+ }
28
+
29
+ describe "#name" do
30
+ it "should return the name param" do
31
+ contact.name.should == params[:name]
32
+ end
33
+
34
+ describe "when the name param is blank" do
35
+ before(:each) do
36
+ params.merge!(:name => nil)
37
+ end
38
+
39
+ it "should return an empty string" do
40
+ contact.name.should == ''
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#email" do
46
+ it "should return the email param" do
47
+ contact.email.should == params[:email]
48
+ end
49
+
50
+ describe "when the email param is blank" do
51
+ before(:each) do
52
+ params.merge!(:email => nil)
53
+ end
54
+
55
+ it "should return an empty string" do
56
+ contact.email.should == ''
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "#subject" do
62
+ it "should return the subject param" do
63
+ contact.subject.should == params[:subject]
64
+ end
65
+
66
+ describe "when the subject param is blank" do
67
+ before(:each) do
68
+ params.merge!(:subject => nil)
69
+ end
70
+
71
+ it "should return an empty string" do
72
+ contact.subject.should == ''
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#message" do
78
+ it "should return the message param" do
79
+ contact.message.should == params[:message]
80
+ end
81
+
82
+ describe "when the message param is blank" do
83
+ before(:each) do
84
+ params.merge!(:message => nil)
85
+ end
86
+
87
+ it "should return an empty string" do
88
+ contact.message.should == ''
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "#captcha" do
94
+ it "should return a captcha image" do
95
+ contact.captcha.should == %{<img id="captcha_image" src="https://s3.amazonaws.com/bigcartel/captcha/28e3d1288cbc70c0cd1a2d10845f8e11e1a90d14.png">}
96
+ end
97
+ end
98
+
99
+ describe "#sent" do
100
+ it "should return false before the form has been sent" do
101
+ contact.sent.should be(false)
102
+ end
103
+
104
+ it "should return false when not on the contact page" do
105
+ request.stub(:path) { '/blah' }
106
+ request.stub(:post?) { true }
107
+ contact.sent.should be(false)
108
+ end
109
+
110
+ describe "when there are errors" do
111
+ let(:errors) { ['There was a problem'] }
112
+
113
+ it "should return false" do
114
+ request.stub(:post?) { true }
115
+ contact.sent.should be(false)
116
+ end
117
+ end
118
+
119
+ it "should return true when the form has been sent" do
120
+ request.stub(:post?) { true }
121
+ contact.sent.should be(true)
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Drops::CountryDrop do
4
+ let(:country) { Dugway::Drops::CountryDrop.new(Dugway.store.country) }
5
+
6
+ describe "#name" do
7
+ it "should return the country's name" do
8
+ country.name.should == 'United States'
9
+ end
10
+ end
11
+
12
+ describe "#code" do
13
+ it "should return the country's code" do
14
+ country.code.should == 'US'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Drops::ImageDrop do
4
+ let(:image) { Dugway::Drops::ImageDrop.new(Dugway.store.products.first['images'].first) }
5
+
6
+ describe "#url" do
7
+ it "should return the image's url" do
8
+ image.url.should == 'http://cache1.bigcartel.com/product_images/92599166/mens_tee_1.jpg'
9
+ end
10
+ end
11
+
12
+ describe "#width" do
13
+ it "should return the image's width" do
14
+ image.width.should == 475
15
+ end
16
+ end
17
+
18
+ describe "#height" do
19
+ it "should return the image's height" do
20
+ image.height.should == 500
21
+ end
22
+ end
23
+ end