Sha256: 3c6511818f24202aad1998fe1da4a5f8ffb267021dc5f61e115d1549930eccc7

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

# Non-database model derived from: http://railscasts.com/episodes/219-active-model
module Calagator

class ModelWithoutDecodeHack
  include ActiveModel::Callbacks
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  define_callbacks :validate

  attr_accessor :kitten

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def persisted?
    false
  end

  def attributes
    { :kitten => kitten }
  end
end

# Same as above but with the mixin
class ModelWithDecodeHack < ModelWithoutDecodeHack
  include DecodeHtmlEntitiesHack
end

describe DecodeHtmlEntitiesHack, :type => :model do
  let(:encoded_string) { "cute &amp; furry" }
  let(:decoded_string) { "cute & furry" }

  it "should not modify attributes in models that don't include it" do
    record = ModelWithoutDecodeHack.new(:kitten => encoded_string)
    expect(record).to be_valid
    expect(record.kitten).to eq encoded_string
  end

  it "should modify attributes in models that include it" do
    record = ModelWithDecodeHack.new(:kitten => encoded_string)
    expect(record).to be_valid
    expect(record.kitten).to eq decoded_string
  end

end

end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
calagator-1.0.0 spec/lib/calagator/decode_html_entities_hack_spec.rb
grokus-1.0.0.9 spec/lib/calagator/decode_html_entities_hack_spec.rb
grokus-1.0.0.8 spec/lib/calagator/decode_html_entities_hack_spec.rb
grokus-1.0.0.7 spec/lib/calagator/decode_html_entities_hack_spec.rb
grokus-1.0.0.6 spec/lib/calagator/decode_html_entities_hack_spec.rb
grokus-1.0.0.5 spec/lib/calagator/decode_html_entities_hack_spec.rb
grokus-1.0.0.3 spec/lib/calagator/decode_html_entities_hack_spec.rb
grokus-1.0.0.2 spec/lib/calagator/decode_html_entities_hack_spec.rb
grokus-1.0.0.1 spec/lib/calagator/decode_html_entities_hack_spec.rb
calagator-1.0.0.rc3 spec/lib/calagator/decode_html_entities_hack_spec.rb
calagator-1.0.0.rc2 spec/lib/calagator/decode_html_entities_hack_spec.rb
calagator-1.0.0.rc1 spec/lib/calagator/decode_html_entities_hack_spec.rb
calagator-0.0.1.pre1 spec/lib/calagator/decode_html_entities_hack_spec.rb