Sha256: e8b310d98637e65bc670a175a81af6a2e4b34b87e1afbd198e53ca6fc18f957c

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

describe TrophyHelper, :type => :helper do
  describe "#display_trophy_link" do
    let(:user) { FactoryGirl.create(:user) }
    let(:id) { '9999' }

    let(:text_attributes) { '[data-add-text="Highlight File on Profile"][data-remove-text="Unhighlight File"]' }
    let(:url_attribute) { "[data-url=\"/users/#{user.to_param}/trophy?file_id=#{id}\"]" }

    context "when there is no trophy" do
      it "should have a link for highlighting" do
        out = helper.display_trophy_link(user, id) { |text| "foo #{text} bar" }
        node = Capybara::Node::Simple.new(out)
        expect(node).to have_selector("a.trophy-class.trophy-off#{text_attributes}#{url_attribute}")
        expect(node).to have_link 'foo Highlight File on Profile bar', href: '#'
      end
    end

    context "when there is a trophy" do
      before do
        user.trophies.create(generic_file_id: id)
      end

      it "should have a link for highlighting" do
        out = helper.display_trophy_link(user, id) { |text| "foo #{text} bar" }
        node = Capybara::Node::Simple.new(out)
        expect(node).to have_selector("a.trophy-class.trophy-on#{text_attributes}#{url_attribute}")
        expect(node).to have_link 'foo Unhighlight File bar', href: '#'
      end

      it "should allow removerow to be passed" do
        out = helper.display_trophy_link(user, id, data: {removerow: true}) { |text| "foo #{text} bar" }
        node = Capybara::Node::Simple.new(out)
        expect(node).to have_selector("a.trophy-class.trophy-on[data-removerow=\"true\"]#{text_attributes}#{url_attribute}")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sufia-6.2.0 spec/helpers/trophy_helper_spec.rb
sufia-6.1.0 spec/helpers/trophy_helper_spec.rb
sufia-6.0.0 spec/helpers/trophy_helper_spec.rb
sufia-6.0.0.rc4 spec/helpers/trophy_helper_spec.rb
sufia-6.0.0.rc3 spec/helpers/trophy_helper_spec.rb