Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing the Rails Controller and refactor into middleware #251

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add spec for idea to insert assets with rack
Patrick Mulder committed Jul 11, 2013

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 08b5f6f3b76624a4838c9a0499323c8e76f5ceef
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -19,5 +19,6 @@ end

group :test do
gem 'rspec', '~>2'
gem 'nokogiri'
gem 'rack-test'
end
4 changes: 2 additions & 2 deletions lib/jammit/controller.rb
Original file line number Diff line number Diff line change
@@ -69,8 +69,8 @@ def package
template_ext = Jammit.template_extension.to_sym
case @extension
when :js
# (@contents = Jammit.packager.pack_javascripts(@package))
'foo_case1.js'
puts @package.inspect
(@contents = Jammit.packager.pack_javascripts(@package))
when template_ext
# (@contents = Jammit.packager.pack_templates(@package))
'foo_case2.js'
33 changes: 27 additions & 6 deletions spec/jammit/controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
# encoding: utf-8
require 'spec_helper'
require 'nokogiri'

describe Jammit::Controller do

def basic_app
lambda { |e| [200, {'Content-Type' => 'text/plain'}, '<h1>FunkyBoss</h1>'] }
def test_html
'<html>
<head>
<meta charset="utf-8">
<title>test page</title>
</head>
<body><h1>FunkyBoss</h1></body>
</html>'
end

def index_app
lambda { |e| [200, {'Content-Type' => 'text/plain'}, test_html] }
end

it "inserts Jammit into the rack env" do
env = env_with_params
setup_rack(basic_app).call(env)
setup_rack(index_app).call(env)
env["jammit"].should be_an_instance_of(Jammit::Controller)
end

describe "serves assets" do
it "responds with 200" do
describe "serving assets" do
it "responds with" do
env = env_with_params("/assets/app.js", {})
result = setup_rack(basic_app).call(env)
result = setup_rack(index_app).call(env)
result.last.should == ['var Foo = 1']
end
end

describe "serving non-assets" do
it "includes script tag" do
env = env_with_params("/index.html", {})
result = setup_rack(index_app).call(env)
test_html_head(result.last, 'title', 'test page')
test_html_head_attributes(result.last, 'meta', 'charset=utf-8')
end
end

end
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -22,3 +22,14 @@
# end
# end
end

def test_html_head(body, tag, keys)
html = Nokogiri::HTML(body)
html.css("head #{tag}").text.should == keys
end

def test_html_head_attributes(body, tag, keys)
html = Nokogiri::HTML(body)
attributes = html.css("head #{tag}").map(&:attributes)
# .... should
end