bradphelan-sinatras-hat 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.gitignore +4 -0
  2. data/LICENSE +22 -0
  3. data/README.md +235 -0
  4. data/Rakefile +59 -0
  5. data/VERSION +1 -0
  6. data/bradphelan-sinatras-hat.gemspec +145 -0
  7. data/ci.rb +9 -0
  8. data/example/app-with-auth.rb +14 -0
  9. data/example/app-with-cache.rb +30 -0
  10. data/example/app.rb +23 -0
  11. data/example/lib/comment.rb +13 -0
  12. data/example/lib/common.rb +19 -0
  13. data/example/lib/post.rb +16 -0
  14. data/example/simple-app.rb +4 -0
  15. data/example/views/comments/index.erb +6 -0
  16. data/example/views/comments/show.erb +1 -0
  17. data/example/views/posts/index.erb +8 -0
  18. data/example/views/posts/new.erb +11 -0
  19. data/example/views/posts/show.erb +28 -0
  20. data/features/authenticated.feature +12 -0
  21. data/features/create.feature +16 -0
  22. data/features/destroy.feature +18 -0
  23. data/features/edit.feature +17 -0
  24. data/features/formats.feature +19 -0
  25. data/features/headers.feature +28 -0
  26. data/features/index.feature +23 -0
  27. data/features/layouts.feature +11 -0
  28. data/features/nested.feature +20 -0
  29. data/features/new.feature +20 -0
  30. data/features/only.feature +13 -0
  31. data/features/show.feature +31 -0
  32. data/features/steps/authenticated_steps.rb +10 -0
  33. data/features/steps/common_steps.rb +77 -0
  34. data/features/steps/create_steps.rb +21 -0
  35. data/features/steps/destroy_steps.rb +16 -0
  36. data/features/steps/edit_steps.rb +7 -0
  37. data/features/steps/format_steps.rb +11 -0
  38. data/features/steps/header_steps.rb +7 -0
  39. data/features/steps/index_steps.rb +26 -0
  40. data/features/steps/nested_steps.rb +11 -0
  41. data/features/steps/new_steps.rb +15 -0
  42. data/features/steps/only_steps.rb +10 -0
  43. data/features/steps/show_steps.rb +24 -0
  44. data/features/steps/update_steps.rb +22 -0
  45. data/features/support/env.rb +17 -0
  46. data/features/support/views/comments/index.erb +5 -0
  47. data/features/support/views/layout.erb +9 -0
  48. data/features/support/views/people/edit.erb +1 -0
  49. data/features/support/views/people/index.erb +1 -0
  50. data/features/support/views/people/layout.erb +9 -0
  51. data/features/support/views/people/new.erb +1 -0
  52. data/features/support/views/people/show.erb +1 -0
  53. data/features/update.feature +25 -0
  54. data/lib/core_ext/array.rb +5 -0
  55. data/lib/core_ext/hash.rb +23 -0
  56. data/lib/core_ext/module.rb +14 -0
  57. data/lib/core_ext/object.rb +45 -0
  58. data/lib/sinatras-hat.rb +22 -0
  59. data/lib/sinatras-hat/actions.rb +81 -0
  60. data/lib/sinatras-hat/authentication.rb +55 -0
  61. data/lib/sinatras-hat/extendor.rb +24 -0
  62. data/lib/sinatras-hat/hash_mutator.rb +18 -0
  63. data/lib/sinatras-hat/logger.rb +36 -0
  64. data/lib/sinatras-hat/maker.rb +187 -0
  65. data/lib/sinatras-hat/model.rb +110 -0
  66. data/lib/sinatras-hat/resource.rb +57 -0
  67. data/lib/sinatras-hat/responder.rb +106 -0
  68. data/lib/sinatras-hat/response.rb +60 -0
  69. data/lib/sinatras-hat/router.rb +46 -0
  70. data/sinatras-hat.gemspec +34 -0
  71. data/spec/actions/create_spec.rb +68 -0
  72. data/spec/actions/destroy_spec.rb +58 -0
  73. data/spec/actions/edit_spec.rb +52 -0
  74. data/spec/actions/index_spec.rb +72 -0
  75. data/spec/actions/new_spec.rb +39 -0
  76. data/spec/actions/show_spec.rb +85 -0
  77. data/spec/actions/update_spec.rb +83 -0
  78. data/spec/extendor_spec.rb +78 -0
  79. data/spec/fixtures/views/articles/edit.erb +1 -0
  80. data/spec/fixtures/views/articles/index.erb +1 -0
  81. data/spec/fixtures/views/articles/new.erb +1 -0
  82. data/spec/fixtures/views/articles/show.erb +1 -0
  83. data/spec/hash_mutator_spec.rb +23 -0
  84. data/spec/maker_spec.rb +411 -0
  85. data/spec/model_spec.rb +152 -0
  86. data/spec/resource_spec.rb +74 -0
  87. data/spec/responder_spec.rb +139 -0
  88. data/spec/response_spec.rb +120 -0
  89. data/spec/router_spec.rb +105 -0
  90. data/spec/spec_helper.rb +80 -0
  91. metadata +161 -0
@@ -0,0 +1,105 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Sinatra::Hat::Router do
4
+ before(:each) do
5
+ build_models!
6
+ end
7
+
8
+ describe "initialization" do
9
+ it "takes an instance of Maker" do
10
+ proc {
11
+ maker = new_maker
12
+ Sinatra::Hat::Router.new(maker)
13
+ }.should_not raise_error
14
+ end
15
+ end
16
+
17
+ describe "#generate" do
18
+ attr_reader :app, :maker, :router
19
+
20
+ before(:each) do
21
+ @app = mock_app { set :views, fixture('views') }
22
+ @maker = new_maker
23
+ @router = Sinatra::Hat::Router.new(maker)
24
+ stub.proxy(app).get(anything)
25
+ end
26
+
27
+ it "takes a Sinatra app" do
28
+ router.generate(app)
29
+ end
30
+
31
+ describe "abiding by the maker's :only option" do
32
+ before(:each) do
33
+ maker.only :index, :show
34
+ router.generate(app)
35
+ end
36
+
37
+ it "should only have the limited options" do
38
+ mock(app).put(anything).never
39
+ mock(app).delete(anything).never
40
+ post '/articles'
41
+ response.status.should == 404
42
+ put "/articles/#{@article.to_param}"
43
+ response.status.should == 404
44
+ delete "/articles/#{@article.to_param}"
45
+ response.status.should == 404
46
+ end
47
+ end
48
+
49
+ describe "generating index route" do
50
+ it "calls the block, passing the request" do
51
+ router.generate(app)
52
+ mock.proxy(maker).handle(:index, anything) { "" }
53
+ get '/articles.yaml'
54
+ end
55
+ end
56
+
57
+ describe "generating show route" do
58
+ it "calls the block, passing the request" do
59
+ router.generate(app)
60
+ mock.proxy(maker).handle(:show, anything) { "" }
61
+ get '/articles/1.yaml'
62
+ end
63
+ end
64
+
65
+ describe "generating create route" do
66
+ it "calls the block, passing the request" do
67
+ router.generate(app)
68
+ mock(maker).handle(:create, anything)
69
+ post '/articles', "maker[name]" => "Pat"
70
+ end
71
+ end
72
+
73
+ describe "generating new route" do
74
+ it "calls the block, passing the request" do
75
+ router.generate(app)
76
+ mock.proxy(maker).handle(:new, anything) { "" }
77
+ get '/articles/new'
78
+ end
79
+ end
80
+
81
+ describe "generating destroy route" do
82
+ it "calls the block, passing the request" do
83
+ router.generate(app)
84
+ mock.proxy(maker).handle(:destroy, anything) { "" }
85
+ delete "/articles/#{@article.to_param}"
86
+ end
87
+ end
88
+
89
+ describe "generating edit route" do
90
+ it "calls the block, passing the request" do
91
+ router.generate(app)
92
+ mock.proxy(maker).handle(:edit, anything) { "" }
93
+ get "/articles/#{@article.to_param}/edit"
94
+ end
95
+ end
96
+
97
+ describe "generating update route" do
98
+ it "calls the block, passing the request" do
99
+ router.generate(app)
100
+ mock.proxy(maker).handle(:update, anything) { "" }
101
+ put "/articles/#{@article.to_param}"
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,80 @@
1
+ ARGV.clear
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
4
+
5
+ require 'rubygems'
6
+ require 'spec'
7
+ require 'rr'
8
+ require 'sinatra/base'
9
+ require 'sinatra/test'
10
+ require 'sinatra/test/rspec'
11
+
12
+ # What we're testing:
13
+ require 'lib/sinatras-hat'
14
+
15
+ # Tired of stupid mocks
16
+ require 'acts_as_fu/base'
17
+
18
+ def fixture(path)
19
+ File.join(File.dirname(__FILE__), 'fixtures', path)
20
+ end
21
+
22
+ Spec::Runner.configure do |config|
23
+ config.mock_with :rr
24
+ config.include Sinatra::Test
25
+ end
26
+
27
+ include ActsAsFu
28
+
29
+ build_model(:articles) do
30
+ string :name
31
+ string :description
32
+ timestamps
33
+
34
+ has_many :comments
35
+
36
+ def self.all
37
+ super(:order => 'created_at DESC')
38
+ end
39
+ end
40
+
41
+ build_model(:comments) do
42
+ string :name
43
+ integer :article_id
44
+
45
+ belongs_to :article
46
+ end
47
+
48
+ module Sinatra::Test
49
+ # Sets up a Sinatra::Base subclass defined with the block
50
+ # given. Used in setup or individual spec methods to establish
51
+ # the application.
52
+ def mock_app(base=Sinatra::Base, &block)
53
+ @app = Sinatra.new(base, &block)
54
+ end
55
+ end
56
+
57
+ def build_models!
58
+ Article.delete_all
59
+ Comment.delete_all
60
+ @article = Article.create! :name => "An article"
61
+ @non_child = @article.comments.create! :name => "Non child!"
62
+ @comment = @article.comments.create! :name => "The child comment"
63
+ end
64
+
65
+ def new_maker(klass=Article, *args, &block)
66
+ Sinatra::Hat::Maker.new(klass, *args, &block)
67
+ end
68
+
69
+ def fake_request(options={})
70
+ app = Sinatra.new
71
+ app.set :views, fixture("views")
72
+ request = app.new
73
+ stub(request).env.returns({ })
74
+ stub(request).params.returns(options)
75
+ stub(request).response.returns(Sinatra::Response.new)
76
+ stub(request).last_modified(anything)
77
+ stub(request).etag(anything)
78
+ request
79
+ end
80
+
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bradphelan-sinatras-hat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Pat Nakajima
8
+ - Brad Phelan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-03-27 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Easy peasy CRUD with sinatra
18
+ email: bradphelan@xtargets.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.md
26
+ files:
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.md
30
+ - Rakefile
31
+ - VERSION
32
+ - bradphelan-sinatras-hat.gemspec
33
+ - ci.rb
34
+ - example/app-with-auth.rb
35
+ - example/app-with-cache.rb
36
+ - example/app.rb
37
+ - example/lib/comment.rb
38
+ - example/lib/common.rb
39
+ - example/lib/post.rb
40
+ - example/simple-app.rb
41
+ - example/views/comments/index.erb
42
+ - example/views/comments/show.erb
43
+ - example/views/posts/index.erb
44
+ - example/views/posts/new.erb
45
+ - example/views/posts/show.erb
46
+ - features/authenticated.feature
47
+ - features/create.feature
48
+ - features/destroy.feature
49
+ - features/edit.feature
50
+ - features/formats.feature
51
+ - features/headers.feature
52
+ - features/index.feature
53
+ - features/layouts.feature
54
+ - features/nested.feature
55
+ - features/new.feature
56
+ - features/only.feature
57
+ - features/show.feature
58
+ - features/steps/authenticated_steps.rb
59
+ - features/steps/common_steps.rb
60
+ - features/steps/create_steps.rb
61
+ - features/steps/destroy_steps.rb
62
+ - features/steps/edit_steps.rb
63
+ - features/steps/format_steps.rb
64
+ - features/steps/header_steps.rb
65
+ - features/steps/index_steps.rb
66
+ - features/steps/nested_steps.rb
67
+ - features/steps/new_steps.rb
68
+ - features/steps/only_steps.rb
69
+ - features/steps/show_steps.rb
70
+ - features/steps/update_steps.rb
71
+ - features/support/env.rb
72
+ - features/support/views/comments/index.erb
73
+ - features/support/views/layout.erb
74
+ - features/support/views/people/edit.erb
75
+ - features/support/views/people/index.erb
76
+ - features/support/views/people/layout.erb
77
+ - features/support/views/people/new.erb
78
+ - features/support/views/people/show.erb
79
+ - features/update.feature
80
+ - lib/core_ext/array.rb
81
+ - lib/core_ext/hash.rb
82
+ - lib/core_ext/module.rb
83
+ - lib/core_ext/object.rb
84
+ - lib/sinatras-hat.rb
85
+ - lib/sinatras-hat/actions.rb
86
+ - lib/sinatras-hat/authentication.rb
87
+ - lib/sinatras-hat/extendor.rb
88
+ - lib/sinatras-hat/hash_mutator.rb
89
+ - lib/sinatras-hat/logger.rb
90
+ - lib/sinatras-hat/maker.rb
91
+ - lib/sinatras-hat/model.rb
92
+ - lib/sinatras-hat/resource.rb
93
+ - lib/sinatras-hat/responder.rb
94
+ - lib/sinatras-hat/response.rb
95
+ - lib/sinatras-hat/router.rb
96
+ - sinatras-hat.gemspec
97
+ - spec/actions/create_spec.rb
98
+ - spec/actions/destroy_spec.rb
99
+ - spec/actions/edit_spec.rb
100
+ - spec/actions/index_spec.rb
101
+ - spec/actions/new_spec.rb
102
+ - spec/actions/show_spec.rb
103
+ - spec/actions/update_spec.rb
104
+ - spec/extendor_spec.rb
105
+ - spec/fixtures/views/articles/edit.erb
106
+ - spec/fixtures/views/articles/index.erb
107
+ - spec/fixtures/views/articles/new.erb
108
+ - spec/fixtures/views/articles/show.erb
109
+ - spec/hash_mutator_spec.rb
110
+ - spec/maker_spec.rb
111
+ - spec/model_spec.rb
112
+ - spec/resource_spec.rb
113
+ - spec/responder_spec.rb
114
+ - spec/response_spec.rb
115
+ - spec/router_spec.rb
116
+ - spec/spec_helper.rb
117
+ has_rdoc: true
118
+ homepage: http://github.com/bradphelan/sinatras-hat
119
+ licenses: []
120
+
121
+ post_install_message:
122
+ rdoc_options:
123
+ - --charset=UTF-8
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: "0"
131
+ version:
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: "0"
137
+ version:
138
+ requirements: []
139
+
140
+ rubyforge_project:
141
+ rubygems_version: 1.3.5
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Easy peasy CRUD with sinatra
145
+ test_files:
146
+ - spec/actions/update_spec.rb
147
+ - spec/actions/new_spec.rb
148
+ - spec/actions/destroy_spec.rb
149
+ - spec/actions/show_spec.rb
150
+ - spec/actions/index_spec.rb
151
+ - spec/actions/edit_spec.rb
152
+ - spec/actions/create_spec.rb
153
+ - spec/extendor_spec.rb
154
+ - spec/resource_spec.rb
155
+ - spec/router_spec.rb
156
+ - spec/response_spec.rb
157
+ - spec/maker_spec.rb
158
+ - spec/model_spec.rb
159
+ - spec/responder_spec.rb
160
+ - spec/hash_mutator_spec.rb
161
+ - spec/spec_helper.rb