require 'spec_helper'
describe CrazyHarry::Translate do
# Add attribute: "partner" to all tags
# Transform "lodging" to "hotel"
let(:harry) { CrazyHarry }
it "should be able to add an attribute to all tags" do
harry.fragment( 'a
c
' ).translate!( add_attributes: { class: 'from-partner'} ).to_s.should ==
'ac
'
end
it "should be able to add multiple attributes to all tags" do
harry.fragment( 'ac
' ).translate!( add_attributes: { class: 'boo', bubba: 'beau' } ).to_s.should ==
'ac
'
end
it "should append information to existing attributes" do
harry.fragment( 'Lorem
' ).translate!( add_attributes: { class: 'from-partner'} ).to_s.should ==
'Lorem
'
end
it "should be able to tranlate free text in the fragment, preservering case" do
harry.fragment( 'Lodging
lodging' ).translate!( from_text: 'lodging', to_text: 'hotel' ).to_s.should ==
'Hotel
hotel'
end
context "targeting and scope" do
it "should only add attributes to targeted content" do
harry.fragment( 'Location:
Saigon
' ).translate!( add_attributes: { class: 'partner' }, text: 'Location:' ).to_s.should ==
'Location:
Saigon
'
end
it "should be able to scope changes to specific blocks" do
harry.fragment( 'Hotel
Hotel
Tent' ).translate!( add_attributes: { class: 'ugly' }, scope: 'p' ).to_s.should ==
'Hotel
Hotel
Tent'
end
end
end