wrest 0.0.9-java → 0.1.0-java
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/CHANGELOG +34 -0
- data/README.rdoc +16 -10
- data/Rakefile +362 -124
- data/VERSION.yml +2 -2
- data/examples/delicious.rb +17 -7
- data/examples/facebook.rb +101 -0
- data/examples/keep_alive.rb +37 -0
- data/examples/twitter.rb +3 -3
- data/examples/twitter_public_timeline.rb +11 -4
- data/examples/wow_realm_status.rb +8 -2
- data/{spec/functional/sample_rails_app/public/favicon.ico → init.rb} +0 -0
- data/lib/wrest/components/{attributes_container → container}/alias_accessors.rb +4 -4
- data/lib/wrest/components/{attributes_container → container}/typecaster.rb +1 -1
- data/lib/wrest/components/{attributes_container.rb → container.rb} +46 -16
- data/lib/wrest/components/mutators.rb +4 -4
- data/lib/wrest/components/translators/json.rb +2 -2
- data/lib/wrest/components/translators/xml.rb +3 -2
- data/lib/wrest/components/translators.rb +3 -3
- data/lib/wrest/components.rb +3 -3
- data/lib/wrest/core_ext/hash.rb +1 -1
- data/lib/wrest/core_ext/string.rb +1 -1
- data/lib/wrest/curl/delete.rb +23 -0
- data/lib/wrest/curl/get.rb +23 -0
- data/lib/wrest/curl/options.rb +16 -0
- data/lib/wrest/curl/post.rb +23 -0
- data/lib/wrest/curl/put.rb +23 -0
- data/lib/wrest/curl/request.rb +95 -0
- data/lib/wrest/curl/response.rb +63 -0
- data/lib/wrest/curl/session.rb +57 -0
- data/lib/wrest/curl.rb +49 -0
- data/lib/wrest/exceptions.rb +16 -1
- data/lib/wrest/http_shared/headers.rb +350 -0
- data/lib/wrest/http_shared/standard_headers.rb +21 -0
- data/lib/wrest/http_shared/standard_tokens.rb +18 -0
- data/lib/wrest/http_shared.rb +24 -0
- data/lib/wrest/native/connection_factory.rb +23 -0
- data/lib/wrest/{http → native}/delete.rb +1 -1
- data/lib/wrest/{http → native}/get.rb +1 -1
- data/lib/wrest/{http → native}/options.rb +1 -1
- data/lib/wrest/{http → native}/post.rb +1 -1
- data/lib/wrest/{http → native}/put.rb +1 -1
- data/lib/wrest/{http → native}/redirection.rb +4 -1
- data/lib/wrest/{http → native}/request.rb +32 -20
- data/lib/wrest/{http → native}/response.rb +12 -4
- data/lib/wrest/native/session.rb +57 -0
- data/lib/wrest/native.rb +32 -0
- data/lib/wrest/resource/base.rb +1 -1
- data/lib/wrest/resource.rb +1 -1
- data/lib/wrest/test/request_patches.rb +5 -0
- data/lib/wrest/test.rb +1 -0
- data/lib/wrest/uri.rb +31 -3
- data/lib/wrest/version.rb +2 -2
- data/lib/wrest.rb +52 -16
- data/spec/unit/spec_helper.rb +12 -3
- data/spec/unit/wrest/components/attributes_container/alias_accessors_spec.rb +2 -2
- data/spec/unit/wrest/components/attributes_container/typecaster_spec.rb +6 -6
- data/spec/unit/wrest/components/attributes_container_spec.rb +44 -12
- data/spec/unit/wrest/components/translators/xml_spec.rb +7 -3
- data/spec/unit/wrest/curl/request_spec.rb +19 -0
- data/spec/unit/wrest/curl/response_spec.rb +16 -0
- data/spec/unit/wrest/http/response_spec.rb +17 -38
- data/spec/unit/wrest/{http → native}/redirection_spec.rb +5 -5
- data/spec/unit/wrest/{http → native}/request_spec.rb +15 -14
- data/spec/unit/wrest/native/response_spec.rb +72 -0
- data/spec/unit/wrest/native/session_spec.rb +74 -0
- data/spec/unit/wrest/resource/base_spec.rb +2 -2
- data/spec/unit/wrest/uri_spec.rb +51 -11
- data/wrest.gemspec +168 -0
- metadata +60 -164
- data/lib/wrest/http.rb +0 -25
- data/spec/functional/sample_rails_app/README +0 -3
- data/spec/functional/sample_rails_app/Rakefile +0 -10
- data/spec/functional/sample_rails_app/app/controllers/application_controller.rb +0 -10
- data/spec/functional/sample_rails_app/app/controllers/lead_bottles_controller.rb +0 -7
- data/spec/functional/sample_rails_app/app/helpers/application_helper.rb +0 -3
- data/spec/functional/sample_rails_app/app/models/bottle.rb +0 -3
- data/spec/functional/sample_rails_app/app/models/glass_bottle.rb +0 -3
- data/spec/functional/sample_rails_app/app/models/lead_bottle.rb +0 -3
- data/spec/functional/sample_rails_app/config/boot.rb +0 -110
- data/spec/functional/sample_rails_app/config/database.yml +0 -16
- data/spec/functional/sample_rails_app/config/environment.rb +0 -42
- data/spec/functional/sample_rails_app/config/environments/development.rb +0 -17
- data/spec/functional/sample_rails_app/config/environments/production.rb +0 -28
- data/spec/functional/sample_rails_app/config/environments/test.rb +0 -28
- data/spec/functional/sample_rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/functional/sample_rails_app/config/initializers/inflections.rb +0 -10
- data/spec/functional/sample_rails_app/config/initializers/mime_types.rb +0 -5
- data/spec/functional/sample_rails_app/config/initializers/new_rails_defaults.rb +0 -19
- data/spec/functional/sample_rails_app/config/initializers/session_store.rb +0 -15
- data/spec/functional/sample_rails_app/config/locales/en.yml +0 -5
- data/spec/functional/sample_rails_app/config/routes.rb +0 -3
- data/spec/functional/sample_rails_app/db/development.sqlite3 +0 -0
- data/spec/functional/sample_rails_app/db/migrate/20090319115628_create_bottle.rb +0 -13
- data/spec/functional/sample_rails_app/db/schema.rb +0 -20
- data/spec/functional/sample_rails_app/db/test.sqlite3 +0 -0
- data/spec/functional/sample_rails_app/log/development.log +0 -1
- data/spec/functional/sample_rails_app/public/404.html +0 -30
- data/spec/functional/sample_rails_app/public/422.html +0 -30
- data/spec/functional/sample_rails_app/public/500.html +0 -30
- data/spec/functional/sample_rails_app/public/images/rails.png +0 -0
- data/spec/functional/sample_rails_app/public/index.html +0 -275
- data/spec/functional/sample_rails_app/public/robots.txt +0 -5
- data/spec/functional/sample_rails_app/script/about +0 -4
- data/spec/functional/sample_rails_app/script/autospec +0 -6
- data/spec/functional/sample_rails_app/script/console +0 -3
- data/spec/functional/sample_rails_app/script/dbconsole +0 -3
- data/spec/functional/sample_rails_app/script/destroy +0 -3
- data/spec/functional/sample_rails_app/script/generate +0 -3
- data/spec/functional/sample_rails_app/script/performance/benchmarker +0 -3
- data/spec/functional/sample_rails_app/script/performance/profiler +0 -3
- data/spec/functional/sample_rails_app/script/plugin +0 -3
- data/spec/functional/sample_rails_app/script/runner +0 -3
- data/spec/functional/sample_rails_app/script/server +0 -3
- data/spec/functional/sample_rails_app/script/spec +0 -10
- data/spec/functional/sample_rails_app/script/spec_server +0 -9
- data/spec/functional/sample_rails_app/test/performance/browsing_test.rb +0 -9
- data/spec/functional/sample_rails_app/test/test_helper.rb +0 -38
- data/spec/functional/sample_rails_app/tmtags +0 -2559
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/MIT-LICENSE +0 -20
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/README.rdoc +0 -100
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/Rakefile +0 -18
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/init.rb +0 -5
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/install.rb +0 -1
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/base.rb +0 -140
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/controllers/resources.rb +0 -16
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/controllers/resources_controller.rb +0 -26
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/controllers/routes_controller.rb +0 -16
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/core_extensions/api.rb +0 -26
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/core_extensions/exception.rb +0 -23
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/core_extensions/from_json.rb +0 -15
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/dispatch.rb +0 -235
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/models/resourced_route.rb +0 -84
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/query.rb +0 -337
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/render/html.rb +0 -50
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/render/json.rb +0 -75
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/render/xml.rb +0 -65
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/render.rb +0 -63
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/retrieve.rb +0 -74
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/version.rb +0 -9
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full.rb +0 -14
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/base_spec.rb +0 -88
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/controllers/resources_spec.rb +0 -29
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/dispatch_spec.rb +0 -262
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/models/resourced_route_spec.rb +0 -62
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/query/parameter_spec.rb +0 -57
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/query_spec.rb +0 -462
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/render/html_spec.rb +0 -4
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/render/json_spec.rb +0 -107
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/render/xml_spec.rb +0 -98
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/render_spec.rb +0 -5
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/retrieve_spec.rb +0 -173
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/spec_helper.rb +0 -98
- data/spec/functional/sample_rails_app/vendor/plugins/resource_full/uninstall.rb +0 -1
- data/spec/functional/spec_helper.rb +0 -0
data/spec/functional/sample_rails_app/vendor/plugins/resource_full/lib/resource_full/retrieve.rb
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
module ResourceFull
|
|
2
|
-
module Retrieve
|
|
3
|
-
class << self
|
|
4
|
-
def included(base)
|
|
5
|
-
super(base)
|
|
6
|
-
# Define new_person, update_person, etc.
|
|
7
|
-
base.before_filter :move_queryable_params_into_model_params_on_create, :only => [:create]
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Override this to provide custom find conditions. This is automatically merged at query
|
|
12
|
-
# time with the queried conditions extracted from params.
|
|
13
|
-
def find_options; {}; end
|
|
14
|
-
|
|
15
|
-
protected
|
|
16
|
-
|
|
17
|
-
def find_model_object
|
|
18
|
-
# TODO I am not sure what the correct behavior should be here, but I'm artifically
|
|
19
|
-
# generating the exception in order to avoid altering the render methods for the time being.
|
|
20
|
-
returning(model_class.find(:first, :conditions => { resource_identifier => params[:id]})) do |o|
|
|
21
|
-
raise ActiveRecord::RecordNotFound, "not found: #{params[:id]}" if o.nil?
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def new_model_object
|
|
26
|
-
model_class.new
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def update_model_object
|
|
30
|
-
returning(find_model_object) do |object|
|
|
31
|
-
object.update_attributes params[model_name]
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def create_model_object
|
|
36
|
-
model_class.create(params[model_name])
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def destroy_model_object
|
|
40
|
-
model_class.destroy_all(resource_identifier => params[:id])
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def find_all_model_objects
|
|
44
|
-
completed_query.find(:all)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def count_all_model_objects
|
|
48
|
-
completed_query.count
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def move_queryable_params_into_model_params_on_create
|
|
52
|
-
params.except(model_name).each do |param_name, value|
|
|
53
|
-
if self.class.queryable_params.collect(&:name).include?(param_name.to_sym)
|
|
54
|
-
params[model_name][param_name] = params.delete(param_name)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
private
|
|
60
|
-
|
|
61
|
-
def completed_query
|
|
62
|
-
self.class.queryable_params.inject(model_class) do |finder, queryer|
|
|
63
|
-
queryer.find finder, params
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def resource_identifier
|
|
68
|
-
returning(self.class.resource_identifier) do |column|
|
|
69
|
-
return column.call(params[:id]) if column.is_a?(Proc)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
end
|
|
74
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Core library
|
|
2
|
-
require 'resource_full/core_extensions/exception'
|
|
3
|
-
require 'resource_full/core_extensions/from_json'
|
|
4
|
-
require 'resource_full/dispatch'
|
|
5
|
-
require 'resource_full/query'
|
|
6
|
-
require 'resource_full/render'
|
|
7
|
-
require 'resource_full/retrieve'
|
|
8
|
-
require 'resource_full/version'
|
|
9
|
-
require 'resource_full/base'
|
|
10
|
-
|
|
11
|
-
# REST API
|
|
12
|
-
require 'resource_full/controllers/resources_controller'
|
|
13
|
-
require 'resource_full/controllers/routes_controller'
|
|
14
|
-
require 'resource_full/core_extensions/api'
|
data/spec/functional/sample_rails_app/vendor/plugins/resource_full/spec/resource_full/base_spec.rb
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ResourceFull::Base, :type => :controller do
|
|
4
|
-
controller_name "resource_full_mocks"
|
|
5
|
-
|
|
6
|
-
it "infers the name of its resource model from its class name" do
|
|
7
|
-
controller.model_name.should == "resource_full_mock"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "infers the class of its resource model from its class name" do
|
|
11
|
-
controller.model_class.should == ResourceFullMock
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
class ResourceFullFake; end
|
|
15
|
-
|
|
16
|
-
it "exposes a particular resource model given a symbol" do
|
|
17
|
-
controller.class.exposes :resource_full_fake
|
|
18
|
-
controller.model_class.should == ResourceFullFake
|
|
19
|
-
controller.class.exposes :resource_full_mock # cleanup
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "exposes a particular resource model given a pluralized symbol" do
|
|
23
|
-
controller.class.exposes :resource_full_fakes
|
|
24
|
-
controller.model_class.should == ResourceFullFake
|
|
25
|
-
controller.class.exposes :resource_full_mock # cleanup
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "exposes a particular resource model given a class" do
|
|
29
|
-
controller.class.exposes ResourceFullFake
|
|
30
|
-
controller.model_class.should == ResourceFullFake
|
|
31
|
-
controller.class.exposes ResourceFullMock # cleanup
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "renders two formats by default" do
|
|
35
|
-
controller.class.allowed_formats.should include(:xml, :html)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "allows you to specify what formats to render" do
|
|
39
|
-
controller.class.responds_to :xml, :json
|
|
40
|
-
controller.class.allowed_formats.should include(:xml, :json)
|
|
41
|
-
controller.class.allowed_formats.should_not include(:html)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
class NonResourcesController < ActionController::Base; end
|
|
45
|
-
class ResourcesController < ResourceFull::Base; end
|
|
46
|
-
|
|
47
|
-
it "knows about all controller subclasses of itself" do
|
|
48
|
-
ActionController::Routing.expects(:possible_controllers).at_least_once.returns %w{resources non_resources}
|
|
49
|
-
ResourceFull::Base.all_resources.should include(ResourcesController)
|
|
50
|
-
ResourceFull::Base.all_resources.should_not include(NonResourcesController)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "serializes the notion of a resource controller as XML" do
|
|
54
|
-
ResourceFullMockUsersController.clear_queryable_params!
|
|
55
|
-
ResourceFullMockUsersController.queryable_with :first_name
|
|
56
|
-
xml = Hash.from_xml(ResourceFullMockUsersController.to_xml)
|
|
57
|
-
xml["resource"]["name"].should == "resource_full_mock_users"
|
|
58
|
-
xml["resource"]["parameters"].first["name"].should == "first_name"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "has a default value of :id for the resource identifier column" do
|
|
62
|
-
ResourceFullMockUsersController.resource_identifier.should == :id
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "allows you to set the resource_identifier field" do
|
|
66
|
-
controller.class.identified_by :first_name
|
|
67
|
-
controller.class.resource_identifier.should == :first_name
|
|
68
|
-
controller.class.resource_identifier = :id # cleanup
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "is paginatable by default" do
|
|
72
|
-
controller.class.should be_paginatable
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "translates a model name into a controller constant" do
|
|
76
|
-
ResourceFull::Base.controller_for("resource_full_mock_users").should == ResourceFullMockUsersController
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it "raises ResourceNotFound if it cannot constantize the requested controller" do
|
|
80
|
-
lambda do
|
|
81
|
-
ResourceFull::Base.controller_for("nonsense")
|
|
82
|
-
end.should raise_error(ResourceFull::ResourceNotFound, "not found: nonsense")
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "returns the controller it's been given if it receives a Class object" do
|
|
86
|
-
ResourceFull::Base.controller_for(ResourceFullMockUsersController).should == ResourceFullMockUsersController
|
|
87
|
-
end
|
|
88
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
-
|
|
3
|
-
module ResourceFull
|
|
4
|
-
module Controllers
|
|
5
|
-
describe ResourcesController, :type => :controller do
|
|
6
|
-
|
|
7
|
-
it "finds all resources" do
|
|
8
|
-
get :index, :format => 'xml'
|
|
9
|
-
response.should have_tag('resources>resource') do
|
|
10
|
-
with_tag('name', 'resource_full_mock_users')
|
|
11
|
-
with_tag('name', 'resource_full_mock_addresses')
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "finds a specific resource" do
|
|
16
|
-
get :show, :format => 'xml', :id => 'resource_full_mock_users'
|
|
17
|
-
response.should have_tag('resource>name', 'resource_full_mock_users')
|
|
18
|
-
response.should_not have_tag('resource>name', 'resource_full_mock_addresses')
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "returns a 404 response when the requested resource is not found" do
|
|
22
|
-
get :show, :format => 'xml', :id => 'foo'
|
|
23
|
-
response.body.should have_tag("errors") { with_tag("error", "ResourceFull::ResourceNotFound: not found: foo") }
|
|
24
|
-
response.code.should == '404'
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
-
|
|
3
|
-
describe "ResourceFull::Dispatch", :type => :controller do
|
|
4
|
-
controller_name "resource_full_mocks"
|
|
5
|
-
|
|
6
|
-
before(:each) do
|
|
7
|
-
ResourceFullMock.stubs(:find).returns stub(:id => 1)
|
|
8
|
-
# controller.stubs :render
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "exposes a method for skipping format and method protection"
|
|
12
|
-
|
|
13
|
-
describe "based on request format" do
|
|
14
|
-
controller_name "resource_full_mocks"
|
|
15
|
-
|
|
16
|
-
after :each do
|
|
17
|
-
controller.class.responds_to :defaults
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "dispatches to index_xml render method if xml is requested" do
|
|
21
|
-
controller.expects(:index_xml)
|
|
22
|
-
get :index, :format => 'xml'
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "dispatches to index_json render method if json is requested" do
|
|
26
|
-
controller.expects(:index_json)
|
|
27
|
-
get :index, :format => 'json'
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "dispatches to index_html render method if html is requested" do
|
|
31
|
-
controller.expects(:index_html)
|
|
32
|
-
controller.stubs(:render)
|
|
33
|
-
get :index, :format => 'html'
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "raises a 406 error if it does not respond to a format for which no methods are included" do
|
|
37
|
-
get :index, :format => 'txt'
|
|
38
|
-
response.code.should == '406'
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "raises a 406 error if it does not respond to a format which has been explicitly removed" do
|
|
42
|
-
controller.class.responds_to :xml
|
|
43
|
-
get :index, :format => 'html'
|
|
44
|
-
response.code.should == '406'
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "includes an appropriate error message if it does not respond to a format which has been explicitly removed" do
|
|
48
|
-
controller.class.responds_to :xml
|
|
49
|
-
get :index, :format => 'html'
|
|
50
|
-
response.body.should =~ /Resource does not have a representation in text\/html format/
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe "based on request action" do
|
|
55
|
-
controller_name "resource_full_mocks"
|
|
56
|
-
|
|
57
|
-
after :each do
|
|
58
|
-
controller.class.responds_to :defaults
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "claims to respond to create, read, update, delete, and count by default" do
|
|
62
|
-
controller.class.responds_to :defaults
|
|
63
|
-
controller.class.allowed_methods.should include(:create, :read, :update, :delete)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "lists all the standard Rails methods plus count as its possible actions" do
|
|
67
|
-
controller.class.possible_actions.should include(:create, :new, :show, :index, :count, :update, :edit, :destroy)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "claims to not respond to any methods for an unsupported format" do
|
|
71
|
-
controller.class.responds_to :xml
|
|
72
|
-
controller.class.allowed_methods(:html).should be_empty
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "claims to respond to default methods for a requested format if no explicit methods are given" do
|
|
76
|
-
controller.class.responds_to :xml
|
|
77
|
-
controller.class.allowed_methods(:xml).should include(:create, :read, :update, :delete)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "claims to respond to only methods given a single value with the :only option" do
|
|
81
|
-
controller.class.responds_to :xml, :only => :read
|
|
82
|
-
controller.class.allowed_methods(:xml).should == [:read]
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "claims to respond to only methods given multiple values with the :only option" do
|
|
86
|
-
controller.class.responds_to :xml, :only => [:read, :delete]
|
|
87
|
-
controller.class.allowed_methods(:xml).should == [:read, :delete]
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "responds successfully to supported methods" do
|
|
91
|
-
controller.class.responds_to :xml, :only => :read
|
|
92
|
-
controller.stubs(:index)
|
|
93
|
-
get :index, :format => "xml"
|
|
94
|
-
response.should be_success
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "disallows unsupported methods with code 405" do
|
|
98
|
-
controller.class.responds_to :html, :only => :read
|
|
99
|
-
controller.stubs(:destroy)
|
|
100
|
-
delete :destroy, :id => 1
|
|
101
|
-
response.code.should == '405'
|
|
102
|
-
response.body.should =~ /Resource does not allow destroy action/
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "ignores and does not verify custom methods" do
|
|
106
|
-
controller.class.responds_to :xml, :only => [:delete]
|
|
107
|
-
|
|
108
|
-
get :foo, :format => 'xml'
|
|
109
|
-
response.body.should have_tag("foo", "bar")
|
|
110
|
-
response.code.should == '200'
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "allows you to specify the appropriate CRUD semantics of a custom method"
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
describe "GET index" do
|
|
117
|
-
controller_name "resource_full_mocks"
|
|
118
|
-
|
|
119
|
-
before :each do
|
|
120
|
-
controller.stubs(:render)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it "sets an @mocks instance variable based on the default finder" do
|
|
124
|
-
ResourceFullMock.stubs(:find).returns "a list of mocks"
|
|
125
|
-
get :index, :format => 'html'
|
|
126
|
-
assigns(:resource_full_mocks).should == "a list of mocks"
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it "sets an @mocks instance variable appropriately if the default finder is overridden" do
|
|
130
|
-
begin
|
|
131
|
-
controller.class.class_eval do
|
|
132
|
-
def find_all_resource_full_mocks; "another list of mocks"; end
|
|
133
|
-
end
|
|
134
|
-
get :index, :format => 'html'
|
|
135
|
-
assigns(:resource_full_mocks).should == "another list of mocks"
|
|
136
|
-
ensure
|
|
137
|
-
controller.class.class_eval do
|
|
138
|
-
undef :find_all_resource_full_mocks
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
describe "GET show" do
|
|
145
|
-
controller_name "resource_full_mocks"
|
|
146
|
-
|
|
147
|
-
before :each do
|
|
148
|
-
controller.stubs(:render)
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it "sets a @mock instance variable based on the default finder" do
|
|
152
|
-
ResourceFullMock.stubs(:find).returns "a mock"
|
|
153
|
-
get :show, :id => 1, :format => 'html'
|
|
154
|
-
assigns(:resource_full_mock).should == "a mock"
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "sets a @mock instance variable appropriately if the default finder is overridden" do
|
|
158
|
-
controller.class.class_eval do
|
|
159
|
-
def find_resource_full_mock; "another mock"; end
|
|
160
|
-
end
|
|
161
|
-
get :show, :id => 1, :format => 'html'
|
|
162
|
-
assigns(:resource_full_mock).should == "another mock"
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
describe "POST create" do
|
|
167
|
-
controller_name "resource_full_mocks"
|
|
168
|
-
|
|
169
|
-
before :each do
|
|
170
|
-
controller.stubs :render
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it "sets a @mock instance variable based on the default creator" do
|
|
174
|
-
ResourceFullMock.stubs(:create).returns stub(:errors => stub_everything, :id => :mock)
|
|
175
|
-
post :create, :format => 'html'
|
|
176
|
-
assigns(:resource_full_mock).id.should == :mock
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it "sets a @mock instance variable appropriately if the default creator is overridden" do
|
|
180
|
-
ResourceFullMock.stubs(:super_create).returns stub(:errors => stub_everything, :id => :super_mock)
|
|
181
|
-
controller.class.class_eval do
|
|
182
|
-
def create_resource_full_mock; ResourceFullMock.super_create; end
|
|
183
|
-
end
|
|
184
|
-
post :create, :format => 'html'
|
|
185
|
-
assigns(:resource_full_mock).id.should == :super_mock
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
describe "PUT update" do
|
|
190
|
-
controller_name "resource_full_mocks"
|
|
191
|
-
|
|
192
|
-
before :each do
|
|
193
|
-
controller.stubs :render
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
it "sets a @mock instance variable based on the default updater" do
|
|
197
|
-
ResourceFullMock.stubs(:find).returns stub(:id => 1, :update_attributes => true, :errors => stub_everything)
|
|
198
|
-
put :update, :id => 1, :format => 'html'
|
|
199
|
-
assigns(:resource_full_mock).id.should == 1
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
it "sets a @mock instance variable appropriately if the default updater is overridden" do
|
|
203
|
-
ResourceFullMock.stubs(:super_update).returns stub(:errors => stub_everything, :id => :super_mock)
|
|
204
|
-
controller.class.class_eval do
|
|
205
|
-
def update_resource_full_mock; ResourceFullMock.super_update; end
|
|
206
|
-
end
|
|
207
|
-
put :update, :id => 1, :format => 'html'
|
|
208
|
-
assigns(:resource_full_mock).id.should == :super_mock
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
describe "when the user agent is IE7" do
|
|
213
|
-
before :each do
|
|
214
|
-
request.env["HTTP_USER_AGENT"] = "MSIE 7.0"
|
|
215
|
-
controller.stubs(:find_all_resource_full_mocks).returns([])
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
it "should set the request format to json when the incoming request format looks like json" do
|
|
219
|
-
get :index, :format => 'json-test'
|
|
220
|
-
response.content_type.should == "application/json"
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
it "should set the request format to json when the incoming request format looks like javascript" do
|
|
224
|
-
get :index, :format => 'javascript-test'
|
|
225
|
-
response.content_type.should == "application/json"
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
it "should set the request format to json when the incoming request uri looks like json" do
|
|
229
|
-
request.env["REQUEST_URI"] = "/resource_full_mocks.json?foo=bar"
|
|
230
|
-
get :index
|
|
231
|
-
response.content_type.should == "application/json"
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
it "should set the request format to xml when the incoming request format looks like xml" do
|
|
235
|
-
get :index, :format => 'xml-test'
|
|
236
|
-
response.content_type.should == "application/xml"
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
it "should set the request format to json when the incoming request uri looks like xml" do
|
|
240
|
-
request.env["REQUEST_URI"] = "/resource_full_mocks.xml?foo=bar"
|
|
241
|
-
get :index
|
|
242
|
-
response.content_type.should == "application/xml"
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
# Dirk assures me that the following functionality is necessary due to the way Rails handles IE7
|
|
246
|
-
# request formats, or perhaps the way IE7 sends its request content-type.
|
|
247
|
-
# TODO Find a better criterion than 'else, use text/html'.
|
|
248
|
-
it "should default the request format to text/html when the incoming request uri is not supported" do
|
|
249
|
-
controller.stubs :render
|
|
250
|
-
request.env["REQUEST_URI"] = "/resource_full_mocks.png"
|
|
251
|
-
get :index
|
|
252
|
-
response.content_type.should == "text/html"
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
# See above.
|
|
256
|
-
it "should default the request format to text/html when the incoming request format is not supported" do
|
|
257
|
-
controller.stubs :render
|
|
258
|
-
get :index, :format => "image/png"
|
|
259
|
-
response.content_type.should == "text/html"
|
|
260
|
-
end
|
|
261
|
-
end
|
|
262
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
-
|
|
3
|
-
module ResourceFull
|
|
4
|
-
module Models
|
|
5
|
-
describe ResourcedRoute do
|
|
6
|
-
it "has a verb, name, pattern, and action" do
|
|
7
|
-
ResourcedRoute.new(:controller => "resource_full_mock_users", :verb => "GET").verb.should == "GET"
|
|
8
|
-
ResourcedRoute.new(:controller => "resource_full_mock_users", :name => "users").name.should == "users"
|
|
9
|
-
ResourcedRoute.new(:controller => "resource_full_mock_users", :pattern => "/users").pattern.should == "/users"
|
|
10
|
-
ResourcedRoute.new(:controller => "resource_full_mock_users", :action => "index").action.should == "index"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "has an associated controller derived from the given string" do
|
|
14
|
-
ResourcedRoute.new(:controller => "resource_full_mock_users").controller.should == ResourceFullMockUsersController
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "has an associated controller derived from the given class" do
|
|
18
|
-
ResourcedRoute.new(:controller => ResourceFullMockUsersController).controller.should == ResourceFullMockUsersController
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "should know if it's a formatted route" do
|
|
22
|
-
ResourcedRoute.new(:controller => "resource_full_mock_users", :name => "formatted_resource_full_mock_users").should be_formatted
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
class DumbController < ActionController::Base; end
|
|
26
|
-
|
|
27
|
-
it "should know if it's a resourced route" do
|
|
28
|
-
ResourcedRoute.new(:controller => DumbController).should_not be_resourced
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "should know how to look up its resource" do
|
|
32
|
-
ResourcedRoute.new(:controller => ResourceFullMockUsersController).resource.should == "resource_full_mock_users"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe "query" do
|
|
36
|
-
it "raises an exception when it can't find a particular route" do
|
|
37
|
-
lambda do
|
|
38
|
-
ResourcedRoute.find("this route does not exist")
|
|
39
|
-
end.should raise_error(ResourceFull::Models::RouteNotFound)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "locates a particular named route" do
|
|
43
|
-
route = ResourcedRoute.find :resource_full_mock_users
|
|
44
|
-
route.pattern.should == "/resource_full_mock_users(.:format)?"
|
|
45
|
-
route.verb.should == "GET"
|
|
46
|
-
route.action.should == "index"
|
|
47
|
-
route.controller.should == ResourceFullMockUsersController
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "locates all named routes" do
|
|
51
|
-
ResourcedRoute.find(:all).collect(&:name).should include(:resource_full_mock_users, :new_resource_full_mock_user, :resource_full_mock_addresses)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "should filter by a particular resource" do
|
|
55
|
-
route_names = ResourcedRoute.find(:all, :resource_id => "resource_full_mock_users").collect(&:name)
|
|
56
|
-
route_names.should include(:resource_full_mock_users)
|
|
57
|
-
route_names.should_not include(:resource_full_mock_addresses)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
-
|
|
3
|
-
# TODO Most of this functionality is covered by more functional tests elsewhere,
|
|
4
|
-
# but it would be nice to have better unit-level coverage for specific breakages.
|
|
5
|
-
module ResourceFull
|
|
6
|
-
module Query
|
|
7
|
-
describe CustomParameter do
|
|
8
|
-
it "renders itself as XML" do
|
|
9
|
-
xml = CustomParameter.new(:name, ResourceFullMockUsersController,
|
|
10
|
-
:fuzzy => true,
|
|
11
|
-
:columns => [:full_name, :username, :email]
|
|
12
|
-
).to_xml
|
|
13
|
-
|
|
14
|
-
Hash.from_xml(xml)["parameter"]["fuzzy"].should be_true
|
|
15
|
-
Hash.from_xml(xml)["parameter"]["name"].should == "name"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe "inferring the correct table" do
|
|
19
|
-
|
|
20
|
-
it "simply uses the given table if one is specified" do
|
|
21
|
-
CustomParameter.new(:foo, ResourceFullMockUsersController, :table => "users").table.should == "users"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "uses the table for the given resource if no :from option is specified" do
|
|
25
|
-
CustomParameter.new(:foo, ResourceFullMockUsersController).table.should == "resource_full_mock_users"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "looks up the table name for the given association if it is direct" do
|
|
29
|
-
CustomParameter.new(:foo, ResourceFullMockUsersController, :from => :resource_full_mock_addresses).table.should == "resource_full_mock_addresses"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "looks up the table name for the given assocation if it is specified in a hash" do
|
|
33
|
-
CustomParameter.new(:foo, ResourceFullMockAddressesController, :from => { :resource_full_mock_user => :resource_full_mock_employer }).table.should == "resource_full_mock_employers"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "subclass" do
|
|
39
|
-
it "returns a copy of itself with its table unchanged if the subclass does not use a different table" do
|
|
40
|
-
parameter = ResourceFull::Query::CustomParameter.new(:name, ResourceFullMocksController)
|
|
41
|
-
parameter.subclass(ResourceFullSubMocksController).table.should == "mock"
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "returns a copy of itself with its table altered if the subclass uses a different table" do
|
|
45
|
-
ResourceFullSubMocksController.exposes :resource_full_mock_user
|
|
46
|
-
parameter = ResourceFull::Query::CustomParameter.new(:name, ResourceFullMocksController)
|
|
47
|
-
parameter.subclass(ResourceFullSubMocksController).table.should == "resource_full_mock_users"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "returns a copy of itself with its table unchanged if it was originally built with a custom table" do
|
|
51
|
-
parameter = ResourceFull::Query::CustomParameter.new(:name, ResourceFullMocksController, :table => "widgets")
|
|
52
|
-
parameter.subclass(ResourceFullSubMocksController).table.should == "widgets"
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|