Sha256: 8d92ee26e1674a8f0e8766682e115bbac06fa94a6b10d295b5c37e76a94e3727

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

require "spec_helper"

module Spree
  describe PinterestHelper do
    describe "pin_it_button output" do
      let(:product) { Factory(:product) }
      let(:output) { helper.pin_it_button(product) }

      context "when the product contains no images" do
        subject { output }
        it { should be_nil }
      end

      context "when the product does contain images" do
        let(:url) { "http://mystore.com/image1.gif" }

        before do
          product.images << Factory.build(:image)
          product.save!
        end

        describe "href" do
          let(:expected_output) do
            image = product.images.first
            "http://pinterest.com/pin/create/button/?url=#{escape(spree.product_url(product, :host => "test.host"))}&media=#{escape(image.attachment.url)}&description=#{escape(product.name)}"
          end

          subject { Nokogiri::HTML(output).xpath("//a/@href").text }

          it { should == expected_output }

          def escape(string)
            URI.escape string, /[^#{URI::PATTERN::UNRESERVED}]/
          end

          def spree
            Spree::Core::Engine.routes.url_helpers
          end
        end

        describe "class" do
          subject { Nokogiri::HTML(output).xpath("//a/@class").text }

          it { should == "pin-it-button" }
        end

        describe "class" do
          subject { Nokogiri::HTML(output).xpath("//a/@count-layout").text }

          it { should == "horizontal" }
        end

        it "is html safe" do
          link_output = double(:link_output)
          link_output.should_receive(:html_safe)
          helper.stub(:link_to).and_return(link_output)

          helper.pin_it_button product
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_pinterest-0.2.0 spec/helpers/spree/pinterest_helper_spec.rb