require File.expand_path(File.dirname(__FILE__) + '/../../test_helper') class Admin::Muck::SubscriptionPlansControllerTest < ActionController::TestCase tests Admin::Muck::SubscriptionPlansController context "admin subscription plan controller" do should_require_login :edit => :get, :update => :put, :login_url => '/login' context "logged in as normal user" do setup do @user = Factory(:user) activate_authlogic login_as @user end should_require_role('admin', :redirect_url => '/login', :edit => :get, :update => :put) end context "admin subscription plan controller - logged in as admin" do setup do @admin = Factory(:user) @admin_role = Factory(:role, :rolename => 'administrator') @admin.roles << @admin_role activate_authlogic login_as @admin @subscription_plan = Factory(:subscription_plan) end context "a GET to show" do setup do get :show, :id => @subscription_plan.id end should_respond_with :success should_render_template :show end context "a GET to new" do setup do get :new end should_respond_with :success should_render_template :new end context "a POST to create" do setup do post :create, :id => @subscription_plan.id, :subscription_plan => {:name => "A title", :sku => "a_plan_2", :amount => 1295, :renewal_period => 30, :trial_period => 15} end should_set_the_flash_to(I18n.translate('muck.commerce.subscription_plan_created')) should_redirect_to("Admin - Show subscription plan") { admin_subscription_plan_path(assigns(:subscription_plan)) } end context "a GET to edit" do setup do get :edit, :id => @subscription_plan.id end should_respond_with :success should_render_template :edit end context "a PUT to update" do setup do put :update, :id => @subscription_plan.id, :subscription_plan => {:name => "New Title"} end should_set_the_flash_to(I18n.translate('muck.commerce.subscription_plan_updated')) should_redirect_to("Admin - Show subscription plan") { admin_subscription_plan_path(assigns(:subscription_plan)) } end context "a PUT to update - invalid parameters" do setup do put :update, :id => @subscription_plan.id, :subscription_plan => {:name => "", :sku => "", :amount => ""} end should_respond_with :success should_render_template :edit should "have errors" do assert assigns['subscription_plan'].errors end end context "a DELETE to destroy" do setup do delete :destroy, :id => @subscription_plan.id end should_set_the_flash_to(I18n.translate('muck.commerce.subscription_plan_deleted')) should_redirect_to("Admin - List subscription plans") { admin_subscription_plans_path } end end end end