Permalink
Browse files

allow some actions to be skipped

  • Loading branch information...
1 parent 8076d36 commit fb5bf06a3aae2e46e2b9f450e6725f79ebe57b15 @subelsky committed May 19, 2012
Showing with 15 additions and 15 deletions.
  1. +15 −15 lib/subelsky_power_tools/controller_shared_behavior.rb
@@ -1,13 +1,13 @@
# https://www.relishapp.com/rspec/rspec-core/v/2-10/docs/example-groups/shared-examples
-shared_examples "a protected plural controller" do
- describe "new", :if => described_class.instance_methods.include?(:new) do
+shared_examples "a protected plural controller" do |skip_actions|
+ describe "new", :if => described_class.instance_methods.include?(:new) && not(Array(skip_actions).include?(:new)) do
it "requires signin" do
get :new
response.should redirect_to signin_redirect
end
end
- describe "edit", :if => described_class.instance_methods.include?(:edit) do
+ describe "edit", :if => described_class.instance_methods.include?(:edit) && not(Array(skip_actions).include?(:edit)) do
def simple_get(obj_id = 1)
get :edit, { id: obj_id }
end
@@ -24,7 +24,7 @@ def simple_get(obj_id = 1)
end
end
- describe "show", :if => described_class.instance_methods.include?(:show) do
+ describe "show", :if => described_class.instance_methods.include?(:show) && not(Array(skip_actions).include?(:show)) do
def simple_get(obj_id = 1)
get :show, { id: obj_id }
end
@@ -41,21 +41,21 @@ def simple_get(obj_id = 1)
end
end
- describe "index", :if => described_class.instance_methods.include?(:index) do
+ describe "index", :if => described_class.instance_methods.include?(:index) && not(Array(skip_actions).include?(:index)) do
it "requires signin" do
get :index
response.should redirect_to signin_redirect
end
end
- describe "create", :if => described_class.instance_methods.include?(:create) do
+ describe "create", :if => described_class.instance_methods.include?(:create) && not(Array(skip_actions).include?(:create)) do
it "requires signin" do
post :create
response.should redirect_to signin_redirect
end
end
- describe "update", :if => described_class.instance_methods.include?(:update) do
+ describe "update", :if => described_class.instance_methods.include?(:update) && not(Array(skip_actions).include?(:update)) do
def simple_put(obj_id = 1,params = {})
put :update, params.merge(id: obj_id)
end
@@ -77,7 +77,7 @@ def simple_put(obj_id = 1,params = {})
end
end
- describe "delete", :if => described_class.instance_methods.include?(:destroy) do
+ describe "delete", :if => described_class.instance_methods.include?(:destroy) && not(Array(skip_actions).include?(:destroy)) do
def simple_delete(obj_id = 1)
delete :destroy, id: obj_id
end
@@ -96,43 +96,43 @@ def simple_delete(obj_id = 1)
end
end
-shared_examples "a protected singular controller" do
- describe "new", :if => described_class.instance_methods.include?(:new) do
+shared_examples "a protected singular controller" do |skip_actions|
+ describe "new", :if => described_class.instance_methods.include?(:new) && not(Array(skip_actions).include?(:new)) do
it "requires signin" do
get :new
response.should redirect_to signin_redirect
end
end
- describe "edit", :if => described_class.instance_methods.include?(:edit) do
+ describe "edit", :if => described_class.instance_methods.include?(:edit) && not(Array(skip_actions).include?(:edit)) do
it "requires signin" do
get :edit
response.should redirect_to signin_redirect
end
end
- describe "show", :if => described_class.instance_methods.include?(:show) do
+ describe "show", :if => described_class.instance_methods.include?(:show) && not(Array(skip_actions).include?(:show)) do
it "requires signin" do
get :show
response.should redirect_to signin_redirect
end
end
- describe "create", :if => described_class.instance_methods.include?(:create) do
+ describe "create", :if => described_class.instance_methods.include?(:create) && not(Array(skip_actions).include?(:create)) do
it "requires signin" do
post :create
response.should redirect_to signin_redirect
end
end
- describe "update", :if => described_class.instance_methods.include?(:update) do
+ describe "update", :if => described_class.instance_methods.include?(:update) && not(Array(skip_actions).include?(:update)) do
it "requires signin" do
put :update
response.should redirect_to signin_redirect
end
end
- describe "delete", :if => described_class.instance_methods.include?(:destroy) do
+ describe "delete", :if => described_class.instance_methods.include?(:destroy) && not(Array(skip_actions).include?(:destroy)) do
it "requires signin" do
delete :destroy
response.should redirect_to signin_redirect

0 comments on commit fb5bf06

Please sign in to comment.