walruz-rails 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +31 -0
  3. data/Rakefile +49 -0
  4. data/VERSION.yml +4 -0
  5. data/examples/rails/README +243 -0
  6. data/examples/rails/Rakefile +10 -0
  7. data/examples/rails/app/controllers/application_controller.rb +10 -0
  8. data/examples/rails/app/helpers/application_helper.rb +3 -0
  9. data/examples/rails/app/models/beatle.rb +26 -0
  10. data/examples/rails/app/models/colaboration.rb +6 -0
  11. data/examples/rails/app/models/song.rb +10 -0
  12. data/examples/rails/config/boot.rb +110 -0
  13. data/examples/rails/config/database.yml +22 -0
  14. data/examples/rails/config/environment.rb +43 -0
  15. data/examples/rails/config/environments/development.rb +17 -0
  16. data/examples/rails/config/environments/production.rb +28 -0
  17. data/examples/rails/config/environments/test.rb +28 -0
  18. data/examples/rails/config/initializers/backtrace_silencers.rb +7 -0
  19. data/examples/rails/config/initializers/inflections.rb +10 -0
  20. data/examples/rails/config/initializers/mime_types.rb +5 -0
  21. data/examples/rails/config/initializers/new_rails_defaults.rb +19 -0
  22. data/examples/rails/config/initializers/session_store.rb +15 -0
  23. data/examples/rails/config/initializers/walruz_initializer.rb +23 -0
  24. data/examples/rails/config/locales/en.yml +5 -0
  25. data/examples/rails/config/routes.rb +43 -0
  26. data/examples/rails/db/development.sqlite3 +0 -0
  27. data/examples/rails/db/migrate/20090604201506_create_beatles.rb +12 -0
  28. data/examples/rails/db/migrate/20090604201512_create_songs.rb +15 -0
  29. data/examples/rails/db/migrate/20090604201527_create_colaborations.rb +17 -0
  30. data/examples/rails/db/schema.rb +44 -0
  31. data/examples/rails/db/test.sqlite3 +0 -0
  32. data/examples/rails/doc/README_FOR_APP +2 -0
  33. data/examples/rails/lib/tasks/rspec.rake +165 -0
  34. data/examples/rails/lib/walruz/policies/author_policy.rb +9 -0
  35. data/examples/rails/lib/walruz/policies/colaboration_policy.rb +22 -0
  36. data/examples/rails/lib/walruz/policies.rb +33 -0
  37. data/examples/rails/log/development.log +1347 -0
  38. data/examples/rails/log/production.log +0 -0
  39. data/examples/rails/log/server.log +0 -0
  40. data/examples/rails/log/test.log +354 -0
  41. data/examples/rails/public/404.html +30 -0
  42. data/examples/rails/public/422.html +30 -0
  43. data/examples/rails/public/500.html +30 -0
  44. data/examples/rails/public/favicon.ico +0 -0
  45. data/examples/rails/public/images/rails.png +0 -0
  46. data/examples/rails/public/index.html +275 -0
  47. data/examples/rails/public/javascripts/application.js +2 -0
  48. data/examples/rails/public/javascripts/controls.js +963 -0
  49. data/examples/rails/public/javascripts/dragdrop.js +973 -0
  50. data/examples/rails/public/javascripts/effects.js +1128 -0
  51. data/examples/rails/public/javascripts/prototype.js +4320 -0
  52. data/examples/rails/public/robots.txt +5 -0
  53. data/examples/rails/public/unathorized.html +9 -0
  54. data/examples/rails/script/about +4 -0
  55. data/examples/rails/script/autospec +6 -0
  56. data/examples/rails/script/console +3 -0
  57. data/examples/rails/script/dbconsole +3 -0
  58. data/examples/rails/script/destroy +3 -0
  59. data/examples/rails/script/generate +3 -0
  60. data/examples/rails/script/performance/benchmarker +3 -0
  61. data/examples/rails/script/performance/profiler +3 -0
  62. data/examples/rails/script/plugin +3 -0
  63. data/examples/rails/script/runner +3 -0
  64. data/examples/rails/script/server +3 -0
  65. data/examples/rails/script/spec +10 -0
  66. data/examples/rails/script/spec_server +9 -0
  67. data/examples/rails/spec/fixtures/beatles.yml +7 -0
  68. data/examples/rails/spec/fixtures/colaborations.yml +7 -0
  69. data/examples/rails/spec/fixtures/songs.yml +7 -0
  70. data/examples/rails/spec/models/beatle_spec.rb +47 -0
  71. data/examples/rails/spec/models/colaboration_spec.rb +4 -0
  72. data/examples/rails/spec/models/song_spec.rb +4 -0
  73. data/examples/rails/spec/rcov.opts +2 -0
  74. data/examples/rails/spec/spec.opts +4 -0
  75. data/examples/rails/spec/spec_helper.rb +48 -0
  76. data/examples/rails/test/performance/browsing_test.rb +9 -0
  77. data/examples/rails/test/test_helper.rb +38 -0
  78. data/lib/walruz/controller_mixin.rb +107 -0
  79. data/lib/walruz_rails.rb +10 -0
  80. data/spec/controller_mixin_spec.rb +92 -0
  81. data/spec/scenario.rb +247 -0
  82. data/spec/spec_helper.rb +29 -0
  83. metadata +169 -0
data/spec/scenario.rb ADDED
@@ -0,0 +1,247 @@
1
+ class Beatle
2
+ include Walruz::Actor
3
+ include Walruz::Subject
4
+
5
+ attr_reader :name
6
+ attr_accessor :songs
7
+ attr_accessor :colaborations
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ @songs = []
12
+ @colaborations = []
13
+ end
14
+
15
+ def sing_the_song(song)
16
+ response = can!(:sing, song)
17
+ case response[:owner]
18
+ when Colaboration
19
+ authors = response[:owner].authors.dup
20
+ authors.delete(self)
21
+ authors.map! { |author| author.name }
22
+ "I need %s to play this song properly" % authors.join(', ')
23
+ when Beatle
24
+ "I just need myself, Let's Rock! \\m/"
25
+ end
26
+ end
27
+
28
+ def sing_with_john(song)
29
+ can!(:sing_with_john, song)
30
+ "Ok John, Let's Play '%s'" % song.name
31
+ end
32
+
33
+
34
+ JOHN = self.new("John")
35
+ PAUL = self.new("Paul")
36
+ RINGO = self.new("Ringo")
37
+ GEORGE = self.new("George")
38
+ end
39
+
40
+ class Colaboration
41
+
42
+ attr_accessor :authors
43
+ attr_accessor :songs
44
+
45
+ def initialize(*authors)
46
+ authors.each do |author|
47
+ author.colaborations << self
48
+ end
49
+ @authors = authors
50
+ @songs = []
51
+ end
52
+
53
+ JOHN_PAUL = self.new(Beatle::JOHN, Beatle::PAUL)
54
+ JOHN_PAUL_GEORGE = self.new(Beatle::JOHN, Beatle::PAUL, Beatle::GEORGE)
55
+ JOHN_GEORGE = self.new(Beatle::PAUL, Beatle::GEORGE)
56
+ end
57
+
58
+ class SubjectIsActorPolicy < Walruz::Policy
59
+
60
+ def authorized?(actor, subject)
61
+ actor == subject
62
+ end
63
+
64
+ end
65
+
66
+ # class AuthorPolicy < Walruz::Policy
67
+ #
68
+ # def authorized?(beatle, song)
69
+ # if song.author == beatle
70
+ # [true, { :owner => beatle }]
71
+ # else
72
+ # false
73
+ # end
74
+ # end
75
+ #
76
+ # end
77
+
78
+ AuthorPolicy = Walruz::Utils.lift_subject(:author, SubjectIsActorPolicy) do |authorized, params, actor, subject|
79
+ params.merge!(:owner => actor) if authorized
80
+ end
81
+
82
+ class AuthorInColaborationPolicy < Walruz::Policy
83
+
84
+ def authorized?(beatle, song)
85
+ return false unless song.colaboration
86
+ if song.colaboration.authors.include?(beatle)
87
+ [true, { :owner => song.colaboration }]
88
+ else
89
+ false
90
+ end
91
+ end
92
+
93
+ end
94
+
95
+ class ColaboratingWithJohnPolicy < Walruz::Policy
96
+ depends_on AuthorInColaborationPolicy
97
+
98
+ def authorized?(beatle, song)
99
+ params[:owner].authors.include?(Beatle::JOHN)
100
+ end
101
+
102
+ end
103
+
104
+ class Song
105
+ include Walruz::Subject
106
+ extend Walruz::Utils
107
+
108
+ check_authorizations :sing => orP(AuthorPolicy, AuthorInColaborationPolicy),
109
+ :sell => andP(AuthorPolicy, notP(AuthorInColaborationPolicy)),
110
+ :sing_with_john => ColaboratingWithJohnPolicy
111
+ attr_accessor :name
112
+ attr_accessor :colaboration
113
+ attr_accessor :author
114
+
115
+ def initialize(name, owner)
116
+ @name = name
117
+ case owner
118
+ when Colaboration
119
+ @colaboration = owner
120
+ when Beatle
121
+ @author = owner
122
+ end
123
+ owner.songs << self
124
+ end
125
+
126
+ A_DAY_IN_LIFE = self.new("A Day In Life", Colaboration::JOHN_PAUL)
127
+ YELLOW_SUBMARINE = self.new("Yellow Submarine", Colaboration::JOHN_PAUL)
128
+ TAXMAN = self.new("Taxman", Colaboration::JOHN_GEORGE)
129
+ YESTERDAY = self.new("Yesterday", Beatle::PAUL)
130
+ ALL_YOU_NEED_IS_LOVE = self.new("All You Need Is Love", Beatle::JOHN)
131
+ BLUE_JAY_WAY = self.new("Blue Jay Way", Beatle::GEORGE)
132
+ end
133
+
134
+
135
+ class Application < ActionController::Base
136
+ include Walruz::ControllerMixin
137
+
138
+ rescue_from Walruz::NotAuthorized, :with => :unauthorized
139
+
140
+ protected
141
+
142
+ def unauthorized
143
+ render :text => 'Unauthorized'
144
+ end
145
+
146
+ end
147
+
148
+ class SongsController < Application
149
+ before_filter :assign_song
150
+ before_filter check_authorization!(:sing, :song), :only => :sings
151
+
152
+ def sings
153
+ text_to_render = '%s is singing %s' % [current_user.name,
154
+ @song.name]
155
+ render :text => text_to_render
156
+ end
157
+
158
+ protected
159
+
160
+ def assign_song
161
+ @song = if params[:song] == 'Yesterday'
162
+ Song::YESTERDAY
163
+ else
164
+ nil
165
+ end
166
+ end
167
+
168
+ end
169
+
170
+ ##### Scenario for testing purposes of before_check_crud_authorizations_of
171
+
172
+ class TruePolicy < Walruz::Policy
173
+
174
+ def authorized?(actor, subject)
175
+ true
176
+ end
177
+
178
+ end
179
+
180
+ class FalsePolicy < Walruz::Policy
181
+
182
+ def authorized?(actor, subject)
183
+ false
184
+ end
185
+
186
+ end
187
+
188
+ class Post
189
+ include Walruz::Subject
190
+ check_authorizations :create => TruePolicy,
191
+ :read => TruePolicy,
192
+ :update => TruePolicy,
193
+ :destroy => FalsePolicy
194
+ end
195
+
196
+ class PostsController < Application
197
+
198
+ before_filter :get_post
199
+ before_check_crud_authorizations_on :post
200
+
201
+ ['show', 'new', 'create', 'edit', 'update', 'destroy'].each do |action|
202
+ class_eval <<-CODE_RUBY
203
+ def #{action}
204
+ render :text => "I'm on action #{action}'"
205
+ end
206
+ CODE_RUBY
207
+ end
208
+
209
+ def get_post
210
+ @post = Post.new
211
+ end
212
+
213
+ def current_user
214
+ Beatle::RINGO
215
+ end
216
+
217
+
218
+ end
219
+
220
+ class OtherPostsController < Application
221
+
222
+ before_filter :get_post
223
+ before_check_crud_authorizations_on :post
224
+
225
+ ['show', 'new', 'create'].each do |action|
226
+ class_eval <<-CODE_RUBY
227
+ def #{action}
228
+ render :text => "I'm on action #{action}'"
229
+ end
230
+ CODE_RUBY
231
+ end
232
+
233
+ def get_post
234
+ @post = Post.new
235
+ end
236
+
237
+ def current_user
238
+ Beatle::RINGO
239
+ end
240
+
241
+
242
+ end
243
+
244
+ ##### End of scenario
245
+
246
+ ActionController::Routing::Routes.reload!
247
+ ActionController::Routing::Routes.draw { |map| map.connect '/:controller/:action' }
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ begin
5
+ require 'rubygems'
6
+ require 'action_controller'
7
+ require 'action_controller/test_process'
8
+ require 'active_record'
9
+ require 'initializer'
10
+ require 'spec'
11
+ require 'walruz'
12
+
13
+ RAILS_ROOT = File.dirname(__FILE__) + '/../tmp'
14
+ module Rails
15
+
16
+ def self.configuration
17
+ Rails::Configuration.new
18
+ end
19
+ end
20
+
21
+ require 'walruz_rails'
22
+ require 'scenario'
23
+
24
+ Spec::Runner.configure do |config|
25
+ config.include(ActionController::TestProcess)
26
+ end
27
+
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: walruz-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Roman Gonzalez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-01 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: roman@noomii.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION.yml
30
+ - examples/rails/README
31
+ - examples/rails/Rakefile
32
+ - examples/rails/app/controllers/application_controller.rb
33
+ - examples/rails/app/helpers/application_helper.rb
34
+ - examples/rails/app/models/beatle.rb
35
+ - examples/rails/app/models/colaboration.rb
36
+ - examples/rails/app/models/song.rb
37
+ - examples/rails/config/boot.rb
38
+ - examples/rails/config/database.yml
39
+ - examples/rails/config/environment.rb
40
+ - examples/rails/config/environments/development.rb
41
+ - examples/rails/config/environments/production.rb
42
+ - examples/rails/config/environments/test.rb
43
+ - examples/rails/config/initializers/backtrace_silencers.rb
44
+ - examples/rails/config/initializers/inflections.rb
45
+ - examples/rails/config/initializers/mime_types.rb
46
+ - examples/rails/config/initializers/new_rails_defaults.rb
47
+ - examples/rails/config/initializers/session_store.rb
48
+ - examples/rails/config/initializers/walruz_initializer.rb
49
+ - examples/rails/config/locales/en.yml
50
+ - examples/rails/config/routes.rb
51
+ - examples/rails/db/development.sqlite3
52
+ - examples/rails/db/migrate/20090604201506_create_beatles.rb
53
+ - examples/rails/db/migrate/20090604201512_create_songs.rb
54
+ - examples/rails/db/migrate/20090604201527_create_colaborations.rb
55
+ - examples/rails/db/schema.rb
56
+ - examples/rails/db/test.sqlite3
57
+ - examples/rails/doc/README_FOR_APP
58
+ - examples/rails/lib/tasks/rspec.rake
59
+ - examples/rails/lib/walruz/policies.rb
60
+ - examples/rails/lib/walruz/policies/author_policy.rb
61
+ - examples/rails/lib/walruz/policies/colaboration_policy.rb
62
+ - examples/rails/log/development.log
63
+ - examples/rails/log/production.log
64
+ - examples/rails/log/server.log
65
+ - examples/rails/log/test.log
66
+ - examples/rails/public/404.html
67
+ - examples/rails/public/422.html
68
+ - examples/rails/public/500.html
69
+ - examples/rails/public/favicon.ico
70
+ - examples/rails/public/images/rails.png
71
+ - examples/rails/public/index.html
72
+ - examples/rails/public/javascripts/application.js
73
+ - examples/rails/public/javascripts/controls.js
74
+ - examples/rails/public/javascripts/dragdrop.js
75
+ - examples/rails/public/javascripts/effects.js
76
+ - examples/rails/public/javascripts/prototype.js
77
+ - examples/rails/public/robots.txt
78
+ - examples/rails/public/unathorized.html
79
+ - examples/rails/script/about
80
+ - examples/rails/script/autospec
81
+ - examples/rails/script/console
82
+ - examples/rails/script/dbconsole
83
+ - examples/rails/script/destroy
84
+ - examples/rails/script/generate
85
+ - examples/rails/script/performance/benchmarker
86
+ - examples/rails/script/performance/profiler
87
+ - examples/rails/script/plugin
88
+ - examples/rails/script/runner
89
+ - examples/rails/script/server
90
+ - examples/rails/script/spec
91
+ - examples/rails/script/spec_server
92
+ - examples/rails/spec/fixtures/beatles.yml
93
+ - examples/rails/spec/fixtures/colaborations.yml
94
+ - examples/rails/spec/fixtures/songs.yml
95
+ - examples/rails/spec/models/beatle_spec.rb
96
+ - examples/rails/spec/models/colaboration_spec.rb
97
+ - examples/rails/spec/models/song_spec.rb
98
+ - examples/rails/spec/rcov.opts
99
+ - examples/rails/spec/spec.opts
100
+ - examples/rails/spec/spec_helper.rb
101
+ - examples/rails/test/performance/browsing_test.rb
102
+ - examples/rails/test/test_helper.rb
103
+ - lib/walruz/controller_mixin.rb
104
+ - lib/walruz_rails.rb
105
+ - spec/controller_mixin_spec.rb
106
+ - spec/scenario.rb
107
+ - spec/spec_helper.rb
108
+ has_rdoc: true
109
+ homepage: http://github.com/noomii/walruz-rails
110
+ licenses: []
111
+
112
+ post_install_message:
113
+ rdoc_options:
114
+ - --charset=UTF-8
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: "0"
122
+ version:
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: "0"
128
+ version:
129
+ requirements: []
130
+
131
+ rubyforge_project: walruz-rails
132
+ rubygems_version: 1.3.3
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Gem for easy integration between walruz andthe Ruby on Rails framework
136
+ test_files:
137
+ - spec/controller_mixin_spec.rb
138
+ - spec/scenario.rb
139
+ - spec/spec_helper.rb
140
+ - examples/rails/app/controllers/application_controller.rb
141
+ - examples/rails/app/helpers/application_helper.rb
142
+ - examples/rails/app/models/beatle.rb
143
+ - examples/rails/app/models/colaboration.rb
144
+ - examples/rails/app/models/song.rb
145
+ - examples/rails/config/boot.rb
146
+ - examples/rails/config/environment.rb
147
+ - examples/rails/config/environments/development.rb
148
+ - examples/rails/config/environments/production.rb
149
+ - examples/rails/config/environments/test.rb
150
+ - examples/rails/config/initializers/backtrace_silencers.rb
151
+ - examples/rails/config/initializers/inflections.rb
152
+ - examples/rails/config/initializers/mime_types.rb
153
+ - examples/rails/config/initializers/new_rails_defaults.rb
154
+ - examples/rails/config/initializers/session_store.rb
155
+ - examples/rails/config/initializers/walruz_initializer.rb
156
+ - examples/rails/config/routes.rb
157
+ - examples/rails/db/migrate/20090604201506_create_beatles.rb
158
+ - examples/rails/db/migrate/20090604201512_create_songs.rb
159
+ - examples/rails/db/migrate/20090604201527_create_colaborations.rb
160
+ - examples/rails/db/schema.rb
161
+ - examples/rails/lib/walruz/policies/author_policy.rb
162
+ - examples/rails/lib/walruz/policies/colaboration_policy.rb
163
+ - examples/rails/lib/walruz/policies.rb
164
+ - examples/rails/spec/models/beatle_spec.rb
165
+ - examples/rails/spec/models/colaboration_spec.rb
166
+ - examples/rails/spec/models/song_spec.rb
167
+ - examples/rails/spec/spec_helper.rb
168
+ - examples/rails/test/performance/browsing_test.rb
169
+ - examples/rails/test/test_helper.rb