Sha256: 4200377f60aeee211269e961717db07fba692c0356741a41561ef50f973bbb5a

Contents?: true

Size: 978 Bytes

Versions: 10

Compression:

Stored size: 978 Bytes

Contents

require 'rails/generators/test_case'
require 'generators/rails/jbuilder_generator'

class JbuilderGeneratorTest < Rails::Generators::TestCase
  tests Rails::Generators::JbuilderGenerator
  arguments %w(Post title body:text password:digest)
  destination File.expand_path('../tmp', __FILE__)
  setup :prepare_destination

  test 'views are generated' do
    run_generator

    %w(index show).each do |view|
      assert_file "app/views/posts/#{view}.json.jbuilder"
    end
  end

  test 'index content' do
    run_generator

    assert_file 'app/views/posts/index.json.jbuilder' do |content|
      assert_match /json\.array!\(@posts\) do \|post\|/, content
      assert_match /json\.extract! post, :title, :body/, content
      assert_match /json\.url post_url\(post, format: :json\)/, content
    end

    assert_file 'app/views/posts/show.json.jbuilder' do |content|
      assert_match /json\.extract! @post, :title, :body, :created_at, :updated_at/, content
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
jbuilder-2.0.0.beta test/jbuilder_generator_test.rb
jbuilder-1.5.2 test/jbuilder_generator_test.rb
jbuilder-1.5.1 test/jbuilder_generator_test.rb
jbuilder-1.5.0 test/jbuilder_generator_test.rb
jbuilder-1.4.2 test/jbuilder_generator_test.rb
jbuilder-1.4.1 test/jbuilder_generator_test.rb
jbuilder-1.4.0 test/jbuilder_generator_test.rb
jbuilder-1.3.0 test/jbuilder_generator_test.rb
jbuilder-1.2.1 test/jbuilder_generator_test.rb
jbuilder-1.2.0 test/jbuilder_generator_test.rb