Sha256: e42fde122ff6cc39339686a290217cdfd42a5846066573c634b1fa5c8ee9f54b

Contents?: true

Size: 1.8 KB

Versions: 5

Compression:

Stored size: 1.8 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::Representer::JSON/
  end

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

    assert_file representer_path('singer'), /include Roar::Representer::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

5 entries across 5 versions & 1 rubygems

Version Path
roar-rails-1.0.1 test/representer_generator_test.rb
roar-rails-1.0.0 test/representer_generator_test.rb
roar-rails-0.1.6 test/representer_generator_test.rb
roar-rails-0.1.5 test/representer_generator_test.rb
roar-rails-0.1.4 test/representer_generator_test.rb