releaf-core 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c757f3eee233bfaf9a11014357ba53e9f0248277
4
- data.tar.gz: 3a3d4269cfd11385c2dbf5ccc1ca16efc01bf684
3
+ metadata.gz: a5ef038649618995ad1209f4a69a9f07dcc563e0
4
+ data.tar.gz: 1c0d5ffc66e4b4245775fcc2b83d5cabed419384
5
5
  SHA512:
6
- metadata.gz: 31efbd050fbb7bda871a605e2e1d4d6b9ab3c8bb838f3c2db914d901d87c7b1d38653043b92058c73e193c316dfefd5fc168828515c7f4e8b7a27335b3a27d82
7
- data.tar.gz: 1cb0c9c7500a4b534b9de135b7ff813d122b9af8fcc1ddbdf42f910947f8cebdc33c02b6f175df7b9c0c43fcb95d8c717b19bead95ef63d2ece36c2d034869c6
6
+ metadata.gz: 71a59ef4a453d8c06295572feb9937184cf899f87f6ad362e61063873ced9632dd5790dd9c2d5f29845c98262ee7463e0fb661e88352b3777867451531399fee
7
+ data.tar.gz: 7e0c50a17a024c48b342e8781087d9fee73cdfee8e6e68f2cba0b97684e1e6ddeb65e0614ea34e72df5a484b87f8b8e98598627f023448a03f15baaa5e5cb697
@@ -14,10 +14,10 @@ class Releaf::ActionController < ActionController::Base
14
14
  include Releaf::ActionController::RichtextAttachments
15
15
  include Releaf::ActionController::Views
16
16
  include Releaf::ActionController::Layout
17
+ include Releaf::ActionController::Exceptions
17
18
  include Releaf::Responders
18
19
 
19
20
  helper_method :controller_scope_name, :page_title
20
- rescue_from Releaf::AccessDenied, with: :access_denied
21
21
 
22
22
  respond_to :html
23
23
  respond_to :json, only: [:create, :update]
@@ -138,10 +138,6 @@ class Releaf::ActionController < ActionController::Base
138
138
  params[:after_save] == "create_another" && feature_available?(:create_another)
139
139
  end
140
140
 
141
- def access_denied
142
- respond_with(nil, responder: action_responder(:access_denied))
143
- end
144
-
145
141
  # Check if @resource has existing restrict relation and it can be deleted
146
142
  #
147
143
  # @return boolean true or false
@@ -0,0 +1,16 @@
1
+ module Releaf::ActionController::Exceptions
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ rescue_from Releaf::AccessDenied, with: :access_denied
6
+ rescue_from Releaf::RecordNotFound, with: :page_not_found
7
+ end
8
+
9
+ def page_not_found
10
+ respond_with(nil, responder: action_responder(:page_not_found))
11
+ end
12
+
13
+ def access_denied
14
+ respond_with(nil, responder: action_responder(:access_denied))
15
+ end
16
+ end
@@ -37,7 +37,11 @@ module Releaf::ActionController::Resources
37
37
  end
38
38
 
39
39
  def load_resource
40
- @resource = resource_class.find(params[:id])
40
+ begin
41
+ @resource = resource_class.find(params[:id])
42
+ rescue ActiveRecord::RecordNotFound
43
+ raise Releaf::RecordNotFound
44
+ end
41
45
  end
42
46
 
43
47
  # Returns true if @resource is assigned (even if it's nil)
@@ -5,6 +5,3 @@
5
5
  .body
6
6
  - if defined? description
7
7
  %div.description= description
8
- %a.return{href: releaf_root_path }
9
- = t("Go home")
10
- %i.fa.fa-chevron-right
@@ -1,2 +1 @@
1
- = render 'releaf/error_pages/error', message: t('Page not found', scope: controller_scope_name), description: t('Something went wrong.', scope: controller_scope_name)
2
-
1
+ = render 'releaf/error_pages/error', message: t('Page not found', scope: controller_scope_name), description: t('You may have mistyped the address or the page may have moved.', scope: controller_scope_name)
@@ -2,4 +2,5 @@ module Releaf
2
2
  class Error < StandardError; end
3
3
  class AccessDenied < Error; end
4
4
  class FeatureDisabled < Error; end
5
+ class RecordNotFound < Error; end
5
6
  end
@@ -37,7 +37,7 @@ module Releaf::RouteMapper
37
37
  end
38
38
 
39
39
  namespace :releaf, path: nil do
40
- get '/*path' => 'errors#page_not_found'
40
+ get '/*path' => 'root#page_not_found'
41
41
  end
42
42
  end
43
43
  end
@@ -4,11 +4,24 @@ describe "Errors feature" do
4
4
  auth_as_user
5
5
  end
6
6
 
7
- it "returns 404 status code and generic error page for nonexistent rotues" do
7
+ it "returns 404 status code and generic error page for nonexistent records" do
8
+ visit "/admin/users/712323/edit"
9
+
10
+ expect(page.status_code).to eq(404)
11
+ within "main" do
12
+ expect(page).to have_text("Page not found")
13
+ expect(page).to have_text("You may have mistyped the address or the page may have moved")
14
+ end
15
+ end
16
+
17
+ it "returns 404 status code and generic error page for nonexistent routes" do
8
18
  visit(releaf_root_path + "/asdassd")
9
19
 
10
20
  expect(page.status_code).to eq(404)
11
- expect(page.body).to match(/not found/)
21
+ within "main" do
22
+ expect(page).to have_text("Page not found")
23
+ expect(page).to have_text("You may have mistyped the address or the page may have moved")
24
+ end
12
25
  end
13
26
 
14
27
  it "returns 403 status code and generic error page for disabled feature" do
@@ -17,7 +30,9 @@ describe "Errors feature" do
17
30
  visit releaf_permissions_roles_path
18
31
 
19
32
  expect(page.status_code).to eq(403)
20
- expect(page.body).to match(/edit feature disabled for roles/i)
33
+ within "main" do
34
+ expect(page).to have_text("edit feature disabled for roles")
35
+ end
21
36
  end
22
37
 
23
38
  it "returns 403 status code and generic error page for restricted content" do
@@ -25,6 +40,8 @@ describe "Errors feature" do
25
40
  visit releaf_permissions_roles_path
26
41
 
27
42
  expect(page.status_code).to eq(403)
28
- expect(page.body).to match(/you are not authorized to access roles/i)
43
+ within "main" do
44
+ expect(page).to have_text("You are not authorized to access roles")
45
+ end
29
46
  end
30
47
  end
@@ -111,7 +111,7 @@ describe Releaf::RouteMapper do
111
111
 
112
112
  it "route to page not found" do
113
113
  expect(get: "/admin/books/1/toolbox")
114
- .to route_to(controller: "releaf/errors", action: "page_not_found", path: "books/1/toolbox")
114
+ .to route_to(controller: "releaf/root", action: "page_not_found", path: "books/1/toolbox")
115
115
  end
116
116
  end
117
117
 
@@ -126,7 +126,7 @@ describe Releaf::RouteMapper do
126
126
 
127
127
  it "route to page not found" do
128
128
  expect(get: "/admin/books/1/toolbox")
129
- .to route_to(controller: "releaf/errors", action: "page_not_found", path: "books/1/toolbox")
129
+ .to route_to(controller: "releaf/root", action: "page_not_found", path: "books/1/toolbox")
130
130
  end
131
131
  end
132
132
 
@@ -141,7 +141,7 @@ describe Releaf::RouteMapper do
141
141
 
142
142
  it "does not mount destroy confirm route" do
143
143
  expect(get: "/admin/books/1/confirm_destroy")
144
- .to route_to(controller: "releaf/errors", action: "page_not_found", path: "books/1/confirm_destroy")
144
+ .to route_to(controller: "releaf/root", action: "page_not_found", path: "books/1/confirm_destroy")
145
145
  end
146
146
  end
147
147
 
@@ -156,7 +156,7 @@ describe Releaf::RouteMapper do
156
156
 
157
157
  it "does not mount destroy confirm route" do
158
158
  expect(get: "/admin/books/1/confirm_destroy")
159
- .to route_to(controller: "releaf/errors", action: "page_not_found", path: "books/1/confirm_destroy")
159
+ .to route_to(controller: "releaf/root", action: "page_not_found", path: "books/1/confirm_destroy")
160
160
  end
161
161
  end
162
162
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: releaf-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CubeSystems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-22 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -386,7 +386,6 @@ files:
386
386
  - app/builders/releaf/settings/form_builder.rb
387
387
  - app/builders/releaf/settings/table_builder.rb
388
388
  - app/controllers/releaf/action_controller.rb
389
- - app/controllers/releaf/errors_controller.rb
390
389
  - app/controllers/releaf/root_controller.rb
391
390
  - app/controllers/releaf/settings_controller.rb
392
391
  - app/helpers/releaf/application_helper.rb
@@ -394,6 +393,7 @@ files:
394
393
  - app/lib/releaf/action_controller/ajax.rb
395
394
  - app/lib/releaf/action_controller/breadcrumbs.rb
396
395
  - app/lib/releaf/action_controller/builders.rb
396
+ - app/lib/releaf/action_controller/exceptions.rb
397
397
  - app/lib/releaf/action_controller/features.rb
398
398
  - app/lib/releaf/action_controller/layout.rb
399
399
  - app/lib/releaf/action_controller/notifications.rb
@@ -1,5 +0,0 @@
1
- class Releaf::ErrorsController < Releaf::ActionController
2
- def page_not_found
3
- respond_with(nil, responder: action_responder(:page_not_found))
4
- end
5
- end