Sha256: 3075e01d29d3b42adef046b2bad5ca5ad08c8eef92eb381a098e99a3c2a07633

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require 'draper'
require 'rspec'

require 'active_model/naming'
require_relative '../app/decorators/post_decorator'

Draper::ViewContext.test_strategy :fast

Post = Struct.new(:id) { extend ActiveModel::Naming }

describe PostDecorator do
  let(:decorator) { PostDecorator.new(object) }
  let(:object) { Post.new(42) }

  it "can use built-in helpers" do
    expect(decorator.truncated).to eq "Once upon a..."
  end

  it "can use built-in private helpers" do
    expect(decorator.html_escaped).to eq "<script>danger</script>"
  end

  it "can't use user-defined helpers from app/helpers" do
    expect{decorator.hello_world}.to raise_error NoMethodError, /hello_world/
  end

  it "can't use path helpers" do
    expect{decorator.path_with_model}.to raise_error NoMethodError, /post_path/
  end

  it "can't use url helpers" do
    expect{decorator.url_with_model}.to raise_error NoMethodError, /post_url/
  end

  it "can't be passed implicitly to url_for" do
    expect{decorator.link}.to raise_error
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
draper-1.4.0 spec/dummy/fast_spec/post_decorator_spec.rb
draper-1.3.1 spec/dummy/fast_spec/post_decorator_spec.rb
draper-1.3.0 spec/dummy/fast_spec/post_decorator_spec.rb
draper-1.2.1 spec/dummy/fast_spec/post_decorator_spec.rb