dugway 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +3 -0
  3. data/Gemfile +2 -0
  4. data/README.md +151 -0
  5. data/Rakefile +12 -0
  6. data/bin/dugway +7 -0
  7. data/dugway.gemspec +43 -0
  8. data/lib/dugway.rb +66 -0
  9. data/lib/dugway/application.rb +147 -0
  10. data/lib/dugway/cart.rb +144 -0
  11. data/lib/dugway/cli.rb +22 -0
  12. data/lib/dugway/cli/build.rb +56 -0
  13. data/lib/dugway/cli/create.rb +71 -0
  14. data/lib/dugway/cli/server.rb +37 -0
  15. data/lib/dugway/cli/templates/Gemfile.tt +2 -0
  16. data/lib/dugway/cli/templates/config.tt +24 -0
  17. data/lib/dugway/cli/templates/gitignore.tt +9 -0
  18. data/lib/dugway/cli/templates/source/cart.html +40 -0
  19. data/lib/dugway/cli/templates/source/checkout.html +33 -0
  20. data/lib/dugway/cli/templates/source/contact.html +37 -0
  21. data/lib/dugway/cli/templates/source/home.html +25 -0
  22. data/lib/dugway/cli/templates/source/images/badge.png +0 -0
  23. data/lib/dugway/cli/templates/source/javascripts/cart.js.coffee +7 -0
  24. data/lib/dugway/cli/templates/source/javascripts/product.js.coffee +7 -0
  25. data/lib/dugway/cli/templates/source/layout.html +101 -0
  26. data/lib/dugway/cli/templates/source/maintenance.html +20 -0
  27. data/lib/dugway/cli/templates/source/product.html +65 -0
  28. data/lib/dugway/cli/templates/source/products.html +25 -0
  29. data/lib/dugway/cli/templates/source/screenshot.jpg +0 -0
  30. data/lib/dugway/cli/templates/source/scripts.js +19 -0
  31. data/lib/dugway/cli/templates/source/settings.json +71 -0
  32. data/lib/dugway/cli/templates/source/styles.css +27 -0
  33. data/lib/dugway/cli/templates/source/stylesheets/cart.css.sass +38 -0
  34. data/lib/dugway/cli/templates/source/stylesheets/layout.css.sass +103 -0
  35. data/lib/dugway/cli/templates/source/stylesheets/product.css.sass +19 -0
  36. data/lib/dugway/cli/templates/source/stylesheets/products.css.sass +20 -0
  37. data/lib/dugway/cli/templates/source/stylesheets/vendor/normalize.css +396 -0
  38. data/lib/dugway/cli/templates/source/success.html +5 -0
  39. data/lib/dugway/controller.rb +148 -0
  40. data/lib/dugway/data/locales/cs.yml +26 -0
  41. data/lib/dugway/data/locales/da.yml +26 -0
  42. data/lib/dugway/data/locales/en-AU.yml +26 -0
  43. data/lib/dugway/data/locales/en-GB.yml +26 -0
  44. data/lib/dugway/data/locales/en-PH.yml +27 -0
  45. data/lib/dugway/data/locales/en-US.yml +26 -0
  46. data/lib/dugway/data/locales/es-MX.yml +26 -0
  47. data/lib/dugway/data/locales/eu.yml +26 -0
  48. data/lib/dugway/data/locales/gsw-CH.yml +26 -0
  49. data/lib/dugway/data/locales/hu.yml +26 -0
  50. data/lib/dugway/data/locales/il.yml +26 -0
  51. data/lib/dugway/data/locales/ja.yml +30 -0
  52. data/lib/dugway/data/locales/ms-MY.yml +26 -0
  53. data/lib/dugway/data/locales/nb.yml +22 -0
  54. data/lib/dugway/data/locales/pl.yml +27 -0
  55. data/lib/dugway/data/locales/pt-BR.yml +26 -0
  56. data/lib/dugway/data/locales/sv-SE.yml +26 -0
  57. data/lib/dugway/data/locales/th.yml +26 -0
  58. data/lib/dugway/data/locales/tr.yml +29 -0
  59. data/lib/dugway/data/locales/zh-TW.yml +30 -0
  60. data/lib/dugway/data/theme_fonts.yml +151 -0
  61. data/lib/dugway/extensions/time.rb +15 -0
  62. data/lib/dugway/liquid/drops/account_drop.rb +17 -0
  63. data/lib/dugway/liquid/drops/artist_drop.rb +9 -0
  64. data/lib/dugway/liquid/drops/artists_drop.rb +13 -0
  65. data/lib/dugway/liquid/drops/base_drop.rb +59 -0
  66. data/lib/dugway/liquid/drops/cart_drop.rb +13 -0
  67. data/lib/dugway/liquid/drops/cart_item_drop.rb +21 -0
  68. data/lib/dugway/liquid/drops/categories_drop.rb +13 -0
  69. data/lib/dugway/liquid/drops/category_drop.rb +9 -0
  70. data/lib/dugway/liquid/drops/contact_drop.rb +29 -0
  71. data/lib/dugway/liquid/drops/country_drop.rb +6 -0
  72. data/lib/dugway/liquid/drops/currency_drop.rb +6 -0
  73. data/lib/dugway/liquid/drops/image_drop.rb +6 -0
  74. data/lib/dugway/liquid/drops/page_drop.rb +13 -0
  75. data/lib/dugway/liquid/drops/pages_drop.rb +9 -0
  76. data/lib/dugway/liquid/drops/product_drop.rb +101 -0
  77. data/lib/dugway/liquid/drops/product_option_drop.rb +27 -0
  78. data/lib/dugway/liquid/drops/products_drop.rb +75 -0
  79. data/lib/dugway/liquid/drops/shipping_option_drop.rb +13 -0
  80. data/lib/dugway/liquid/drops/theme_drop.rb +23 -0
  81. data/lib/dugway/liquid/filters/comparison_filters.rb +48 -0
  82. data/lib/dugway/liquid/filters/core_filters.rb +138 -0
  83. data/lib/dugway/liquid/filters/default_pagination.rb +35 -0
  84. data/lib/dugway/liquid/filters/font_filters.rb +9 -0
  85. data/lib/dugway/liquid/filters/url_filters.rb +66 -0
  86. data/lib/dugway/liquid/filters/util_filters.rb +119 -0
  87. data/lib/dugway/liquid/tags/checkout_form.rb +9 -0
  88. data/lib/dugway/liquid/tags/get.rb +58 -0
  89. data/lib/dugway/liquid/tags/paginate.rb +129 -0
  90. data/lib/dugway/liquifier.rb +122 -0
  91. data/lib/dugway/logger.rb +16 -0
  92. data/lib/dugway/request.rb +36 -0
  93. data/lib/dugway/store.rb +166 -0
  94. data/lib/dugway/template.rb +44 -0
  95. data/lib/dugway/theme.rb +145 -0
  96. data/lib/dugway/theme_font.rb +68 -0
  97. data/lib/dugway/version.rb +3 -0
  98. data/spec/fixtures/store/page/about-us.js +1 -0
  99. data/spec/fixtures/store/products.js +1 -0
  100. data/spec/fixtures/store/store.js +1 -0
  101. data/spec/fixtures/theme/cart.html +33 -0
  102. data/spec/fixtures/theme/checkout.html +31 -0
  103. data/spec/fixtures/theme/contact.html +37 -0
  104. data/spec/fixtures/theme/home.html +38 -0
  105. data/spec/fixtures/theme/images/bc_badge.png +0 -0
  106. data/spec/fixtures/theme/javascripts/one.js +3 -0
  107. data/spec/fixtures/theme/javascripts/two.js.coffee +2 -0
  108. data/spec/fixtures/theme/layout.html +77 -0
  109. data/spec/fixtures/theme/maintenance.html +17 -0
  110. data/spec/fixtures/theme/product.html +73 -0
  111. data/spec/fixtures/theme/products.html +41 -0
  112. data/spec/fixtures/theme/screenshot.jpg +0 -0
  113. data/spec/fixtures/theme/scripts.js +2 -0
  114. data/spec/fixtures/theme/settings.json +55 -0
  115. data/spec/fixtures/theme/styles.css +4 -0
  116. data/spec/fixtures/theme/stylesheets/one.css +3 -0
  117. data/spec/fixtures/theme/stylesheets/two.css.sass +4 -0
  118. data/spec/fixtures/theme/success.html +5 -0
  119. data/spec/spec_helper.rb +24 -0
  120. data/spec/units/dugway/request_spec.rb +206 -0
  121. data/spec/units/dugway/store_spec.rb +194 -0
  122. data/spec/units/dugway/template_spec.rb +145 -0
  123. data/spec/units/dugway/theme_font_spec.rb +136 -0
  124. data/spec/units/dugway_spec.rb +9 -0
  125. metadata +549 -0
@@ -0,0 +1,194 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Store do
4
+ let(:store) { Dugway::Store.new('dugway') }
5
+
6
+ describe "#account" do
7
+ it "should return account params" do
8
+ store.account.should be_present
9
+ store.account['name'].should == 'Dugway'
10
+ store.account['url'].should == 'http://dugway.bigcartel.com'
11
+ end
12
+ end
13
+
14
+ describe "#theme_pages" do
15
+ it "should return an array of the default theme pages" do
16
+ store.theme_pages.should be_present
17
+ store.theme_pages.size.should == 8
18
+ store.theme_pages.first.should == { 'name' => 'Home', 'permalink' => 'home', 'url' => '/', 'category' => 'theme' }
19
+ end
20
+ end
21
+
22
+ describe "#custom_pages" do
23
+ it "should return an array of the store's custom pages" do
24
+ store.custom_pages.should be_present
25
+ store.custom_pages.size.should == 1
26
+ store.custom_pages.first.should == { 'category' => 'custom', 'content' => "<p>We're really cool!</p>", 'permalink' => 'about-us', 'name' => 'About Us', 'id' => 95821979, 'url' => '/about-us' }
27
+ end
28
+ end
29
+
30
+ describe "#pages" do
31
+ it "should return an array of the combined theme and custom pages" do
32
+ store.pages.should be_present
33
+ store.pages.size.should == 9
34
+ store.pages.first.should == { 'name' => 'Home', 'permalink' => 'home', 'url' => '/', 'category' => 'theme' }
35
+ store.pages.last.should == { 'category' => 'custom', 'content' => "<p>We're really cool!</p>", 'permalink' => 'about-us', 'name' => 'About Us', 'id' => 95821979, 'url' => '/about-us' }
36
+ end
37
+ end
38
+
39
+ describe "#page" do
40
+ it "should return a theme page by permalink" do
41
+ store.page('home').should == { 'name' => 'Home', 'permalink' => 'home', 'url' => '/', 'category' => 'theme' }
42
+ end
43
+
44
+ it "should return a custom page by permalink" do
45
+ store.page('about-us').should == { 'category' => 'custom', 'content' => "<p>We're really cool!</p>", 'permalink' => 'about-us', 'name' => 'About Us', 'id' => 95821979, 'url' => '/about-us' }
46
+ end
47
+
48
+ it "should return nil with a bad permalink" do
49
+ store.page('blah').should be_nil
50
+ end
51
+ end
52
+
53
+ describe "#categories" do
54
+ it "should return an array of the store's categories" do
55
+ store.categories.should be_present
56
+ store.categories.size.should == 4
57
+ store.categories.first.should == { 'permalink' => 'cds', 'name' => 'CDs', 'id' => 4615184, 'url' => '/category/cds' }
58
+ end
59
+ end
60
+
61
+ describe "#category" do
62
+ it "should return a category by permalink" do
63
+ store.category('cds').should == { 'permalink' => 'cds', 'name' => 'CDs', 'id' => 4615184, 'url' => '/category/cds' }
64
+ end
65
+
66
+ it "should return nil with a bad permalink" do
67
+ store.category('blah').should be_nil
68
+ end
69
+ end
70
+
71
+ describe "#category_products" do
72
+ it "should return an array of products for that category" do
73
+ products = store.category_products('tees')
74
+ products.size.should == 2
75
+ products.first['name'].should == 'My Product'
76
+ end
77
+
78
+ it "should return an empty array with a bad permalink" do
79
+ store.category_products('blah').should == []
80
+ end
81
+ end
82
+
83
+ describe "#artists" do
84
+ it "should return an array of the store's artists" do
85
+ store.artists.should be_present
86
+ store.artists.size.should == 2
87
+ store.artists.first.should == { 'permalink' => 'artist-one', 'name' => 'Artist One', 'id' => 176141, 'url' => '/artist/artist-one' }
88
+ end
89
+ end
90
+
91
+ describe "#artist" do
92
+ it "should return an artist by permalink" do
93
+ store.artist('artist-one').should == { 'permalink' => 'artist-one', 'name' => 'Artist One', 'id' => 176141, 'url' => '/artist/artist-one' }
94
+ end
95
+
96
+ it "should return nil with a bad permalink" do
97
+ store.artist('blah').should be_nil
98
+ end
99
+ end
100
+
101
+ describe "#artist_products" do
102
+ it "should return an array of products for that artist" do
103
+ products = store.artist_products('artist-one')
104
+ products.size.should == 1
105
+ products.first['name'].should == 'My Product'
106
+ end
107
+
108
+ it "should return an empty array with a bad permalink" do
109
+ store.artist_products('blah').should == []
110
+ end
111
+ end
112
+
113
+ describe "#products" do
114
+ it "should return an array of the store's products" do
115
+ store.products.should be_present
116
+ store.products.size.should == 3
117
+ store.products.first['name'].should == 'My Product'
118
+ end
119
+ end
120
+
121
+ describe "#product" do
122
+ it "should return a product by permalink" do
123
+ store.product('my-product')['name'].should == 'My Product'
124
+ end
125
+
126
+ it "should return nil with a bad permalink" do
127
+ store.product('blah').should be_nil
128
+ end
129
+ end
130
+
131
+ describe "#product_and_option" do
132
+ it "should a product and option by option id" do
133
+ product, option = store.product_and_option(29474321)
134
+ product['name'].should == 'My Product'
135
+ option['name'].should == 'Small'
136
+ end
137
+
138
+ it "should return nil with a bad option id" do
139
+ store.product_and_option(12345).should be_nil
140
+ end
141
+ end
142
+
143
+ describe "#previous_product" do
144
+ it "should return the previous product when there is one" do
145
+ store.previous_product('my-tee')['name'].should == 'My Product'
146
+ end
147
+
148
+ it "should return nil when there isn't one" do
149
+ store.previous_product('my-product').should be_nil
150
+ end
151
+ end
152
+
153
+ describe "#next_product" do
154
+ it "should return the next product when there is one" do
155
+ store.next_product('my-tee')['name'].should == 'My Print'
156
+ end
157
+
158
+ it "should return nil when there isn't one" do
159
+ store.next_product('my-print').should be_nil
160
+ end
161
+ end
162
+
163
+ describe "#search_products" do
164
+ it "should return an array of products for that search term" do
165
+ products = store.search_products('product')
166
+ products.size.should == 1
167
+ products.first['name'].should == 'My Product'
168
+ end
169
+
170
+ it "should return an empty array with a bad permalink" do
171
+ store.search_products('blah').should == []
172
+ end
173
+ end
174
+
175
+ describe "#country" do
176
+ it "returns the store's country" do
177
+ store.country.should == { 'name' => 'United States', 'id' => 43, 'code' => 'US' }
178
+ end
179
+ end
180
+
181
+ describe "#currency" do
182
+ it "returns the store's currency" do
183
+ store.currency.should == { 'sign' => '$', 'name' => 'U.S. Dollar', 'id' => 1, 'code' => 'USD' }
184
+ end
185
+ end
186
+
187
+ describe "#locale" do
188
+ it "returns the store's locale based on their currency" do
189
+ store.locale.should == 'en-US'
190
+ store.stub(:currency) {{ 'code' => 'JPY' }}
191
+ store.locale.should == 'ja'
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::Template do
4
+ let(:name) { 'home.html' }
5
+ let(:template) { Dugway::Template.new(name) }
6
+
7
+ describe "#content" do
8
+ it "returns the content of the file" do
9
+ template.content.should == Dugway.theme.file_content(name)
10
+ end
11
+ end
12
+
13
+ describe "#content_type" do
14
+ describe "for HTML" do
15
+ it "returns the proper content type" do
16
+ template.content_type.should == 'text/html'
17
+ end
18
+ end
19
+
20
+ describe "for CSS" do
21
+ let(:name) { 'styles.css' }
22
+
23
+ it "returns the proper content type" do
24
+ template.content_type.should == 'text/css'
25
+ end
26
+ end
27
+
28
+ describe "for JS" do
29
+ let(:name) { 'scripts.js' }
30
+
31
+ it "returns the proper content type" do
32
+ template.content_type.should == 'application/javascript'
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#extension" do
38
+ describe "for HTML" do
39
+ it "returns the proper extension" do
40
+ template.extension.should == '.html'
41
+ end
42
+ end
43
+
44
+ describe "for CSS" do
45
+ let(:name) { 'styles.css' }
46
+
47
+ it "returns the proper extension" do
48
+ template.extension.should == '.css'
49
+ end
50
+ end
51
+
52
+ describe "for JS" do
53
+ let(:name) { 'scripts.js' }
54
+
55
+ it "returns the proper extension" do
56
+ template.extension.should == '.js'
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "#html?" do
62
+ describe "when it's an HTML template" do
63
+ it "returns true" do
64
+ template.html?.should be_true
65
+ end
66
+ end
67
+
68
+ describe "when it's not an HTML template" do
69
+ let(:name) { 'styles.css' }
70
+
71
+ it "returns false" do
72
+ template.html?.should be_false
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#standalone_html?" do
78
+ describe "for HTML pages with head_content" do
79
+ let(:name) { 'maintenance.html' }
80
+
81
+ it "returns true" do
82
+ template.standalone_html?.should be_true
83
+ end
84
+ end
85
+
86
+ describe "for HTML pages without head_content" do
87
+ it "returns false" do
88
+ template.standalone_html?.should be_false
89
+ end
90
+ end
91
+
92
+ describe "for non-HTML" do
93
+ let(:name) { 'styles.css' }
94
+
95
+ it "returns false" do
96
+ template.standalone_html?.should be_false
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "#render" do
102
+ let(:theme) { Dugway.theme }
103
+ let(:store) { Dugway::Store.new('dugway') }
104
+ let(:request) { Dugway::Request.new({ 'rack.url_scheme' => 'http', 'HTTP_HOST' => 'sexy.dev', 'PATH_INFO' => '/' }) }
105
+ let(:variables) { {} }
106
+ let(:layout) { theme.layout }
107
+ let(:content) { theme.file_content(name) }
108
+
109
+ describe "when rendering an embedded HTML template" do
110
+ it "calls renders properly with Liquifier" do
111
+ Dugway::Liquifier.any_instance.should_receive(:render).with(content, variables) { content }
112
+ Dugway::Liquifier.any_instance.should_receive(:render).with(layout, variables.update(:page_content => content))
113
+ template.render(request, variables)
114
+ end
115
+ end
116
+
117
+ describe "when rendering a standalone HTML template" do
118
+ let(:name) { 'maintenance.html' }
119
+
120
+ it "calls renders properly with Liquifier" do
121
+ Dugway::Liquifier.any_instance.should_receive(:render).with(content, variables)
122
+ template.render(request, variables)
123
+ end
124
+ end
125
+
126
+ describe "when rendering non-HTML template" do
127
+ let(:name) { 'scripts.js' }
128
+
129
+ it "doesn't liquify it" do
130
+ Dugway::Liquifier.any_instance.should_not_receive(:render)
131
+ template.render(request, variables).should == content
132
+ end
133
+ end
134
+
135
+ describe "when passing variables" do
136
+ let(:variables) { { :errors => ['one', 'two'] } }
137
+
138
+ it "calls renders properly with Liquifier" do
139
+ Dugway::Liquifier.any_instance.should_receive(:render).with(content, variables) { content }
140
+ Dugway::Liquifier.any_instance.should_receive(:render).with(layout, variables.update(:page_content => content))
141
+ template.render(request, variables)
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dugway::ThemeFont do
4
+ before(:each) do
5
+ # Start fresh each time, so stubs work
6
+ Dugway::ThemeFont.send(:remove_class_variable, :@@source) rescue nil
7
+ Dugway::ThemeFont.send(:remove_class_variable, :@@all) rescue nil
8
+ Dugway::ThemeFont.send(:remove_class_variable, :@@options) rescue nil
9
+ Dugway::ThemeFont.send(:remove_class_variable, :@@google_font_names) rescue nil
10
+ end
11
+
12
+ describe ".all" do
13
+ it "should return all theme fonts" do
14
+ Dugway::ThemeFont.all.should be_present
15
+ end
16
+
17
+ it "should be in alphabetical order" do
18
+ Dugway::ThemeFont.all.first.name.should == 'Amaranth'
19
+ Dugway::ThemeFont.all.last.name.should == 'Verdana'
20
+ end
21
+ end
22
+
23
+ describe ".options" do
24
+ before(:each) do
25
+ Dugway::ThemeFont.stub(:all) {[
26
+ Dugway::ThemeFont.new('One'),
27
+ Dugway::ThemeFont.new('Two'),
28
+ Dugway::ThemeFont.new('Three')
29
+ ]}
30
+ end
31
+
32
+ it "should return an array of all font names" do
33
+ Dugway::ThemeFont.options.should == ['One', 'Two', 'Three']
34
+ end
35
+ end
36
+
37
+ describe ".find_by_name" do
38
+ it "should return a font by its name" do
39
+ georgia = Dugway::ThemeFont.find_by_name('Georgia')
40
+ georgia.name.should == 'Georgia'
41
+ georgia.family.should == 'Georgia, "Times New Roman", Times, serif'
42
+ georgia.collection.should == 'default'
43
+ end
44
+
45
+ it "should return nil if the font doesn't exist" do
46
+ Dugway::ThemeFont.find_by_name('Blah').should be_nil
47
+ end
48
+ end
49
+
50
+ describe ".find_family_by_name" do
51
+ it "should return the font family by its name" do
52
+ Dugway::ThemeFont.find_family_by_name('Georgia').should == 'Georgia, "Times New Roman", Times, serif'
53
+ end
54
+
55
+ it "should return the font name if no font is found" do
56
+ Dugway::ThemeFont.find_family_by_name('Blah').should == 'Blah'
57
+ end
58
+ end
59
+
60
+ describe ".google_font_names" do
61
+ before(:each) do
62
+ Dugway::ThemeFont.stub(:all) {[
63
+ Dugway::ThemeFont.new('One Font', 'One Family', 'google'),
64
+ Dugway::ThemeFont.new('Two', 'Two Family', 'default'),
65
+ Dugway::ThemeFont.new('Three', 'Three Family', 'google')
66
+ ]}
67
+ end
68
+
69
+ it "returns a sorted array of font names in the google collection" do
70
+ Dugway::ThemeFont.google_font_names.should == ['One Font', 'Three']
71
+ end
72
+ end
73
+
74
+ describe ".google_font_url_for_fonts" do
75
+ it "should return a url for a given array of font names" do
76
+ Dugway::ThemeFont.google_font_url_for_fonts(['Matt Rules', 'Dude', 'Yeah']).should == "//fonts.googleapis.com/css?family=Matt+Rules|Dude|Yeah"
77
+ end
78
+
79
+ it "should return a url for a singular font in an array" do
80
+ Dugway::ThemeFont.google_font_url_for_fonts(['Matt Rules']).should == "//fonts.googleapis.com/css?family=Matt+Rules"
81
+ end
82
+ end
83
+
84
+ describe ".google_font_url_for_all_fonts" do
85
+ before(:each) do
86
+ Dugway::ThemeFont.stub(:all) {[
87
+ Dugway::ThemeFont.new('One Font', 'One Family', 'google'),
88
+ Dugway::ThemeFont.new('Two', 'Two Family', 'default'),
89
+ Dugway::ThemeFont.new('Three', 'Three Family', 'google')
90
+ ]}
91
+ end
92
+
93
+ it "should return a URL for all Google fonts" do
94
+ Dugway::ThemeFont.google_font_url_for_all_fonts.should == "//fonts.googleapis.com/css?family=One+Font|Three"
95
+ end
96
+ end
97
+
98
+ describe ".google_font_url_for_theme" do
99
+ let(:fonts) { { :header_font => {}, :body_font => {}, :paragraph_font => {} } }
100
+
101
+ before(:each) do
102
+ Dugway::Theme.any_instance.stub(:customization) { fonts }
103
+ Dugway::Theme.any_instance.stub(:fonts) { fonts }
104
+
105
+ Dugway::ThemeFont.stub(:all) {[
106
+ Dugway::ThemeFont.new('One Font', 'One Family', 'google'),
107
+ Dugway::ThemeFont.new('Two', 'Two Family', 'default'),
108
+ Dugway::ThemeFont.new('Three', 'Three Family', 'google')
109
+ ]}
110
+ end
111
+
112
+ describe "when it has multiple Google fonts" do
113
+ let(:fonts) { { :header_font => 'One Font', :body_font => 'Two', :paragraph_font => 'Three' } }
114
+
115
+ it "should return the correct URL" do
116
+ Dugway::ThemeFont.google_font_url_for_theme.should == "//fonts.googleapis.com/css?family=One+Font|Three"
117
+ end
118
+ end
119
+
120
+ describe "when it has one Google font" do
121
+ let(:fonts) { { :header_font => 'One Font', :body_font => 'Two' } }
122
+
123
+ it "should return the correct URL" do
124
+ Dugway::ThemeFont.google_font_url_for_theme.should == "//fonts.googleapis.com/css?family=One+Font"
125
+ end
126
+ end
127
+
128
+ describe "when it has no Google fonts" do
129
+ let(:fonts) { { :body_font => 'Two' } }
130
+
131
+ it "should return the correct URL" do
132
+ Dugway::ThemeFont.google_font_url_for_theme.should be_nil
133
+ end
134
+ end
135
+ end
136
+ end