thumblemonks-chicago 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY.txt +0 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +5 -0
- data/Rakefile +24 -0
- data/chicago.gemspec +35 -0
- data/lib/chicago/application.rb +35 -0
- data/lib/chicago/helpers.rb +24 -0
- data/lib/chicago/responders.rb +15 -0
- data/lib/chicago/shoulda/sinatra.rb +69 -0
- data/lib/chicago/shoulda.rb +1 -0
- data/lib/chicago.rb +3 -0
- data/test/application_test.rb +33 -0
- data/test/responders_test.rb +14 -0
- data/test/test_helper.rb +33 -0
- metadata +70 -0
data/HISTORY.txt
ADDED
File without changes
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Justin Knowlden, Gabriel Gironda, Dan Hodos, Thumble Monks
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
desc 'Default task: run all tests'
|
6
|
+
task :default => [:test]
|
7
|
+
|
8
|
+
task(:set_test_env) { ENV['SINATRA_ENV'] ||= 'test' }
|
9
|
+
|
10
|
+
task :environment do
|
11
|
+
# Nothing yet
|
12
|
+
end
|
13
|
+
|
14
|
+
task :test => [:set_test_env, :environment]
|
15
|
+
desc 'Run all tests'
|
16
|
+
Rake::TestTask.new do |t|
|
17
|
+
t.test_files = FileList['test/*_test.rb']
|
18
|
+
t.verbose = true
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Open an irb session preloaded with this library"
|
22
|
+
task :console do
|
23
|
+
exec "irb -rubygems"
|
24
|
+
end
|
data/chicago.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "chicago"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.date = "2008-12-05"
|
5
|
+
s.summary = "Sinatra runtime and testing extensions used commonly by Thumblemonks"
|
6
|
+
s.email = %w[gus@gusg.us gabriel.gironda@gmail.com]
|
7
|
+
s.homepage = "http://github.com/thumblemonks/chicago/tree/master"
|
8
|
+
s.description = "Sinatra runtime and testing extensions used commonly by Thumblemonks. For example, :json_response, which turns an object into JSON and sets the content-type appropriately."
|
9
|
+
s.authors = %w[Justin\ Knowlden Gabriel\ Gironda]
|
10
|
+
|
11
|
+
s.has_rdoc = false
|
12
|
+
s.rdoc_options = ["--main", "README.markdown"]
|
13
|
+
s.extra_rdoc_files = ["HISTORY.txt", "README.markdown"]
|
14
|
+
|
15
|
+
# run git ls-files to get an updated list
|
16
|
+
s.files = %w[
|
17
|
+
HISTORY.txt
|
18
|
+
MIT-LICENSE
|
19
|
+
README.markdown
|
20
|
+
Rakefile
|
21
|
+
chicago.gemspec
|
22
|
+
lib/chicago.rb
|
23
|
+
lib/chicago/application.rb
|
24
|
+
lib/chicago/helpers.rb
|
25
|
+
lib/chicago/responders.rb
|
26
|
+
lib/chicago/shoulda.rb
|
27
|
+
lib/chicago/shoulda/sinatra.rb
|
28
|
+
]
|
29
|
+
|
30
|
+
s.test_files = %w[
|
31
|
+
test/application_test.rb
|
32
|
+
test/responders_test.rb
|
33
|
+
test/test_helper.rb
|
34
|
+
]
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Thumblemonks
|
2
|
+
module Sinatra
|
3
|
+
module Application
|
4
|
+
|
5
|
+
# Assumes all CSS is SASS and is referenced as being in a directory named stylesheets
|
6
|
+
def catch_all_css(path='/stylesheets')
|
7
|
+
get("#{path}/*.css") {sass params["splat"].first.to_sym}
|
8
|
+
end
|
9
|
+
|
10
|
+
# When you don't want anything special, but to load a named view
|
11
|
+
def get_obvious(name)
|
12
|
+
get "/#{name}" do
|
13
|
+
title = name.to_s
|
14
|
+
haml name.to_sym
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end # Application
|
19
|
+
|
20
|
+
module Object
|
21
|
+
def self.forward_sinatra_method(*methods)
|
22
|
+
Array(methods).each do |method|
|
23
|
+
module_eval <<-EOS
|
24
|
+
def #{method}(*args, &b) ::Sinatra.application.#{method}(*args, &b); end
|
25
|
+
EOS
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
forward_sinatra_method :catch_all_css, :get_obvious
|
30
|
+
end # Object
|
31
|
+
end # Sinatra
|
32
|
+
end # Thumblemonks
|
33
|
+
|
34
|
+
Sinatra::Application.instance_eval { include Thumblemonks::Sinatra::Application }
|
35
|
+
Object.instance_eval { include Thumblemonks::Sinatra::Object }
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Thumblemonks
|
2
|
+
module Sinatra
|
3
|
+
module Helpers
|
4
|
+
def anchor(name, url, options={})
|
5
|
+
defaults = {:href => url}
|
6
|
+
options_str = hash_to_attributes(defaults.merge(options))
|
7
|
+
%Q[<a #{options_str}>#{name}</a>]
|
8
|
+
end
|
9
|
+
|
10
|
+
def stylesheet_include(name, options={})
|
11
|
+
defaults = {:href => "/stylesheets/#{name}.css", :media => "screen",
|
12
|
+
:rel => "stylesheet", :type => "text/css"}
|
13
|
+
options_str = hash_to_attributes(defaults.merge(options))
|
14
|
+
%Q[<link #{options_str}/>]
|
15
|
+
end
|
16
|
+
private
|
17
|
+
def hash_to_attributes(options)
|
18
|
+
options.map {|k,v| "#{k}=\"#{v}\""}.join(' ')
|
19
|
+
end
|
20
|
+
end # Helpers
|
21
|
+
end # Sinatra
|
22
|
+
end # Thumblemonks
|
23
|
+
|
24
|
+
Sinatra::EventContext.instance_eval { include Thumblemonks::Sinatra::Helpers }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Thumblemonks
|
2
|
+
module Sinatra
|
3
|
+
module Responders
|
4
|
+
|
5
|
+
# Returns a JSON response for an object
|
6
|
+
def json_response(object)
|
7
|
+
content_type 'application/json'
|
8
|
+
object.to_json
|
9
|
+
end
|
10
|
+
|
11
|
+
end # Responders
|
12
|
+
end # Sinatra
|
13
|
+
end # Thumblemonks
|
14
|
+
|
15
|
+
Sinatra::EventContext.instance_eval { include Thumblemonks::Sinatra::Responders }
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Thumblemonks
|
4
|
+
module Shoulda
|
5
|
+
module Sinatra
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
klass.extend(Macros)
|
9
|
+
klass.send(:include, Helpers)
|
10
|
+
end
|
11
|
+
|
12
|
+
module Macros
|
13
|
+
def should_have_response_status(expected)
|
14
|
+
should("have response status") { assert_response expected }
|
15
|
+
end
|
16
|
+
|
17
|
+
def should_have_response_body(expected)
|
18
|
+
should("have response body") { assert_response_body expected }
|
19
|
+
end
|
20
|
+
|
21
|
+
def should_have_content_type(expected)
|
22
|
+
should("have content_type") { assert_content_type expected }
|
23
|
+
end
|
24
|
+
|
25
|
+
def should_have_json_response(json={}, &block)
|
26
|
+
should_have_content_type 'application/json'
|
27
|
+
should "have JSON response in the body" do
|
28
|
+
json = self.instance_eval(&block) if block_given?
|
29
|
+
json = json.to_json unless json.instance_of?(String) || json.instance_of?(Regexp)
|
30
|
+
assert_response_body json
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end # Macros
|
34
|
+
|
35
|
+
module Helpers
|
36
|
+
def deny(check, message=nil)
|
37
|
+
assert(!check, message)
|
38
|
+
end
|
39
|
+
|
40
|
+
def assert_response(status)
|
41
|
+
assert_equal status, @response.status
|
42
|
+
end
|
43
|
+
|
44
|
+
def assert_response_body(body)
|
45
|
+
assert_match body, @response.body
|
46
|
+
end
|
47
|
+
|
48
|
+
def assert_content_type(expected)
|
49
|
+
assert_equal expected, @response.headers['Content-type']
|
50
|
+
end
|
51
|
+
|
52
|
+
# Usage:
|
53
|
+
#
|
54
|
+
# assert_redirected_to '/foo/bar'
|
55
|
+
# or
|
56
|
+
# assert_redirected_to %r[foo.bar]
|
57
|
+
def assert_redirected_to(expected_path)
|
58
|
+
yield if block_given?
|
59
|
+
assert_response 302
|
60
|
+
action = expected_path.kind_of?(Regexp) ? 'match' : 'equal'
|
61
|
+
send("assert_#{action}", expected_path, @response.headers["Location"])
|
62
|
+
end
|
63
|
+
end # Helpers
|
64
|
+
|
65
|
+
end # Sinatra
|
66
|
+
end # Shoulda
|
67
|
+
end # Thumblemonks
|
68
|
+
|
69
|
+
Test::Unit::TestCase.instance_eval { include Thumblemonks::Shoulda::Sinatra }
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'chicago/shoulda/sinatra'
|
data/lib/chicago.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class ApplicationTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "catching all css" do
|
6
|
+
context "with default path" do
|
7
|
+
setup do
|
8
|
+
get_it '/stylesheets/foo.css'
|
9
|
+
end
|
10
|
+
|
11
|
+
should_have_response_status 200
|
12
|
+
should_have_response_body %r[.bar \{\s+display: none; \}\s]
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with specified path" do
|
16
|
+
setup do
|
17
|
+
get_it '/css/goo.css'
|
18
|
+
end
|
19
|
+
|
20
|
+
should_have_response_status 200
|
21
|
+
should_have_response_body %r[.car \{\s+display: some; \}\s]
|
22
|
+
end
|
23
|
+
end # catching all css
|
24
|
+
|
25
|
+
context "getting obvious views" do
|
26
|
+
setup do
|
27
|
+
get_it '/baz'
|
28
|
+
end
|
29
|
+
|
30
|
+
should_have_response_body "Whatever man. That's just like, your opinion."
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class RespondersTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "json response" do
|
6
|
+
setup do
|
7
|
+
get_it "/json_bait"
|
8
|
+
end
|
9
|
+
|
10
|
+
should_have_response_status 201
|
11
|
+
should_have_json_response({:foo => :bar})
|
12
|
+
end # json response
|
13
|
+
|
14
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
require 'sinatra/test/unit'
|
5
|
+
require 'shoulda'
|
6
|
+
|
7
|
+
require 'chicago'
|
8
|
+
require 'chicago/shoulda'
|
9
|
+
|
10
|
+
# JSON Stuff
|
11
|
+
get "/json_bait" do
|
12
|
+
status(201)
|
13
|
+
json_response({:foo => "bar"})
|
14
|
+
end
|
15
|
+
|
16
|
+
# CSS Stuff
|
17
|
+
|
18
|
+
catch_all_css
|
19
|
+
template :foo do
|
20
|
+
".bar\n :display none"
|
21
|
+
end
|
22
|
+
|
23
|
+
catch_all_css('/css')
|
24
|
+
template :goo do
|
25
|
+
".car\n :display some"
|
26
|
+
end
|
27
|
+
|
28
|
+
# Getting obvious
|
29
|
+
|
30
|
+
get_obvious 'baz'
|
31
|
+
template :baz do
|
32
|
+
"Whatever man. That's just like, your opinion."
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thumblemonks-chicago
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Knowlden
|
8
|
+
- Gabriel Gironda
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-12-05 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Sinatra runtime and testing extensions used commonly by Thumblemonks. For example, :json_response, which turns an object into JSON and sets the content-type appropriately.
|
18
|
+
email:
|
19
|
+
- gus@gusg.us
|
20
|
+
- gabriel.gironda@gmail.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files:
|
26
|
+
- HISTORY.txt
|
27
|
+
- README.markdown
|
28
|
+
files:
|
29
|
+
- HISTORY.txt
|
30
|
+
- MIT-LICENSE
|
31
|
+
- README.markdown
|
32
|
+
- Rakefile
|
33
|
+
- chicago.gemspec
|
34
|
+
- lib/chicago.rb
|
35
|
+
- lib/chicago/application.rb
|
36
|
+
- lib/chicago/helpers.rb
|
37
|
+
- lib/chicago/responders.rb
|
38
|
+
- lib/chicago/shoulda.rb
|
39
|
+
- lib/chicago/shoulda/sinatra.rb
|
40
|
+
has_rdoc: false
|
41
|
+
homepage: http://github.com/thumblemonks/chicago/tree/master
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --main
|
45
|
+
- README.markdown
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.2.0
|
64
|
+
signing_key:
|
65
|
+
specification_version: 2
|
66
|
+
summary: Sinatra runtime and testing extensions used commonly by Thumblemonks
|
67
|
+
test_files:
|
68
|
+
- test/application_test.rb
|
69
|
+
- test/responders_test.rb
|
70
|
+
- test/test_helper.rb
|