Skip to content

Commit

Permalink
Move the CoffeeShop app to test/fixtures/coffee_shop
Browse files Browse the repository at this point in the history
This helps get rid of the bootstrap method
  • Loading branch information
Trung Lê committed Mar 9, 2016
1 parent a6f75ff commit 89045b9
Show file tree
Hide file tree
Showing 27 changed files with 370 additions and 77 deletions.
1 change: 1 addition & 0 deletions lib/hanami/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def namespace
end

def load_initializers!
# require 'byebug'; byebug
Dir["#{configuration.root}/config/initializers/**/*.rb"].each do |file|
require file
end
Expand Down
5 changes: 2 additions & 3 deletions test/application_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'test_helper'

CoffeeShop::Application.bootstrap
require_relative './fixtures/coffee_shop/config/environment'

describe Hanami::Application do
before do
Expand All @@ -19,7 +18,7 @@
configuration = CoffeeShop::Application.configuration

configuration.must_be_kind_of Hanami::Configuration
configuration.root.must_equal Pathname.new(__dir__).join('../tmp/coffee_shop')
configuration.root.must_equal Pathname.new(__dir__).join('../test/fixtures/coffee_shop')
end
end

Expand Down
71 changes: 0 additions & 71 deletions test/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,6 @@ def suffix(value = nil)
end
end

class Order
include Hanami::Entity

attributes :size, :coffee, :qty
end

class OrderRepository
include Hanami::Repository
end

module CoffeeShop
class Application < Hanami::Application
def self.bootstrap
Pathname.new(File.dirname(__FILE__)).join('../tmp/coffee_shop/app/templates').mkpath
Pathname.new(File.dirname(__FILE__)).join('../tmp/coffee_shop/app/templates/mailers').mkpath
Pathname.new(File.dirname(__FILE__)).join('../tmp/coffee_shop/config/initializers/').mkpath

File.open("#{File.dirname(__FILE__)}/../tmp/coffee_shop/config/initializers/init1.rb", 'w') { |f| f.write('class CollaborationInitializer1; end;') }
File.open("#{File.dirname(__FILE__)}/../tmp/coffee_shop/config/initializers/init2.rb", 'w') { |f| f.write('class CollaborationInitializer2; end;') }
end

configure do
root Pathname.new(File.dirname(__FILE__)).join('../tmp/coffee_shop')
layout nil

load_paths.clear
templates 'app/templates'

default_response_format :html

security.x_frame_options "DENY"
security.content_security_policy %{
form-action 'self';
referrer origin-when-cross-origin;
reflected-xss block;
frame-ancestors 'self';
base-uri 'self';
default-src 'none';
connect-src 'self';
img-src 'self';
style-src 'self';
font-src 'self';
object-src 'self';
plugin-types application/pdf;
child-src 'self';
frame-src 'self';
media-src 'self'
}

scheme 'https'
host 'hanami-coffeeshop.org'

routes do
get '/', to: ->{}, as: :root
end

adapter type: :memory, uri: 'memory://localhost'
mapping do
collection :orders do
entity Order

attribute :id, Integer
attribute :size, String
attribute :coffee, String
attribute :qty, Integer
end
end
end
end
end

module Reviews
class Application < Hanami::Application
configure do
Expand Down
Binary file added test/fixtures/coffee_shop/app/assets/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions test/fixtures/coffee_shop/app/assets/images/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
1 change: 1 addition & 0 deletions test/fixtures/coffee_shop/app/assets/javascripts/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
1 change: 1 addition & 0 deletions test/fixtures/coffee_shop/app/assets/stylesheets/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
1 change: 1 addition & 0 deletions test/fixtures/coffee_shop/app/controllers/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
10 changes: 10 additions & 0 deletions test/fixtures/coffee_shop/app/templates/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype HTML>
<html>
<head>
<title>CoffeeShop</title>
<%= favicon %>
</head>
<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions test/fixtures/coffee_shop/app/views/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
7 changes: 7 additions & 0 deletions test/fixtures/coffee_shop/app/views/application_layout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module CoffeeShop
module Views
class ApplicationLayout
include CoffeeShop::Layout
end
end
end
3 changes: 3 additions & 0 deletions test/fixtures/coffee_shop/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require './config/environment'

run CoffeeShop::Application.new

0 comments on commit 89045b9

Please sign in to comment.