Sha256: 9c39a4595b7e24443be4c38c913c1271e44d14b0ffff82d059c569235ca5cb77

Contents?: true

Size: 1.77 KB

Versions: 4

Compression:

Stored size: 1.77 KB

Contents

require 'test_helper'
require 'rails/generators'

require 'generators/rails/representer_generator'

class RepresentetGeneratorTest < Rails::Generators::TestCase
  destination File.join(Rails.root, "tmp")
  setup :prepare_destination
  tests Rails::Generators::RepresenterGenerator

  test "create a representer with correct class_name" do
    run_generator %w(singer)

    assert_file representer_path('singer'), /module SingerRepresenter/
  end

  test "create a representer with correct properties" do
    run_generator %w(singer name id)

    assert_file representer_path('singer'), /property :name/
    assert_file representer_path('singer'), /property :id/
  end

  test "create a representer with default json support" do
    run_generator %w(singer)

    assert_file representer_path('singer'), /include Roar::JSON/
  end

  test "create a representer with different format support" do
    run_generator %w(singer --format=XML)

    assert_file representer_path('singer'), /include Roar::XML/
  end

  test "create a representer with property, class and exnted" do
    run_generator %w(singer band:band:group_representer instrument:equipament:instrument_representer)

    assert_file representer_path('singer'),
      /property :band, :class => Band, :extend => GroupRepresenter/
    assert_file representer_path('singer'),
      /property :instrument, :class => Equipament, :extend => InstrumentRepresenter/
  end

  test "create a representer with property and class only" do
    run_generator %w(singer band:band instrument:equipament)

    assert_file representer_path('singer'),
      /property :band, :class => Band/
    assert_file representer_path('singer'),
      /property :instrument, :class => Equipament/
  end

  def representer_path(name)
    "app/representers/#{name}_representer.rb"
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/roar-rails-1.2.0/test/representer_generator_test.rb
roar-rails-1.2.0 test/representer_generator_test.rb
roar-rails-1.1.0 test/representer_generator_test.rb
roar-rails-1.0.2 test/representer_generator_test.rb