faceted 1.0.8 → 1.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/Gemfile +3 -1
- data/Gemfile.lock +70 -0
- data/VERSION +1 -1
- data/faceted.gemspec +9 -2
- data/lib/faceted/controller.rb +5 -5
- data/spec/controller_spec.rb +57 -0
- data/spec/spec_helper.rb +3 -0
- metadata +36 -3
data/Gemfile
CHANGED
@@ -3,13 +3,15 @@ source "http://rubygems.org"
|
|
3
3
|
# Example:
|
4
4
|
gem "activesupport", ">= 2.3.5"
|
5
5
|
gem "activemodel"
|
6
|
+
gem "rails"
|
6
7
|
|
7
8
|
# Add dependencies to develop your gem here.
|
8
9
|
# Include everything needed to run rake, tests, features, etc.
|
9
|
-
group :development do
|
10
|
+
group :development, :test do
|
10
11
|
gem "shoulda", ">= 0"
|
11
12
|
gem "rdoc", "~> 3.12"
|
12
13
|
gem "rspec"
|
14
|
+
gem "rspec-rails"
|
13
15
|
gem "bundler"
|
14
16
|
gem "jeweler", "~> 1.8.4"
|
15
17
|
gem "simplecov"
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,76 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
actionmailer (3.2.8)
|
5
|
+
actionpack (= 3.2.8)
|
6
|
+
mail (~> 2.4.4)
|
7
|
+
actionpack (3.2.8)
|
8
|
+
activemodel (= 3.2.8)
|
9
|
+
activesupport (= 3.2.8)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.4)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.2)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.3)
|
4
17
|
activemodel (3.2.8)
|
5
18
|
activesupport (= 3.2.8)
|
6
19
|
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.8)
|
21
|
+
activemodel (= 3.2.8)
|
22
|
+
activesupport (= 3.2.8)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.8)
|
26
|
+
activemodel (= 3.2.8)
|
27
|
+
activesupport (= 3.2.8)
|
7
28
|
activesupport (3.2.8)
|
8
29
|
i18n (~> 0.6)
|
9
30
|
multi_json (~> 1.0)
|
31
|
+
arel (3.0.2)
|
10
32
|
builder (3.0.3)
|
11
33
|
diff-lcs (1.1.3)
|
34
|
+
erubis (2.7.0)
|
12
35
|
git (1.2.5)
|
36
|
+
hike (1.2.1)
|
13
37
|
i18n (0.6.1)
|
14
38
|
jeweler (1.8.4)
|
15
39
|
bundler (~> 1.0)
|
16
40
|
git (>= 1.2.5)
|
17
41
|
rake
|
18
42
|
rdoc
|
43
|
+
journey (1.0.4)
|
19
44
|
json (1.7.5)
|
45
|
+
mail (2.4.4)
|
46
|
+
i18n (>= 0.4.0)
|
47
|
+
mime-types (~> 1.16)
|
48
|
+
treetop (~> 1.4.8)
|
49
|
+
mime-types (1.19)
|
20
50
|
multi_json (1.3.6)
|
51
|
+
polyglot (0.3.3)
|
52
|
+
rack (1.4.1)
|
53
|
+
rack-cache (1.2)
|
54
|
+
rack (>= 0.4)
|
55
|
+
rack-ssl (1.3.2)
|
56
|
+
rack
|
57
|
+
rack-test (0.6.2)
|
58
|
+
rack (>= 1.0)
|
59
|
+
rails (3.2.8)
|
60
|
+
actionmailer (= 3.2.8)
|
61
|
+
actionpack (= 3.2.8)
|
62
|
+
activerecord (= 3.2.8)
|
63
|
+
activeresource (= 3.2.8)
|
64
|
+
activesupport (= 3.2.8)
|
65
|
+
bundler (~> 1.0)
|
66
|
+
railties (= 3.2.8)
|
67
|
+
railties (3.2.8)
|
68
|
+
actionpack (= 3.2.8)
|
69
|
+
activesupport (= 3.2.8)
|
70
|
+
rack-ssl (~> 1.3.2)
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
rdoc (~> 3.4)
|
73
|
+
thor (>= 0.14.6, < 2.0)
|
21
74
|
rake (0.9.2.2)
|
22
75
|
rdoc (3.12)
|
23
76
|
json (~> 1.4)
|
@@ -29,6 +82,11 @@ GEM
|
|
29
82
|
rspec-expectations (2.11.2)
|
30
83
|
diff-lcs (~> 1.1.3)
|
31
84
|
rspec-mocks (2.11.2)
|
85
|
+
rspec-rails (2.11.4)
|
86
|
+
actionpack (>= 3.0)
|
87
|
+
activesupport (>= 3.0)
|
88
|
+
railties (>= 3.0)
|
89
|
+
rspec (~> 2.11.0)
|
32
90
|
shoulda (3.1.1)
|
33
91
|
shoulda-context (~> 1.0)
|
34
92
|
shoulda-matchers (~> 1.2)
|
@@ -39,6 +97,16 @@ GEM
|
|
39
97
|
multi_json (~> 1.0)
|
40
98
|
simplecov-html (~> 0.5.3)
|
41
99
|
simplecov-html (0.5.3)
|
100
|
+
sprockets (2.1.3)
|
101
|
+
hike (~> 1.2)
|
102
|
+
rack (~> 1.0)
|
103
|
+
tilt (~> 1.1, != 1.3.0)
|
104
|
+
thor (0.16.0)
|
105
|
+
tilt (1.3.3)
|
106
|
+
treetop (1.4.12)
|
107
|
+
polyglot
|
108
|
+
polyglot (>= 0.3.1)
|
109
|
+
tzinfo (0.3.35)
|
42
110
|
|
43
111
|
PLATFORMS
|
44
112
|
ruby
|
@@ -48,7 +116,9 @@ DEPENDENCIES
|
|
48
116
|
activesupport (>= 2.3.5)
|
49
117
|
bundler
|
50
118
|
jeweler (~> 1.8.4)
|
119
|
+
rails
|
51
120
|
rdoc (~> 3.12)
|
52
121
|
rspec
|
122
|
+
rspec-rails
|
53
123
|
shoulda
|
54
124
|
simplecov
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/faceted.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "faceted"
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Corey Ehmke", "Max Thom Stahl"]
|
12
|
-
s.date = "2012-12-
|
12
|
+
s.date = "2012-12-07"
|
13
13
|
s.description = "Faceted provides set of tools, patterns, and modules for use in API implementations."
|
14
14
|
s.email = "corey@trunkclub.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/faceted/model.rb",
|
34
34
|
"lib/faceted/presenter.rb",
|
35
35
|
"spec/collector_spec.rb",
|
36
|
+
"spec/controller_spec.rb",
|
36
37
|
"spec/presenter_spec.rb",
|
37
38
|
"spec/spec_helper.rb"
|
38
39
|
]
|
@@ -48,18 +49,22 @@ Gem::Specification.new do |s|
|
|
48
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
50
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
|
50
51
|
s.add_runtime_dependency(%q<activemodel>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<rails>, [">= 0"])
|
51
53
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
52
54
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
53
55
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<rspec-rails>, [">= 0"])
|
54
57
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
55
58
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
59
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
57
60
|
else
|
58
61
|
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
59
62
|
s.add_dependency(%q<activemodel>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
60
64
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
65
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
66
|
s.add_dependency(%q<rspec>, [">= 0"])
|
67
|
+
s.add_dependency(%q<rspec-rails>, [">= 0"])
|
63
68
|
s.add_dependency(%q<bundler>, [">= 0"])
|
64
69
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
65
70
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
@@ -67,9 +72,11 @@ Gem::Specification.new do |s|
|
|
67
72
|
else
|
68
73
|
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
69
74
|
s.add_dependency(%q<activemodel>, [">= 0"])
|
75
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
70
76
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
71
77
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
72
78
|
s.add_dependency(%q<rspec>, [">= 0"])
|
79
|
+
s.add_dependency(%q<rspec-rails>, [">= 0"])
|
73
80
|
s.add_dependency(%q<bundler>, [">= 0"])
|
74
81
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
75
82
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
data/lib/faceted/controller.rb
CHANGED
@@ -4,12 +4,12 @@ module Faceted
|
|
4
4
|
|
5
5
|
# For rendering a response with a single object, e.g.
|
6
6
|
# render_response(@address)
|
7
|
-
def render_response(obj)
|
7
|
+
def render_response(obj, code=nil)
|
8
8
|
render :json => {
|
9
9
|
success: obj.success,
|
10
10
|
response: obj.to_hash,
|
11
11
|
errors: obj.errors
|
12
|
-
}
|
12
|
+
}, :status => code || obj.success ? 200 : 400
|
13
13
|
end
|
14
14
|
|
15
15
|
# For rendering a response with a multiple objects, e.g.
|
@@ -18,7 +18,7 @@ module Faceted
|
|
18
18
|
render :json => {
|
19
19
|
success: true,
|
20
20
|
response: {"#{key}".to_sym => array},
|
21
|
-
errors:
|
21
|
+
errors: nil
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
@@ -28,8 +28,8 @@ module Faceted
|
|
28
28
|
render :json => {
|
29
29
|
success: false,
|
30
30
|
response: nil,
|
31
|
-
errors: "
|
32
|
-
}, :status =>
|
31
|
+
errors: "#{exception.message}"
|
32
|
+
}, :status => 400
|
33
33
|
end
|
34
34
|
|
35
35
|
# In your base API controller:
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Birthplace # Mock AR model
|
4
|
+
attr_accessor :id, :city, :state
|
5
|
+
def initialize(params={}); params.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)}; end
|
6
|
+
def attributes; {:id => self.id, :city => self.city, :state => self.state}; end
|
7
|
+
def reload; self; end
|
8
|
+
end
|
9
|
+
|
10
|
+
module MyApi
|
11
|
+
|
12
|
+
class MyApi::Application < Rails::Application
|
13
|
+
end
|
14
|
+
|
15
|
+
class Birthplace
|
16
|
+
include Faceted::Presenter
|
17
|
+
presents :birthplace
|
18
|
+
field :city
|
19
|
+
field :state
|
20
|
+
end
|
21
|
+
|
22
|
+
class BirthplacesController < ActionController::Base
|
23
|
+
include Faceted::Controller
|
24
|
+
include Rails.application.routes.url_helpers
|
25
|
+
def show
|
26
|
+
@birthplace = MyApi::Birthplace.first
|
27
|
+
render_response @birthplace
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe MyApi::BirthplacesController, :type => :controller do
|
35
|
+
|
36
|
+
before do
|
37
|
+
MyApi::Birthplace.stub(:first) { MyApi::Birthplace.new }
|
38
|
+
MyApi::Application.routes.draw do
|
39
|
+
namespace :my_api do
|
40
|
+
resources :birthplaces
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'renders with a 200 when the operation is successful' do
|
46
|
+
MyApi::Birthplace.any_instance.stub(:success) { true }
|
47
|
+
get :show, :id => 1
|
48
|
+
response.code.should == "200"
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'renders with a 400 when the operation is unsuccessful' do
|
52
|
+
MyApi::Birthplace.any_instance.stub(:success) { false }
|
53
|
+
get :show, :id => 1
|
54
|
+
response.code.should == "400"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faceted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -44,6 +44,22 @@ dependencies:
|
|
44
44
|
- - ! '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rails
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
47
63
|
- !ruby/object:Gem::Dependency
|
48
64
|
name: shoulda
|
49
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,6 +108,22 @@ dependencies:
|
|
92
108
|
- - ! '>='
|
93
109
|
- !ruby/object:Gem::Version
|
94
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
95
127
|
- !ruby/object:Gem::Dependency
|
96
128
|
name: bundler
|
97
129
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +196,7 @@ files:
|
|
164
196
|
- lib/faceted/model.rb
|
165
197
|
- lib/faceted/presenter.rb
|
166
198
|
- spec/collector_spec.rb
|
199
|
+
- spec/controller_spec.rb
|
167
200
|
- spec/presenter_spec.rb
|
168
201
|
- spec/spec_helper.rb
|
169
202
|
homepage: http://github.com/trunkclub/faceted
|
@@ -181,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
214
|
version: '0'
|
182
215
|
segments:
|
183
216
|
- 0
|
184
|
-
hash: -
|
217
|
+
hash: -4341699658491499181
|
185
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
219
|
none: false
|
187
220
|
requirements:
|