Sha256: 0f39ca93604e5478ed4302da8a5f54db297f50d67eacbe5f8b513e27331ceb27

Contents?: true

Size: 1.5 KB

Versions: 14

Compression:

Stored size: 1.5 KB

Contents

require 'test_helper'
require 'rails'
require 'active_model/serializer/railtie'
require 'test_app'

class SerializerGeneratorTest < Rails::Generators::TestCase
  destination File.expand_path('../../../tmp', __FILE__)
  setup :prepare_destination

  tests Rails::Generators::SerializerGenerator
  arguments %w(account name:string description:text business:references)

  def test_generates_a_serializer_with_attributes_and_associations
    run_generator
    assert_file 'app/serializers/account_serializer.rb', /class AccountSerializer < ActiveModel::Serializer/ do |serializer|
      assert_match(/attributes :id, :name, :description/, serializer)
      assert_match(/has_one :business/, serializer)
    end
  end

  def test_generates_a_namespaced_serializer
    run_generator ['admin/account']
    assert_file 'app/serializers/admin/account_serializer.rb', /class Admin::AccountSerializer < ActiveModel::Serializer/
  end

  def test_uses_application_serializer_if_one_exists
    Object.const_set(:ApplicationSerializer, Class.new)
    run_generator
    assert_file 'app/serializers/account_serializer.rb', /class AccountSerializer < ApplicationSerializer/
  ensure
    Object.send :remove_const, :ApplicationSerializer
  end

  def test_uses_given_parent
    Object.const_set(:ApplicationSerializer, Class.new)
    run_generator ['Account', '--parent=MySerializer']
    assert_file 'app/serializers/account_serializer.rb', /class AccountSerializer < MySerializer/
  ensure
    Object.send :remove_const, :ApplicationSerializer
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
active_model_serializers-0.9.13 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.12 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.11 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.9 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.8 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.7 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.6 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.5 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.4 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.3 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.2 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.1 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.0 test/integration/generators/serializer_generator_test.rb
active_model_serializers-0.9.0.alpha1 test/integration/generators/serializer_generator_test.rb