Skip to content

Commit

Permalink
Add tests to the CRUD layout
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Dec 19, 2023
1 parent 5e8b4d2 commit de259a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
doctype html
html lang= I18n.locale
html lang=I18n.locale
head
meta charset="utf-8"
meta name="viewport" content="width=device-width, initial-scale=1.0"
Expand Down
6 changes: 1 addition & 5 deletions .template/spec/variants/web/app/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
end

it 'loads the javascript entry file in the layout' do
expect(file('app/views/layouts/application.html.erb')).to contain('<%= javascript_include_tag "application"')
expect(file('app/views/layouts/application.html.slim')).to contain('javascript_include_tag "application"')
end

it 'imports necessary modules' do
Expand Down Expand Up @@ -103,9 +103,5 @@
it 'includes the localization concern in the application controller' do
expect(file('app/controllers/application_controller.rb')).to contain('include Localization')
end

it 'modifies the html tag to attach the current locale' do
expect(file('app/views/layouts/application.html.erb')).to contain("<html lang='<%= I18n.locale %>'>")
end
end
end
18 changes: 13 additions & 5 deletions .template/variants/web/app/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
# Javascript
directory 'app/javascript'

if File.exist?('app/views/layouts/application.html.erb')
insert_into_file 'app/views/layouts/application.html.erb', before: %r{</head>} do
erb_layout_file = 'app/views/layouts/application.html.erb'
slim_layout_file = 'app/views/layouts/application.html.slim'
layout_file = nil

layout_file = erb_layout_file if File.exist?(erb_layout_file)
layout_file = slim_layout_file if File.exist?(slim_layout_file)

if layout_file
insert_into_file layout_file, before: %r{</head>} do
<<~ERB.indent(2)
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
ERB
end
else
@template_errors.add <<~ERROR
Cannot include javascript into `app/views/layouts/application.html.erb`
Cannot include javascript into `app/views/layouts/application.html.{erb|slim}`
Content: <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
ERROR
end
Expand All @@ -33,11 +40,12 @@
RUBY
end

if File.exist?('app/views/layouts/application.html.erb')
if erb_layout_file
gsub_file 'app/views/layouts/application.html.erb', /<html>/ do
"<html lang='<%= I18n.locale %>'>"
end
else
# The slim layout (CRUD addon) already has the lang attribute
elsif slim_layout_file.blank?
@template_errors.add <<~ERROR
Cannot insert the lang attribute into html tag into `app/views/layouts/application.html.erb`
Content: <html lang='<%= I18n.locale %>'>
Expand Down

0 comments on commit de259a3

Please sign in to comment.