diff --git a/cuba-sugar.gemspec b/cuba-sugar.gemspec index af63e15..56481fb 100644 --- a/cuba-sugar.gemspec +++ b/cuba-sugar.gemspec @@ -10,6 +10,7 @@ Gem::Specification.new do |s| s.test_files = `git ls-files test`.split("\n") s.add_dependency("cuba") + s.add_dependency("cuba-contrib") s.add_dependency("json") s.add_dependency("rack_csrf") diff --git a/lib/cuba/sugar.rb b/lib/cuba/sugar.rb index c14fec1..bad6c0d 100644 --- a/lib/cuba/sugar.rb +++ b/lib/cuba/sugar.rb @@ -1,7 +1,7 @@ -require 'json' +require "cuba/contrib" require "rack/csrf" -class Cuba +module Cuba::Sugar # Sugar to access root of a page # @@ -56,6 +56,7 @@ def as(http_code = 200, extra_headers = {}) # end # end def as_json(http_code = 200, extra_headers = {}) + require 'json' extra_headers["Content-Type"] ||= "application/json" as(http_code, extra_headers) do (yield).to_json if block_given? diff --git a/test/as.rb b/test/as.rb index c00a055..e12548f 100644 --- a/test/as.rb +++ b/test/as.rb @@ -1,6 +1,7 @@ require File.expand_path("helper", File.dirname(__FILE__)) test "set status and headers through helper" do + Cuba.plugin Cuba::Sugar Cuba.define do on "users" do as 201, {"Content-Location" => "http://somewhere.com/users/705"} do diff --git a/test/as_json.rb b/test/as_json.rb index 32db117..e56787a 100644 --- a/test/as_json.rb +++ b/test/as_json.rb @@ -3,6 +3,8 @@ test "set a block to return json" do rum_and_coke = { "rum" => "hot", "coke" => "sweet" } + + Cuba.plugin Cuba::Sugar Cuba.define do on "drinks" do as_json 201, {"Content-Location" => "http://somewhere.com/drinks/42"} do diff --git a/test/csrf.rb b/test/csrf.rb index 8b195bf..b7cff42 100644 --- a/test/csrf.rb +++ b/test/csrf.rb @@ -1,6 +1,7 @@ require File.expand_path("helper", File.dirname(__FILE__)) test "set status and headers through helper" do + Cuba.plugin Cuba::Sugar Cuba.define do on "users" do as do diff --git a/test/helpers.rb b/test/helpers.rb index a7d4001..a85cf02 100644 --- a/test/helpers.rb +++ b/test/helpers.rb @@ -1,6 +1,7 @@ require File.expand_path("helper", File.dirname(__FILE__)) test "set status and headers through helpers" do + Cuba.plugin Cuba::Sugar Cuba.define do helpers do def upperize(string) diff --git a/test/redirect.rb b/test/redirect.rb index ed0337a..e5307d8 100644 --- a/test/redirect.rb +++ b/test/redirect.rb @@ -1,6 +1,7 @@ require File.expand_path("helper", File.dirname(__FILE__)) test "redirect helper" do + Cuba.plugin Cuba::Sugar Cuba.define do on "old" do redirect "/new" diff --git a/test/subdomain.rb b/test/subdomain.rb index cfe560f..df50e65 100644 --- a/test/subdomain.rb +++ b/test/subdomain.rb @@ -1,6 +1,7 @@ require File.expand_path("helper", File.dirname(__FILE__)) test "eval only in a given subdomain" do + Cuba.plugin Cuba::Sugar Cuba.define do on subdomain("api"), root do as do