spree_pinterest 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -9,3 +9,4 @@ nbproject
9
9
  *.swp
10
10
  spec/dummy
11
11
  *.gem
12
+ Gemfile.lock
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --colour
2
+ --format Fuubar
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.2.0
2
+
3
+ * Always use product_url when pinning
4
+
1
5
  # 0.1.1
2
6
 
3
7
  * Relaxed dependency on `spree_core`
data/Gemfile CHANGED
@@ -1,7 +1,17 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ group :development do
4
+ gem "guard-rspec"
5
+ end
6
+
3
7
  group :test do
4
8
  gem 'ffaker'
9
+ gem "fuubar"
10
+ gem "nokogiri"
11
+
12
+ # See https://github.com/spree/spree/issues/1155. This can be removed
13
+ # once they push the next release.
14
+ gem "spree", :git => "git://github.com/spree/spree.git"
5
15
  end
6
16
 
7
17
  if RUBY_VERSION < "1.9"
data/Guardfile ADDED
@@ -0,0 +1,17 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2, :cli => "--format Fuubar --fail-fast" do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+ end
17
+
@@ -1,9 +1,9 @@
1
1
  module Spree
2
2
  module PinterestHelper
3
3
  def pin_it_button(product)
4
- return if product.images.blank?
4
+ return if product.images.empty?
5
5
 
6
- url = escape request.url
6
+ url = escape spree.product_url(product)
7
7
  media = escape product.images.first.attachment.url
8
8
  description = escape product.name
9
9
 
@@ -1,3 +1,3 @@
1
1
  module SpreePinterest
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/spec/factories.rb ADDED
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :image, :class => 'Spree::Image' do
3
+ attachment File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/lambo.jpg'))
4
+ end
5
+ end
Binary file
@@ -0,0 +1,63 @@
1
+ require "spec_helper"
2
+
3
+ module Spree
4
+ describe PinterestHelper do
5
+ describe "pin_it_button output" do
6
+ let(:product) { Factory(:product) }
7
+ let(:output) { helper.pin_it_button(product) }
8
+
9
+ context "when the product contains no images" do
10
+ subject { output }
11
+ it { should be_nil }
12
+ end
13
+
14
+ context "when the product does contain images" do
15
+ let(:url) { "http://mystore.com/image1.gif" }
16
+
17
+ before do
18
+ product.images << Factory.build(:image)
19
+ product.save!
20
+ end
21
+
22
+ describe "href" do
23
+ let(:expected_output) do
24
+ image = product.images.first
25
+ "http://pinterest.com/pin/create/button/?url=#{escape(spree.product_url(product, :host => "test.host"))}&media=#{escape(image.attachment.url)}&description=#{escape(product.name)}"
26
+ end
27
+
28
+ subject { Nokogiri::HTML(output).xpath("//a/@href").text }
29
+
30
+ it { should == expected_output }
31
+
32
+ def escape(string)
33
+ URI.escape string, /[^#{URI::PATTERN::UNRESERVED}]/
34
+ end
35
+
36
+ def spree
37
+ Spree::Core::Engine.routes.url_helpers
38
+ end
39
+ end
40
+
41
+ describe "class" do
42
+ subject { Nokogiri::HTML(output).xpath("//a/@class").text }
43
+
44
+ it { should == "pin-it-button" }
45
+ end
46
+
47
+ describe "class" do
48
+ subject { Nokogiri::HTML(output).xpath("//a/@count-layout").text }
49
+
50
+ it { should == "horizontal" }
51
+ end
52
+
53
+ it "is html safe" do
54
+ link_output = double(:link_output)
55
+ link_output.should_receive(:html_safe)
56
+ helper.stub(:link_to).and_return(link_output)
57
+
58
+ helper.pin_it_button product
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }
11
11
 
12
12
  # Requires factories defined in spree_core
13
13
  require 'spree/core/testing_support/factories'
14
+ FactoryGirl.find_definitions
14
15
 
15
16
  RSpec.configure do |config|
16
17
  # == Mock Framework
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_pinterest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-02 00:00:00.000000000 Z
12
+ date: 2012-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core
16
- requirement: &70109602092360 !ruby/object:Gem::Requirement
16
+ requirement: &70100608233560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70109602092360
24
+ version_requirements: *70100608233560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capybara
27
- requirement: &70109602091760 !ruby/object:Gem::Requirement
27
+ requirement: &70100608228740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70109602091760
35
+ version_requirements: *70100608228740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: factory_girl
38
- requirement: &70109602090980 !ruby/object:Gem::Requirement
38
+ requirement: &70100608227720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70109602090980
46
+ version_requirements: *70100608227720
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ffaker
49
- requirement: &70109602090260 !ruby/object:Gem::Requirement
49
+ requirement: &70100608227020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70109602090260
57
+ version_requirements: *70100608227020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec-rails
60
- requirement: &70109602089320 !ruby/object:Gem::Requirement
60
+ requirement: &70100608226500 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '2.7'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70109602089320
68
+ version_requirements: *70100608226500
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &70109602088880 !ruby/object:Gem::Requirement
71
+ requirement: &70100608225820 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70109602088880
79
+ version_requirements: *70100608225820
80
80
  description: This extension provides a Pinterest "Pin it" button for your Spree product
81
81
  images.
82
82
  email: chad@genuitytech.com
@@ -88,6 +88,7 @@ files:
88
88
  - .rspec
89
89
  - CHANGELOG.md
90
90
  - Gemfile
91
+ - Guardfile
91
92
  - LICENSE
92
93
  - README.md
93
94
  - Rakefile
@@ -106,6 +107,9 @@ files:
106
107
  - lib/spree_pinterest/engine.rb
107
108
  - lib/spree_pinterest/version.rb
108
109
  - script/rails
110
+ - spec/factories.rb
111
+ - spec/fixtures/lambo.jpg
112
+ - spec/helpers/spree/pinterest_helper_spec.rb
109
113
  - spec/spec_helper.rb
110
114
  - spree_pinterest.gemspec
111
115
  homepage: http://genuitytech.com
@@ -134,4 +138,7 @@ signing_key:
134
138
  specification_version: 3
135
139
  summary: Pinterest button for Spree products
136
140
  test_files:
141
+ - spec/factories.rb
142
+ - spec/fixtures/lambo.jpg
143
+ - spec/helpers/spree/pinterest_helper_spec.rb
137
144
  - spec/spec_helper.rb