Browse files

Added stub_authorization! for request specs

This is used to give the current request spec permission to perform any and all admin actions
  • Loading branch information...
1 parent f006e01 commit 405d5bdd512ac94614b09b3f538038a08322d3ed @radar radar committed May 29, 2012
Showing with 90 additions and 6 deletions.
  1. +4 −0 core/app/models/spree/ability.rb
  2. +3 −1 core/spec/requests/admin/configuration/analytics_tracker_spec.rb
  3. +2 −0 core/spec/requests/admin/configuration/general_settings_spec.rb
  4. +2 −0 core/spec/requests/admin/configuration/inventory_settings_spec.rb
  5. +2 −0 core/spec/requests/admin/configuration/mail_methods_spec.rb
  6. +2 −0 core/spec/requests/admin/configuration/payment_methods_spec.rb
  7. +2 −0 core/spec/requests/admin/configuration/shipping_methods_spec.rb
  8. +2 −0 core/spec/requests/admin/configuration/states_spec.rb
  9. +2 −0 core/spec/requests/admin/configuration/tax_categories_spec.rb
  10. +2 −0 core/spec/requests/admin/configuration/tax_rates_spec.rb
  11. +2 −0 core/spec/requests/admin/configuration/taxonomies_spec.rb
  12. +2 −0 core/spec/requests/admin/configuration/zones_spec.rb
  13. +2 −0 core/spec/requests/admin/homepage_spec.rb
  14. +2 −0 core/spec/requests/admin/orders/adjustments_spec.rb
  15. +2 −0 core/spec/requests/admin/orders/customer_details_spec.rb
  16. +2 −0 core/spec/requests/admin/orders/history_spec.rb
  17. +2 −0 core/spec/requests/admin/orders/listing_spec.rb
  18. +2 −0 core/spec/requests/admin/orders/order_details_spec.rb
  19. +2 −0 core/spec/requests/admin/orders/payments_spec.rb
  20. +2 −0 core/spec/requests/admin/orders/return_authorizations_spec.rb
  21. +2 −1 core/spec/requests/admin/orders/shipments_spec.rb
  22. +2 −0 core/spec/requests/admin/products/edit/images_spec.rb
  23. +2 −0 core/spec/requests/admin/products/edit/products_spec.rb
  24. +2 −0 core/spec/requests/admin/products/edit/taxons_spec.rb
  25. +2 −0 core/spec/requests/admin/products/edit/variants_spec.rb
  26. +2 −0 core/spec/requests/admin/products/option_types_spec.rb
  27. +2 −0 core/spec/requests/admin/products/products_spec.rb
  28. +2 −0 core/spec/requests/admin/products/properties_spec.rb
  29. +2 −0 core/spec/requests/admin/products/prototypes_spec.rb
  30. +2 −0 core/spec/requests/admin/products/variant_spec.rb
  31. +2 −0 core/spec/requests/admin/reports_spec.rb
  32. +2 −0 core/spec/requests/admin/users_spec.rb
  33. +23 −4 core/spec/support/authorization_helpers.rb
View
4 core/app/models/spree/ability.rb
@@ -18,6 +18,10 @@ def self.register_ability(ability)
self.abilities.add(ability)
end
+ def self.remove_ability(ability)
+ self.abilities.delete(ability)
+ end
+
def initialize(user)
self.clear_aliased_actions
View
4 core/spec/requests/admin/configuration/analytics_tracker_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Analytics Tracker" do
+ stub_authorization!
+
context "index" do
before(:each) do
2.times { create(:tracker, :environment => "test") }
@@ -22,7 +24,7 @@
find('table.index tr:nth-child(2) td:nth-child(2)').text.should == "Test"
find('table.index tr:nth-child(2) td:nth-child(3)').text.should == "Yes"
end
- end
+ end
context "create" do
before(:each) do
View
2 core/spec/requests/admin/configuration/general_settings_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "General Settings" do
+ stub_authorization!
+
before(:each) do
visit spree.admin_path
click_link "Configuration"
View
2 core/spec/requests/admin/configuration/inventory_settings_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Inventory Settings" do
+ stub_authorization!
+
context "changing settings" do
before(:each) do
reset_spree_preferences do |config|
View
2 core/spec/requests/admin/configuration/mail_methods_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Mail Methods" do
+ stub_authorization!
+
before(:each) do
visit spree.admin_path
click_link "Configuration"
View
2 core/spec/requests/admin/configuration/payment_methods_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Payment Methods" do
+ stub_authorization!
+
before(:each) do
visit spree.admin_path
click_link "Configuration"
View
2 core/spec/requests/admin/configuration/shipping_methods_spec.rb
@@ -2,6 +2,8 @@
require 'active_record/fixtures'
describe "Shipping Methods" do
+ stub_authorization!
+
before(:all) do
fixtures_dir = File.expand_path('../../../../../db/default', __FILE__)
ActiveRecord::Fixtures.create_fixtures(fixtures_dir, ['spree/countries', 'spree/zones', 'spree/zone_members', 'spree/states', 'spree/roles'])
View
2 core/spec/requests/admin/configuration/states_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "States" do
+ stub_authorization!
+
let!(:country) { create(:country) }
before(:each) do
View
2 core/spec/requests/admin/configuration/tax_categories_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Tax Categories" do
+ stub_authorization!
+
before(:each) do
visit spree.admin_path
click_link "Configuration"
View
2 core/spec/requests/admin/configuration/tax_rates_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Tax Rates" do
+ stub_authorization!
+
let!(:tax_rate) { create(:tax_rate, :calculator => stub_model(Spree::Calculator)) }
before do
View
2 core/spec/requests/admin/configuration/taxonomies_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Taxonomies" do
+ stub_authorization!
+
before(:each) do
visit spree.admin_path
click_link "Configuration"
View
2 core/spec/requests/admin/configuration/zones_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Zones" do
+ stub_authorization!
+
before(:each) do
Spree::Zone.delete_all
visit spree.admin_path
View
2 core/spec/requests/admin/homepage_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Homepage" do
+ stub_authorization!
+
context "visiting the homepage" do
before(:each) do
visit spree.admin_path
View
2 core/spec/requests/admin/orders/adjustments_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Adjustments" do
+ stub_authorization!
+
before(:each) do
visit spree.admin_path
order = create(:order, :completed_at => "2011-02-01 12:36:15", :number => "R100")
View
2 core/spec/requests/admin/orders/customer_details_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Customer Details" do
+ stub_authorization!
+
let(:shipping_method) { create(:shipping_method, :display_on => "front_end") }
let(:order) { create(:order_with_inventory_unit_shipped, :completed_at => 1.year.ago, :shipping_method => shipping_method) }
View
2 core/spec/requests/admin/orders/history_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Admin visiting history" do
+ stub_authorization!
+
it "should display order history", :js => true do
order = create(:order)
order.finalize!
View
2 core/spec/requests/admin/orders/listing_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Orders Listing" do
+ stub_authorization!
+
before(:each) do
create(:order, :created_at => Time.now + 1.day, :completed_at => Time.now + 1.day, :number => "R100")
create(:order, :created_at => Time.now - 1.day, :completed_at => Time.now - 1.day, :number => "R200")
View
2 core/spec/requests/admin/orders/order_details_spec.rb
@@ -2,6 +2,8 @@
require 'spec_helper'
describe "Order Details" do
+ stub_authorization!
+
context "edit order page" do
before do
View
2 core/spec/requests/admin/orders/payments_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Payments" do
+ stub_authorization!
+
before(:each) do
reset_spree_preferences do |config|
View
2 core/spec/requests/admin/orders/return_authorizations_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "return authorizations" do
+ stub_authorization!
+
let!(:order) { create(:completed_order_with_totals) }
before do
View
3 core/spec/requests/admin/orders/shipments_spec.rb
@@ -1,7 +1,8 @@
require 'spec_helper'
describe "Shipments" do
-
+ stub_authorization!
+
Spree::Zone.delete_all
let(:shipping_method) { create(:shipping_method, :zone => Spree::Zone.find_by_name('North America') || create(:zone, :name => 'North America')) }
let(:order) { create(:completed_order_with_totals, :number => "R100", :state => "complete", :shipping_method => shipping_method) }
View
2 core/spec/requests/admin/products/edit/images_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Product Images" do
+ stub_authorization!
+
context "uploading and editing an image", :js => true do
it "should allow an admin to upload and edit an image for a product" do
Spree::Image.attachment_definitions[:attachment].delete :storage
View
2 core/spec/requests/admin/products/edit/products_spec.rb
@@ -2,6 +2,8 @@
require 'spec_helper'
describe 'Product Details' do
+ stub_authorization!
+
context 'editing a product' do
let(:available_on) { Time.now }
it 'should list the product details' do
View
2 core/spec/requests/admin/products/edit/taxons_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Product Taxons" do
+ stub_authorization!
+
context "managing taxons" do
it "should allow an admin to manage taxons", :js => true do
taxon = create(:taxon, :name => 'Brands')
View
2 core/spec/requests/admin/products/edit/variants_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Product Variants" do
+ stub_authorization!
+
before(:each) do
visit spree.admin_path
end
View
2 core/spec/requests/admin/products/option_types_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Option Types" do
+ stub_authorization!
+
before(:each) do
visit spree.admin_path
click_link "Products"
View
2 core/spec/requests/admin/products/products_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Products" do
+ stub_authorization!
+
context "as admin user" do
before(:each) do
visit spree.admin_path
View
2 core/spec/requests/admin/products/properties_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Properties" do
+ stub_authorization!
+
before(:each) do
visit spree.admin_path
click_link "Products"
View
2 core/spec/requests/admin/products/prototypes_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Prototypes" do
+ stub_authorization!
+
context "listing prototypes" do
it "should be able to list existing prototypes" do
create(:property, :name => "model", :presentation => "Model")
View
2 core/spec/requests/admin/products/variant_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Variants" do
+ stub_authorization!
+
context "creating a new variant" do
it "should allow an admin to create a new variant" do
product = create(:product_with_option_types, :price => "1.99", :cost_price => "1.00", :weight => "2.5", :height => "3.0", :width => "1.0", :depth => "1.5")
View
2 core/spec/requests/admin/reports_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Reports" do
+ stub_authorization!
+
context "visiting the admin reports page" do
it "should have the right content" do
visit spree.admin_path
View
2 core/spec/requests/admin/users_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Users" do
+ stub_authorization!
+
before(:each) do
create(:user, :email => "a@example.com")
create(:user, :email => "b@example.com")
View
27 core/spec/support/authorization_helpers.rb
@@ -1,11 +1,30 @@
module AuthorizationHelpers
- def stub_authorization!
- before do
- controller.should_receive(:authorize!).twice.and_return(true)
+ module Controller
+ def stub_authorization!
+ before do
+ controller.should_receive(:authorize!).twice.and_return(true)
+ end
+ end
+ end
+
+ module Request
+ class SuperAbility
+ include CanCan::Ability
+
+ def initialize(user)
+ # allow anyone to perform index on Order
+ can :manage, :all
+ end
+ end
+
+ def stub_authorization!
+ before(:all) { Spree::Ability.register_ability(AuthorizationHelpers::Request::SuperAbility) }
+ after(:all) { Spree::Ability.remove_ability(AuthorizationHelpers::Request::SuperAbility) }
end
end
end
RSpec.configure do |config|
- config.extend AuthorizationHelpers
+ config.extend AuthorizationHelpers::Controller, :type => :controller
+ config.extend AuthorizationHelpers::Request, :type => :request
end

0 comments on commit 405d5bd

Please sign in to comment.