Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
111 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
RSpec.describe "Project initializers", type: :cli do | ||
it "mounts Rack middleware" do | ||
with_project("project_initializers", gems: ['i18n']) do | ||
write "config/locales/en.yml", <<-EOF | ||
en: | ||
greeting: "Welcome stranger" | ||
EOF | ||
|
||
write "config/initializers/i18n.rb", <<-EOF | ||
require 'i18n' | ||
I18n.load_path = Dir['config/locales/*.yml'] | ||
I18n.backend.load_translations | ||
EOF | ||
|
||
generate "action web home#index --url=/" | ||
rewrite "apps/web/views/home/index.rb", <<-EOF | ||
module Web::Views::Home | ||
class Index | ||
include Web::View | ||
def greeting | ||
I18n.t(:greeting) | ||
end | ||
end | ||
end | ||
EOF | ||
|
||
rewrite "apps/web/templates/home/index.html.erb", <<-EOF | ||
<h1><%= greeting%></h1> | ||
EOF | ||
server do | ||
get '/' | ||
|
||
expect(last_response.body).to include("Welcome stranger") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
RSpec.describe "Components: finalizers", type: :cli do | ||
it "finalizes project" do | ||
with_project do | ||
require Pathname.new(Dir.pwd).join("config", "environment") | ||
Hanami::Components.resolve('finalizers') | ||
|
||
expect(Hanami::Components['finalizers']).to be(true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
RSpec.describe "Components: finalizers", type: :cli do | ||
it "ensures to load components once" do | ||
with_project do | ||
write "config/initializers/counter.rb", <<-EOF | ||
class Counter | ||
@counter = 0 | ||
def self.counter | ||
@counter | ||
end | ||
def self.increment! | ||
@counter += 1 | ||
end | ||
end | ||
Counter.increment! | ||
EOF | ||
|
||
require Pathname.new(Dir.pwd).join("config", "environment") | ||
Hanami::Components.resolve('finalizers') | ||
|
||
counter = Counter.counter | ||
|
||
# Simulate accidental double trigger | ||
Hanami::Components.resolve('finalizers') | ||
|
||
# counter shouldn't have been changed | ||
expect(Counter.counter).to eq(counter) | ||
end | ||
end | ||
end |