Skip to content

Commit 532ca8a

Browse files
author
Alfredo Gallegos
committed
adds failing tests
1 parent 100bca4 commit 532ca8a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require 'test_helper'
2+
require 'rails/generators/test_case'
3+
require 'generators/rails/jbuilder_generator'
4+
5+
class JbuilderGeneratorWithNamespaceTest < Rails::Generators::TestCase
6+
tests Rails::Generators::JbuilderGenerator
7+
arguments %w(api/foo bar:integer baz:string)
8+
destination File.expand_path('../tmp', __FILE__)
9+
setup :prepare_destination
10+
11+
test 'all views are generated' do
12+
run_generator
13+
14+
%w(index show).each do |view|
15+
assert_file "app/views/api/foos/#{view}.json.jbuilder"
16+
end
17+
assert_file "app/views/api/foos/_api_foo.json.jbuilder"
18+
end
19+
20+
test 'the files are correctly structured to work' do
21+
run_generator
22+
23+
assert_file 'app/views/api/foos/index.json.jbuilder' do |content|
24+
assert_match %r{json.array! @api_foos, partial: 'api/foos/api_foo', as: :api_foo}, content
25+
end
26+
27+
assert_file 'app/views/api/foos/show.json.jbuilder' do |content|
28+
assert_match %r{json.partial! \"api/foos/api_foo\", api_foo: @api_foo}, content
29+
end
30+
31+
assert_file 'app/views/api/foos/_api_foo.json.jbuilder' do |content|
32+
assert_match %r{json\.extract! api_foo, :id, :bar, :baz, :created_at, :updated_at}, content
33+
assert_match %r{json\.url api_foo_url\(api_foo, format: :json\)}, content
34+
end
35+
36+
37+
end
38+
end

0 commit comments

Comments
 (0)