hookercookerman-merb-resource-scope 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.
Files changed (31) hide show
  1. data/LICENSE +20 -0
  2. data/README.textile +297 -0
  3. data/Rakefile +82 -0
  4. data/TODO +3 -0
  5. data/lib/dependencies.rb +1 -0
  6. data/lib/merb-resource-scope.rb +25 -0
  7. data/lib/merb-resource-scope/controller/actions.rb +67 -0
  8. data/lib/merb-resource-scope/controller/helpers.rb +252 -0
  9. data/lib/merb-resource-scope/controller/scoped_resource_mixin.rb +300 -0
  10. data/lib/merb-resource-scope/controller/singleton_actions.rb +25 -0
  11. data/lib/merb-resource-scope/merbtasks.rb +6 -0
  12. data/lib/merb-resource-scope/router/resource_specification.rb +144 -0
  13. data/lib/merb-resource-scope/specification.rb +36 -0
  14. data/spec/app.rb +7 -0
  15. data/spec/controller/_build_enclosing_scope_spec.rb +107 -0
  16. data/spec/controller/scope_resource_mixin_spec.rb +0 -0
  17. data/spec/integration/admin_posts_controller_spec.rb +158 -0
  18. data/spec/integration/campaign_post_comments_controller_spec.rb +158 -0
  19. data/spec/integration/campaign_posts_controller_spec.rb +73 -0
  20. data/spec/integration/campaigns_controller_spec.rb +43 -0
  21. data/spec/integration/images_spec.rb +17 -0
  22. data/spec/integration/myhome_controller_spec.rb +29 -0
  23. data/spec/integration/myhome_posts_comment_controller_spec.rb +44 -0
  24. data/spec/integration/myhome_posts_controller_spec.rb +55 -0
  25. data/spec/integration/profile_images_controller_spec.rb +61 -0
  26. data/spec/integration/tags_controller_spec.rb +34 -0
  27. data/spec/integration/user_posts_controller_spec.rb +71 -0
  28. data/spec/request_with_controller.rb +103 -0
  29. data/spec/spec_helper.rb +33 -0
  30. data/spec/specification_spec.rb +1 -0
  31. metadata +88 -0
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ given "requsting post_images/:id/tags" do
4
+ DataMapper.auto_migrate!
5
+ @post_image = PostImage.gen
6
+ Tag.gen :post_image => @post_image
7
+ @rack = request_with_controller("/post_images/#{@post_image.id}/tags")
8
+ end
9
+
10
+ describe "tags controller spec", :given => "requsting post_images/:id/tags" do
11
+ it "should not be cool 'requsting post_images/:id/tags' as there is no action" do
12
+ @rack.status.should == 500
13
+ end
14
+ end
15
+
16
+ given "requsting post_images/:id/tags/:id" do
17
+ DataMapper.auto_migrate!
18
+ @post_image = PostImage.gen
19
+ @tag = Tag.gen :post_image => @post_image
20
+ @rack = request_with_controller("/post_images/#{@post_image.id}/tags/#{@tag.id}")
21
+ end
22
+
23
+ describe "tags controller spec", :given => "requsting post_images/:id/tags/:id" do
24
+ it "should be cool 'requsting post_images/:id/tags/:id' as there there is an action" do
25
+ @rack.should be_successful
26
+ end
27
+ it "should have a current_resource of 'PostImage.get(:id).tags.get(@tag.id)'" do
28
+ @rack.controller.current_resource.should == PostImage.get(@post_image.id).tags.get(@tag.id)
29
+ end
30
+
31
+ it "should have a enclosing_resource of 'PostImage.get(:id)'" do
32
+ @rack.controller.enclosing_resource.should == PostImage.get(@post_image.id)
33
+ end
34
+ end
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ given "requsting '/users/hookercookerman/posts/merb-is-gravey'" do
4
+ DataMapper.auto_migrate!
5
+ @user = User.gen :login => "hookercookerman"
6
+ @post = Post.gen :title => "merb-is-gravey", :user => @user
7
+ @rack = request_with_controller("/users/hookercookerman/posts/merb-is-gravey")
8
+ end
9
+
10
+ describe "Posts controller spec", :given => "requsting '/users/hookercookerman/posts/merb-is-gravey'" do
11
+ it "should be cool 'requsting requsting /users/hookercookerman/posts/merb-is-gravey" do
12
+ @rack.should be_successful
13
+ end
14
+
15
+ it "should have an current_resource of User.first(:conditions => {:login => 'hookercookerman'}).post.first :conditions => {:title => 'merb-is-gravey}" do
16
+ @rack.controller.current_resource.should == @post
17
+ end
18
+
19
+ it "should have an enclosing resource of User.first(:conditions => {:login => 'hookercookerman'})" do
20
+ @rack.controller.enclosing_resource.should == @user
21
+ end
22
+
23
+ it "should have a enclosing_resource_url of /users/:id" do
24
+ @rack.controller.enclosing_resource_url.should == "/users/hookercookerman"
25
+ end
26
+
27
+ it "should have enclosing_resources_url of /users" do
28
+ @rack.controller.enclosing_resources_url.should == "/users"
29
+ end
30
+
31
+ it "should have current_resources_url of /users/:id/posts" do
32
+ @rack.controller.current_resources_url.should == "/users/hookercookerman/posts"
33
+ end
34
+ end
35
+
36
+
37
+ given "requsting '/users/hookercookerman/posts via POST'" do
38
+ DataMapper.auto_migrate!
39
+ @user = User.gen :login => "hookercookerman"
40
+ @post = Post.gen :title => "merb-is-gravey", :user => @user
41
+ @rack = request_with_controller("/users/hookercookerman/posts", :method => "POST",
42
+ :params => {:post => {:title => "beans", :body => "eggs"}})
43
+ end
44
+
45
+ describe "Posts controller spec", :given => "requsting '/users/hookercookerman/posts via POST'" do
46
+ it "should have an current_resource of" do
47
+ @rack.controller.current_resource.body.should == "eggs"
48
+ @rack.controller.current_resource.title.should == "beans"
49
+ end
50
+
51
+ it "should be a saved record" do
52
+ @rack.controller.current_resource.new_record? == false
53
+ end
54
+ end
55
+
56
+
57
+ given "requsting '/users/10' where user does not exist" do
58
+ DataMapper.auto_migrate!
59
+ @rack = request_with_controller("/users/10")
60
+ end
61
+
62
+ describe "User controller spec", :given => "requsting '/users/10' where user does not exist" do
63
+ it "should not be cool 'requsting requsting requsting '/users/10'" do
64
+ @rack.should_not be_successful
65
+ end
66
+ end
67
+
68
+ describe "User controller spec where user does not exist" do
69
+ it "should be cool 'requsting requsting requsting '/users/10'" do
70
+ end
71
+ end
@@ -0,0 +1,103 @@
1
+ # OK OK OK OK
2
+ # its a hack, but had to specs up and running
3
+ # when find a way to do this properly
4
+ # WHY DID YOU DO THIS????
5
+ # basically I need to go through the routes fully in the specs, and I also need access to the controller
6
+ # hence the names request_with_controller
7
+
8
+ module Merb
9
+ module Rack
10
+ class ResourceTest
11
+
12
+ # The main rack application call method. This is the entry point from rack (and the webserver)
13
+ # to your application.
14
+ #
15
+ # ==== Parameters
16
+ # env<Hash>:: A rack request of parameters.
17
+ #
18
+ # ==== Returns
19
+ # <Array>:: A rack response of [status<Integer>, headers<Hash>, body<String, Stream>]
20
+ #
21
+ # @api private
22
+ def call(env)
23
+ begin
24
+ request = Merb::Request.new(env)
25
+ request.find_route!
26
+ klass = request.controller
27
+
28
+ controller = klass.new(request)
29
+ controller._dispatch(request.params[:action])
30
+ rescue Object => e
31
+ return [500, {Merb::Const::CONTENT_TYPE => Merb::Const::TEXT_SLASH_HTML}, e.message + Merb::Const::BREAK_TAG + e.backtrace.join(Merb::Const::BREAK_TAG)]
32
+ end
33
+ Merb.logger.info
34
+ Merb::Const::DOUBLE_NEWLINE
35
+ Merb.logger.flush
36
+
37
+ # end
38
+ controller.rack_response << controller
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ module Merb
45
+ module Test
46
+ module RequestHelper
47
+
48
+
49
+ def request_with_controller(uri, env = {})
50
+ uri = url(uri) if uri.is_a?(Symbol)
51
+ uri = URI(uri)
52
+ uri.scheme ||= "http"
53
+ uri.host ||= "example.org"
54
+
55
+ if (env[:method] == "POST" || env["REQUEST_METHOD"] == "POST")
56
+ params = env.delete(:body_params) if env.key?(:body_params)
57
+ params = env.delete(:params) if env.key?(:params) && !env.key?(:input)
58
+
59
+ unless env.key?(:input)
60
+ env[:input] = Merb::Parse.params_to_query_string(params)
61
+ env["CONTENT_TYPE"] = "application/x-www-form-urlencoded"
62
+ end
63
+ end
64
+
65
+ if env[:params]
66
+ uri.query = [
67
+ uri.query, Merb::Parse.params_to_query_string(env.delete(:params))
68
+ ].compact.join("&")
69
+ end
70
+
71
+ ignore_cookies = env.has_key?(:jar) && env[:jar].nil?
72
+
73
+ unless ignore_cookies
74
+ # Setup a default cookie jar container
75
+ @__cookie_jar__ ||= Merb::Test::CookieJar.new
76
+ # Grab the cookie group name
77
+ jar = env.delete(:jar) || :default
78
+ # Set the cookie header with the cookies
79
+ env["HTTP_COOKIE"] = @__cookie_jar__.for(jar, uri)
80
+ end
81
+
82
+ app = Merb::Rack::ResourceTest.new
83
+ rack = app.call(::Rack::MockRequest.env_for(uri.to_s, env))
84
+
85
+
86
+ rack = Struct.new(:status, :headers, :body, :url, :env, :controller).
87
+ new(rack[0], rack[1], rack[2], uri, env, rack[3])
88
+
89
+ @__cookie_jar__.update(jar, uri, rack.headers["Set-Cookie"]) unless ignore_cookies
90
+
91
+ Merb::Dispatcher.work_queue.size.times do
92
+ Merb::Dispatcher.work_queue.pop.call
93
+ end
94
+
95
+ yield rack.controller if block_given?
96
+ rack
97
+ end
98
+ alias requesting_with_controller request_with_controller
99
+
100
+
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,33 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'test-stack')
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'rubygems'
5
+
6
+ # Add the local gems dir if found within the app root; any dependencies loaded
7
+ # hereafter will try to load from the local gems before loading system gems.
8
+ if (local_gem_dir = File.join(File.dirname(__FILE__), ".." , "test-stack", "gems")) && $BUNDLE.nil?
9
+ $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
10
+ end
11
+
12
+ require "merb-core"
13
+ require 'merb-resource-scope'
14
+
15
+ require "spec"
16
+
17
+ require File.expand_path(File.dirname(__FILE__) + '/request_with_controller')
18
+
19
+ Merb.start_environment(
20
+ :testing => true,
21
+ :adapter => 'runner',
22
+ :environment => ENV['MERB_ENV'] || 'test',
23
+ :merb_root => File.dirname(__FILE__) / ".." / "test-stack",
24
+ :log_file => File.dirname(__FILE__) / ".." / "test-stack" / "log" / "merb_test.log"
25
+ )
26
+
27
+ Spec::Runner.configure do |config|
28
+ config.include(Merb::Test::ViewHelper)
29
+ config.include(Merb::Test::RouteHelper)
30
+ config.include(Merb::Test::ControllerHelper)
31
+ end
32
+
33
+ require File.dirname(__FILE__) / ".." / "test-stack" / "spec" / "spec_fixtures"
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hookercookerman-merb-resource-scope
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hookercookerman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Merb plugin that provides scoped resourceful controllers
17
+ email: hookercookerman@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.textile
24
+ - LICENSE
25
+ - TODO
26
+ files:
27
+ - LICENSE
28
+ - README.textile
29
+ - Rakefile
30
+ - TODO
31
+ - lib/dependencies.rb
32
+ - lib/merb-resource-scope
33
+ - lib/merb-resource-scope/controller
34
+ - lib/merb-resource-scope/controller/actions.rb
35
+ - lib/merb-resource-scope/controller/helpers.rb
36
+ - lib/merb-resource-scope/controller/scoped_resource_mixin.rb
37
+ - lib/merb-resource-scope/controller/singleton_actions.rb
38
+ - lib/merb-resource-scope/merbtasks.rb
39
+ - lib/merb-resource-scope/router
40
+ - lib/merb-resource-scope/router/resource_specification.rb
41
+ - lib/merb-resource-scope/specification.rb
42
+ - lib/merb-resource-scope.rb
43
+ has_rdoc: true
44
+ homepage: http://www.dynamic50.com/
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.2.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: Merb plugin that provides scoped resourceful controllers
69
+ test_files:
70
+ - spec/app.rb
71
+ - spec/controller
72
+ - spec/controller/_build_enclosing_scope_spec.rb
73
+ - spec/controller/scope_resource_mixin_spec.rb
74
+ - spec/integration
75
+ - spec/integration/admin_posts_controller_spec.rb
76
+ - spec/integration/campaign_post_comments_controller_spec.rb
77
+ - spec/integration/campaign_posts_controller_spec.rb
78
+ - spec/integration/campaigns_controller_spec.rb
79
+ - spec/integration/images_spec.rb
80
+ - spec/integration/myhome_controller_spec.rb
81
+ - spec/integration/myhome_posts_comment_controller_spec.rb
82
+ - spec/integration/myhome_posts_controller_spec.rb
83
+ - spec/integration/profile_images_controller_spec.rb
84
+ - spec/integration/tags_controller_spec.rb
85
+ - spec/integration/user_posts_controller_spec.rb
86
+ - spec/request_with_controller.rb
87
+ - spec/spec_helper.rb
88
+ - spec/specification_spec.rb