grape-rabl 0.1.0 → 0.2.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/grape-rabl.gemspec +22 -22
- data/lib/grape-rabl/formatter.rb +1 -1
- data/lib/grape-rabl/version.rb +1 -1
- data/spec/grape_rabl_partials_spec.rb +29 -0
- data/spec/grape_rabl_spec.rb +61 -57
- data/spec/grape_rabl_xml_spec.rb +44 -0
- data/spec/spec_helper.rb +18 -17
- data/spec/views/_partial.rabl +1 -0
- data/spec/views/info.rabl +1 -0
- data/spec/views/project.rabl +10 -0
- metadata +9 -5
data/grape-rabl.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/grape-rabl/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Piotr Niełacny"]
|
6
|
-
gem.email = ["piotr.nielacny@gmail.com"]
|
7
|
-
gem.description = %q{Use rabl in grape}
|
8
|
-
gem.summary = %q{Use rabl in grape}
|
9
|
-
gem.homepage = "https://github.com/LTe/grape-rabl"
|
10
|
-
|
11
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
-
gem.files = `git ls-files`.split("\n")
|
13
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
-
gem.name = "grape-rabl"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = Grape::Rabl::VERSION
|
17
|
-
|
18
|
-
gem.add_dependency "grape", "~> 0.
|
19
|
-
gem.add_dependency "rabl"
|
20
|
-
gem.add_dependency "tilt"
|
21
|
-
gem.add_dependency "i18n"
|
22
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/grape-rabl/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Piotr Niełacny"]
|
6
|
+
gem.email = ["piotr.nielacny@gmail.com"]
|
7
|
+
gem.description = %q{Use rabl in grape}
|
8
|
+
gem.summary = %q{Use rabl in grape}
|
9
|
+
gem.homepage = "https://github.com/LTe/grape-rabl"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "grape-rabl"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Grape::Rabl::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "grape", "~> 0.3"
|
19
|
+
gem.add_dependency "rabl"
|
20
|
+
gem.add_dependency "tilt"
|
21
|
+
gem.add_dependency "i18n"
|
22
|
+
end
|
data/lib/grape-rabl/formatter.rb
CHANGED
data/lib/grape-rabl/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Grape::Rabl partials" do
|
4
|
+
subject do
|
5
|
+
Class.new(Grape::API)
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
subject.format :json
|
10
|
+
subject.formatter :json, Grape::Formatter::Rabl
|
11
|
+
subject.before { env["api.tilt.root"] = "#{File.dirname(__FILE__)}/views" }
|
12
|
+
end
|
13
|
+
|
14
|
+
def app
|
15
|
+
subject
|
16
|
+
end
|
17
|
+
|
18
|
+
it "proper render partials" do
|
19
|
+
subject.get("/home", :rabl => "project") do
|
20
|
+
@author = OpenStruct.new(:author => "LTe")
|
21
|
+
@type = OpenStruct.new(:type => "paper")
|
22
|
+
@project = OpenStruct.new(:name => "First", :type => @type, :author => @author)
|
23
|
+
end
|
24
|
+
|
25
|
+
get("/home")
|
26
|
+
last_response.body.should ==
|
27
|
+
"{\"project\":{\"name\":\"First\",\"info\":{\"type\":\"paper\"},\"author\":{\"author\":\"LTe\"}}}"
|
28
|
+
end
|
29
|
+
end
|
data/spec/grape_rabl_spec.rb
CHANGED
@@ -1,57 +1,61 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Grape::Rabl do
|
4
|
-
subject do
|
5
|
-
Class.new(Grape::API)
|
6
|
-
end
|
7
|
-
|
8
|
-
before do
|
9
|
-
subject.format :json
|
10
|
-
subject.formatter :json, Grape::Formatter::Rabl
|
11
|
-
end
|
12
|
-
|
13
|
-
def app
|
14
|
-
subject
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should work without rabl template' do
|
18
|
-
subject.get("/home") {"Hello World"}
|
19
|
-
get "/home"
|
20
|
-
last_response.body.should == "Hello World"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should raise error about root directory" do
|
24
|
-
subject.get("/home", :rabl => true){}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Grape::Rabl do
|
4
|
+
subject do
|
5
|
+
Class.new(Grape::API)
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
subject.format :json
|
10
|
+
subject.formatter :json, Grape::Formatter::Rabl
|
11
|
+
end
|
12
|
+
|
13
|
+
def app
|
14
|
+
subject
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should work without rabl template' do
|
18
|
+
subject.get("/home") {"Hello World"}
|
19
|
+
get "/home"
|
20
|
+
last_response.body.should == "Hello World"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise error about root directory" do
|
24
|
+
subject.get("/home", :rabl => true){}
|
25
|
+
get "/home"
|
26
|
+
last_response.status.should == 500
|
27
|
+
last_response.body.should include "Use Rack::Config to set 'api.tilt.root' in config.ru"
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
context "titl root is setup" do
|
32
|
+
before do
|
33
|
+
subject.before { env["api.tilt.root"] = "#{File.dirname(__FILE__)}/views" }
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should respond with proper content-type" do
|
37
|
+
subject.get("/home", :rabl => "user"){}
|
38
|
+
get("/home")
|
39
|
+
last_response.headers["Content-Type"].should == "application/json"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not raise error about root directory" do
|
43
|
+
subject.get("/home", :rabl => true){}
|
44
|
+
get "/home"
|
45
|
+
last_response.status.should == 500
|
46
|
+
last_response.body.should_not include "Use Rack::Config to set 'api.tilt.root' in config.ru"
|
47
|
+
end
|
48
|
+
|
49
|
+
["user", "user.rabl"].each do |rabl_option|
|
50
|
+
it "should render rabl template (#{rabl_option})" do
|
51
|
+
subject.get("/home", :rabl => rabl_option) do
|
52
|
+
@user = OpenStruct.new(:name => "LTe", :email => "email@example.com")
|
53
|
+
@project = OpenStruct.new(:name => "First")
|
54
|
+
end
|
55
|
+
|
56
|
+
get "/home"
|
57
|
+
last_response.body.should == '{"user":{"name":"LTe","email":"email@example.com","project":{"name":"First"}}}'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Grape::Rabl do
|
4
|
+
subject do
|
5
|
+
Class.new(Grape::API)
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
subject.format :xml
|
10
|
+
subject.formatter :xml, Grape::Formatter::Rabl
|
11
|
+
end
|
12
|
+
|
13
|
+
def app
|
14
|
+
subject
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with xml format" do
|
18
|
+
before do
|
19
|
+
subject.before {
|
20
|
+
env["api.tilt.root"] = "#{File.dirname(__FILE__)}/views"
|
21
|
+
env["api.format"] = :xml
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should respond with proper content-type" do
|
26
|
+
subject.get("/home", :rabl => "user"){}
|
27
|
+
get("/home")
|
28
|
+
last_response.headers["Content-Type"].should == "application/xml"
|
29
|
+
end
|
30
|
+
|
31
|
+
["user", "user.rabl"].each do |rabl_option|
|
32
|
+
it "should render rabl template (#{rabl_option})" do
|
33
|
+
subject.get("/home", :rabl => rabl_option) do
|
34
|
+
@user = OpenStruct.new(:name => "LTe", :email => "email@example.com")
|
35
|
+
@project = OpenStruct.new(:name => "First")
|
36
|
+
end
|
37
|
+
|
38
|
+
get "/home"
|
39
|
+
|
40
|
+
last_response.body.should == %Q{<?xml version="1.0" encoding="UTF-8"?>\n<user>\n <name>LTe</name>\n <email>email@example.com</email>\n <project>\n <name>First</name>\n </project>\n</user>\n}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
|
4
|
-
require 'bundler'
|
5
|
-
Bundler.setup :default, :test
|
6
|
-
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
Bundler.setup :default, :test
|
6
|
+
|
7
|
+
require 'active_support/core_ext/hash/conversions'
|
8
|
+
require 'grape/rabl'
|
9
|
+
require 'rspec'
|
10
|
+
require 'rack/test'
|
11
|
+
require 'ostruct'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include Rack::Test::Methods
|
15
|
+
end
|
16
|
+
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
18
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
attributes :type
|
@@ -0,0 +1 @@
|
|
1
|
+
attributes :author
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-rabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grape
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: '0.3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: '0.3'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rabl
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,8 +95,13 @@ files:
|
|
95
95
|
- lib/grape-rabl/tilt.rb
|
96
96
|
- lib/grape-rabl/version.rb
|
97
97
|
- lib/grape/rabl.rb
|
98
|
+
- spec/grape_rabl_partials_spec.rb
|
98
99
|
- spec/grape_rabl_spec.rb
|
100
|
+
- spec/grape_rabl_xml_spec.rb
|
99
101
|
- spec/spec_helper.rb
|
102
|
+
- spec/views/_partial.rabl
|
103
|
+
- spec/views/info.rabl
|
104
|
+
- spec/views/project.rabl
|
100
105
|
- spec/views/user.rabl
|
101
106
|
homepage: https://github.com/LTe/grape-rabl
|
102
107
|
licenses: []
|
@@ -123,4 +128,3 @@ signing_key:
|
|
123
128
|
specification_version: 3
|
124
129
|
summary: Use rabl in grape
|
125
130
|
test_files: []
|
126
|
-
has_rdoc:
|