adeia 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/adeia/controller_methods.rb +14 -1
  3. data/lib/adeia/controller_resource.rb +1 -11
  4. data/lib/adeia/version.rb +1 -1
  5. data/spec/adeia/controller_methods_spec.rb +20 -1
  6. data/spec/features/redirect_back_or_spec.rb +32 -0
  7. data/spec/spec_helper.rb +1 -0
  8. data/spec/test_app/app/controllers/application_controller.rb +3 -0
  9. data/spec/test_app/app/controllers/articles_controller.rb +2 -3
  10. data/spec/test_app/app/controllers/comments_controller.rb +17 -0
  11. data/spec/test_app/app/controllers/pages_controller.rb +6 -0
  12. data/spec/test_app/app/controllers/sessions_controller.rb +2 -1
  13. data/spec/test_app/app/views/comments/new.html.erb +7 -0
  14. data/spec/test_app/app/views/pages/dashboard.html.erb +3 -0
  15. data/spec/test_app/config/application.rb +8 -0
  16. data/spec/test_app/config/routes.rb +5 -3
  17. data/spec/test_app/log/development.log +38 -0
  18. data/spec/test_app/log/test.log +4960 -0
  19. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
  20. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/9Fw_WnCC15QnXUQZ4eYTYLOBv20at5Z5gL-WJx_QsR4.cache +1 -0
  21. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/B52YLhAHmH3YmcdKcLjsgEEptVLsyy70mdivlMhWpwo.cache +0 -0
  22. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/DmmfrCpXtt74Hr6NO54lxyOCDv6klnDyBqeDFR7oDU8.cache +2 -0
  23. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/HAZ0ouG4bMq-xhCNwwW1_zHW_Xrv2dmE5rM7dNa0j6g.cache +1 -0
  24. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/HggfmBmV-rmvrvzJjqvjmDpwB2BTEQvh6krp0CcrI0U.cache +1 -0
  25. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/Jq-mhdojMq1WOqRn6VTdZrYcFFO9W88GGYnNBOCQ5fs.cache +1 -0
  26. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/M_KUTj7by27gLcyqVc2Uz9gtnUzDPo-cc9fw5-cB79M.cache +0 -0
  27. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +2 -0
  28. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/OqW-GtebPfTCjTjUqLDAjq59TfMSUnr0yXwjZqaH1ZY.cache +0 -0
  29. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/T_LATULiY1B-VdlBm543JXK-rMpAu3gMzKReRQXWhrs.cache +0 -0
  30. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/XHwHkIYxBrF9dqrLA7cltux80RMtB5uP7Thdx6p-J8s.cache +1 -0
  31. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/azllX2USS3pIkqwWCoUFuar1sOvmJG85PIO0jGpkjg8.cache +0 -0
  32. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/b9C_dpG2bL0B4PAVraluQxLpi87exSZXpMXfcQAdcTA.cache +1 -0
  33. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/fhCTdpSf2dKxcXFkBZy81w65UX0HZUzJnPqLF0eXe1c.cache +0 -0
  34. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/gj7jbeiYIdeoQeoh9p96r2xSlkLhFW4cqQeFKrzZJDc.cache +0 -0
  35. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +3 -0
  36. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/m36EDdApBppvyoX6m8cNCOm1eyt7pipkfASRya0sKqM.cache +1 -0
  37. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
  38. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/s0IFRa_BOyV2VUH7-DBuslcZPbZHrQxu1NvUN3I4O88.cache +1 -0
  39. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/w8wDbJ9a5U-rSRVsy6KWOVuPXk5LnbSkSpP4bMFj1q0.cache +1 -0
  40. data/spec/test_app/tmp/cache/assets/test/sprockets/v3.0/xjR7NEbTIbdnGQSxICRALdQtl8j_HoPOKkS5gwE2Jw0.cache +1 -0
  41. metadata +70 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f30f7fa1eed97db1750a87c086adbf844427bfc2
4
- data.tar.gz: 0f0805b6158786a85b585c9ef57142abe87944b7
3
+ metadata.gz: 8b88b34b9e3cf15bf8012237d1b0175bb9554ae8
4
+ data.tar.gz: b4cf556246fe43b51ca8f3e056106c849c372487
5
5
  SHA512:
6
- metadata.gz: b5f3dc2e53876486e29c471b40178989924d9fd7e2525a2ed63921a25806988569b17fb1085f33f0481217fa5e72c117a2791ccf68efe33b1459a3559a7ed632
7
- data.tar.gz: d259aa746873ad3d115fb9f29e62ff305c02f9ad724987438a699901462c85df6cf887920a87b3c7010ebe3cc5e2b8eadfeb92979e52ba69f9a4ad54b3301ef0
6
+ metadata.gz: 313c6b24c7633f1fc6af4771b3bd34d2295050bc98fa2512d991f9e03e462c5df9d5ab3c520eee4a6f6fab4ccac1718472738096464f86765641c0529e68822e
7
+ data.tar.gz: 929af587b2acab783df69cc9c9440e1860be98967a75899f8a23753110a334dabe8e729c42bc379658a45038ffac217563c4d892ab3a3cfd70d95bdc2752afba
@@ -40,7 +40,10 @@ module Adeia
40
40
  end
41
41
 
42
42
  def require_login!
43
- raise LoginRequired unless signed_in?
43
+ unless signed_in?
44
+ store_location
45
+ raise LoginRequired
46
+ end
44
47
  end
45
48
 
46
49
  def can?(action, element, resource=nil)
@@ -62,6 +65,16 @@ module Adeia
62
65
  cookies.delete(:return_to)
63
66
  end
64
67
 
68
+ # Store the current url in a cookie
69
+ #
70
+ # * *Args* :
71
+ #
72
+ # * *Returns* :
73
+ #
74
+ def store_location
75
+ cookies[:return_to] = request.fullpath if request.get?
76
+ end
77
+
65
78
  end
66
79
 
67
80
  end
@@ -33,7 +33,7 @@ module Adeia
33
33
  @token = args.fetch(:token, @controller.request.GET[:token])
34
34
  @resource = args[:resource]
35
35
  @user = @controller.current_user
36
- store_location
36
+ @controller.store_location
37
37
  end
38
38
 
39
39
  def load_resource
@@ -116,16 +116,6 @@ module Adeia
116
116
  end
117
117
  end
118
118
 
119
- # Store the current url in a cookie
120
- #
121
- # * *Args* :
122
- #
123
- # * *Returns* :
124
- #
125
- def store_location
126
- @controller.request.cookie_jar[:return_to] = @controller.request.fullpath
127
- end
128
-
129
119
  end
130
120
 
131
121
  end
data/lib/adeia/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Adeia
2
- VERSION = "0.10.0"
2
+ VERSION = "0.10.1"
3
3
  end
@@ -91,6 +91,25 @@ module Adeia
91
91
  end
92
92
  end
93
93
 
94
+ context "with a resource provided and a controller with a different name" do
95
+
96
+ controller do
97
+ def index
98
+ @article = Article.create(title: "Rspec tests", content: "Lorem ipsum", id: 100)
99
+ @can = can? :read, "letters", @article
100
+ render nothing: true
101
+ end
102
+ end
103
+
104
+ it "returns true when the user is authorized" do
105
+ sign_in_user
106
+ create(:permission, owner: @user, element_name: "letters", type_name: "on_entry", resource_id: 100, read_right: true)
107
+ get :index
108
+ expect(assigns(:can)).to be true
109
+ end
110
+
111
+ end
112
+
94
113
  context "with a resource and a namespace" do
95
114
 
96
115
  controller do
@@ -111,7 +130,7 @@ module Adeia
111
130
 
112
131
  end
113
132
 
114
- describe "#rights?" do
133
+ describe "#rights?" do
115
134
 
116
135
  controller do
117
136
  def index
@@ -0,0 +1,32 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe "#redirect_back_or", :type => :feature do
4
+
5
+ let(:user) { create(:user) }
6
+
7
+ it "stores the location when authorizing" do
8
+ create(:permission, element_name: "articles", read_right: true, owner: user)
9
+ visit "/articles" # redirect to login path
10
+ fill_in "Name", with: user.name
11
+ fill_in "Password", with: "12341"
12
+ click_button "Login"
13
+ expect(page.current_path).to eq "/articles"
14
+ end
15
+
16
+ it "stores the location when requiring login" do
17
+ visit "/comments" # redirect to login path
18
+ fill_in "Name", with: user.name
19
+ fill_in "Password", with: "12341"
20
+ click_button "Login"
21
+ expect(page.current_path).to eq "/comments"
22
+ end
23
+
24
+ it "doesn't store the location if the HTTP method isn't GET" do
25
+ visit "/comments/new"
26
+ click_button "Create a comment" # redirect to login path
27
+ fill_in "Name", with: user.name
28
+ fill_in "Password", with: "12341"
29
+ click_button "Login"
30
+ expect(page.current_path).to eq "/"
31
+ end
32
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'factory_girl_rails'
2
+ require 'capybara/rspec'
2
3
  require 'rspec/active_model/mocks'
3
4
 
4
5
  FactoryGirl.definition_file_paths = [ File.join(File.dirname(__FILE__), '../spec/factories') ]
@@ -2,4 +2,7 @@ class ApplicationController < ActionController::Base
2
2
  # Prevent CSRF attacks by raising an exception.
3
3
  # For APIs, you may want to use :null_session instead.
4
4
  protect_from_forgery with: :exception
5
+
6
+ rescue_from(Adeia::LoginRequired) { |e| redirect_to login_path }
7
+ rescue_from(Adeia::AccessDenied) { |e| redirect_to root_path }
5
8
  end
@@ -1,6 +1,6 @@
1
+ # Used to test #authorize!, #load_and_authorize & load_and_authorize!
1
2
  class ArticlesController < ApplicationController
2
- load_and_authorize only: [:edit]
3
- require_login only: [:update]
3
+ load_and_authorize except: [:index, :show, :new]
4
4
 
5
5
  def index
6
6
  authorize_and_load_records!
@@ -19,7 +19,6 @@ class ArticlesController < ApplicationController
19
19
  end
20
20
 
21
21
  def create
22
- require_login!
23
22
  @article = Article.new(article_params)
24
23
  @article.user = current_user
25
24
  if @article.save
@@ -0,0 +1,17 @@
1
+ # Used to test #store_location & #redirect_back_or
2
+ class CommentsController < ApplicationController
3
+
4
+ def index
5
+ require_login!
6
+ render text: "All the comments"
7
+ end
8
+
9
+ def new
10
+ end
11
+
12
+ def create
13
+ require_login!
14
+ render text: "Comment created"
15
+ end
16
+
17
+ end
@@ -0,0 +1,6 @@
1
+ class PagesController < ApplicationController
2
+
3
+ def dashboard
4
+ end
5
+
6
+ end
@@ -7,7 +7,7 @@ class SessionsController < ApplicationController
7
7
  @user = User.find_by_name(params[:session][:name])
8
8
  if @user && @user.authenticate(params[:session][:password])
9
9
  sign_in(@user, permanent: params[:session][:remember_me] == "1")
10
- redirect_to articles_path, success: "Signed in"
10
+ redirect_back_or root_path, success: "Signed in"
11
11
  else
12
12
  flash.now[:error] = "Incorrect user/password"
13
13
  render 'new'
@@ -15,6 +15,7 @@ class SessionsController < ApplicationController
15
15
  end
16
16
 
17
17
  def destroy
18
+ require_login!
18
19
  sign_out
19
20
  redirect_to root_path, success: "Signed out"
20
21
  end
@@ -0,0 +1,7 @@
1
+ <h1>New comment</h1>
2
+
3
+ <%= form_tag comments_path do %>
4
+
5
+ <%= submit_tag "Create a comment" %>
6
+
7
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <h1>Dashboard</h1>
2
+ <h2>All your last activities here ! </h2>
3
+ <p>You're not very active those days...</p>
@@ -21,6 +21,14 @@ module Dummy
21
21
 
22
22
  # Do not swallow errors in after_commit/after_rollback callbacks.
23
23
  config.active_record.raise_in_transactional_callbacks = true
24
+
25
+ config.generators do |g|
26
+ g.orm :active_record
27
+ g.template_engine :erb
28
+ g.stylesheets false
29
+ g.javascripts false
30
+ g.helper false
31
+ end
24
32
  end
25
33
  end
26
34
 
@@ -1,11 +1,13 @@
1
1
  Rails.application.routes.draw do
2
2
  mount Adeia::Engine => "/adeia"
3
3
 
4
- root "articles#index"
4
+ root "pages#dashboard"
5
+ get "dashboard", to: "pages#dashboard"
5
6
 
6
- get 'login', to: "sessions#new"
7
- get 'logout', to: 'sessions#destroy'
7
+ get "login", to: "sessions#new"
8
+ get "logout", to: "sessions#destroy"
8
9
  resources :sessions, only: [:create]
9
10
 
10
11
  resources :articles
12
+ resources :comments
11
13
  end
@@ -52310,3 +52310,41 @@ Migrating to CreateArticles (20151012185726)
52310
52310
  FROM sqlite_temp_master
52311
52311
  WHERE name='index_articles_on_user_id' AND type='index'
52312
52312
 
52313
+
52314
+
52315
+ Started GET "/" for ::1 at 2015-11-16 21:10:23 +0100
52316
+ ActiveRecord::SchemaMigration Load (0.8ms) SELECT "schema_migrations".* FROM "schema_migrations"
52317
+ Processing by ArticlesController#dashboard as HTML
52318
+ Rendered articles/dashboard.html.erb within layouts/application (2.3ms)
52319
+ User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = ? LIMIT 1 [["remember_token", "24c43IkYlTqZjPq3y4veLw"]]
52320
+ Completed 200 OK in 263ms (Views: 261.5ms | ActiveRecord: 1.0ms)
52321
+
52322
+
52323
+ Started GET "/assets/scaffold.self-83b741db49389dc7cfdf85bf7537a0219cce48e085c4116afc83d55c9af47c78.css?body=1" for ::1 at 2015-11-16 21:10:23 +0100
52324
+
52325
+
52326
+ Started GET "/assets/application.self-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css?body=1" for ::1 at 2015-11-16 21:10:23 +0100
52327
+
52328
+
52329
+ Started GET "/assets/application.self-8f06a73c35179188914ab50e057157639fce1401c1cdca640ac9cec33746fc5b.js?body=1" for ::1 at 2015-11-16 21:10:23 +0100
52330
+
52331
+
52332
+ Started GET "/login" for ::1 at 2015-11-16 21:10:27 +0100
52333
+ Processing by SessionsController#new as HTML
52334
+ Rendered sessions/new.html.erb within layouts/application (32.2ms)
52335
+ User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = ? LIMIT 1 [["remember_token", "24c43IkYlTqZjPq3y4veLw"]]
52336
+ Completed 200 OK in 55ms (Views: 54.6ms | ActiveRecord: 0.1ms)
52337
+
52338
+
52339
+ Started GET "/logout" for ::1 at 2015-11-16 21:10:29 +0100
52340
+ Processing by SessionsController#destroy as HTML
52341
+ User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = ? LIMIT 1 [["remember_token", "24c43IkYlTqZjPq3y4veLw"]]
52342
+ Redirected to http://localhost:3000/login
52343
+ Completed 302 Found in 2ms (ActiveRecord: 0.2ms)
52344
+
52345
+
52346
+ Started GET "/login" for ::1 at 2015-11-16 21:10:29 +0100
52347
+ Processing by SessionsController#new as HTML
52348
+ Rendered sessions/new.html.erb within layouts/application (1.6ms)
52349
+ User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = ? LIMIT 1 [["remember_token", "24c43IkYlTqZjPq3y4veLw"]]
52350
+ Completed 200 OK in 27ms (Views: 26.4ms | ActiveRecord: 0.1ms)