summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--billing/app/controllers/billing_base_controller.rb2
-rw-r--r--billing/app/controllers/subscriptions_controller.rb2
-rw-r--r--billing/app/views/subscriptions/show.html.haml3
-rw-r--r--billing/config/routes.rb4
-rw-r--r--billing/test/integration/subscription_test.rb48
-rw-r--r--config/application.rb2
-rw-r--r--config/environments/production.rb11
-rw-r--r--users/app/controllers/v1/users_controller.rb2
-rw-r--r--users/app/models/user.rb4
-rw-r--r--users/test/integration/browser/account_test.rb4
-rw-r--r--users/test/unit/account_test.rb11
11 files changed, 70 insertions, 23 deletions
diff --git a/billing/app/controllers/billing_base_controller.rb b/billing/app/controllers/billing_base_controller.rb
index c250831..0453677 100644
--- a/billing/app/controllers/billing_base_controller.rb
+++ b/billing/app/controllers/billing_base_controller.rb
@@ -7,7 +7,7 @@ class BillingBaseController < ApplicationController
def assign_user
if params[:user_id]
@user = User.find(params[:user_id])
- elsif params[:action] == "confirm" or params[:action] == "destroy" # confirms and subscription deletes will come back with different ID set, so check for this first
+ elsif params[:action] == "confirm"# confirms will come back with different ID set, so check for this first
# This is only for cases where an admin cannot apply action for customer, but should be all confirms
@user = current_user
elsif params[:id]
diff --git a/billing/app/controllers/subscriptions_controller.rb b/billing/app/controllers/subscriptions_controller.rb
index 4047847..4b1851a 100644
--- a/billing/app/controllers/subscriptions_controller.rb
+++ b/billing/app/controllers/subscriptions_controller.rb
@@ -3,7 +3,7 @@ class SubscriptionsController < BillingBaseController
before_filter :fetch_subscription, :only => [:show, :destroy]
before_filter :confirm_no_active_subscription, :only => [:new, :create]
# for now, admins cannot create or destroy subscriptions for others:
- before_filter :confirm_self, :only => [:destroy, :new, :create]
+ before_filter :confirm_self, :only => [:new, :create]
def new
# don't show link to subscribe if they are already subscribed?
diff --git a/billing/app/views/subscriptions/show.html.haml b/billing/app/views/subscriptions/show.html.haml
index ebb7e0d..39f4d1a 100644
--- a/billing/app/views/subscriptions/show.html.haml
+++ b/billing/app/views/subscriptions/show.html.haml
@@ -3,5 +3,4 @@
Current
Subscription
= render :partial => "subscription_details", :locals => {:subscription => @subscription}
-- if @user == current_user
- = link_to t(:cancel_subscription), subscription_path(@subscription.id), :confirm => t(:are_you_sure), :method => :delete, :class => 'btn btn-danger' if @subscription.status == 'Active' # permission check or should that just be on show?
+= link_to t(:cancel_subscription), user_subscription_path(@user, @subscription.id), :confirm => t(:are_you_sure), :method => :delete, :class => 'btn btn-danger' if @subscription.status == 'Active' # permission check or should that just be on show?
diff --git a/billing/config/routes.rb b/billing/config/routes.rb
index 8b7b5bf..e024f43 100644
--- a/billing/config/routes.rb
+++ b/billing/config/routes.rb
@@ -4,7 +4,7 @@ Rails.application.routes.draw do
match 'payments/confirm' => 'payments#confirm', :as => :confirm_payment
resources :users do
resources :payments, :only => [:index]
- resources :subscriptions, :only => [:index, :show]
+ resources :subscriptions, :only => [:index, :show, :destroy]
end
resources :customer, :only => [:new, :edit]
@@ -14,7 +14,7 @@ Rails.application.routes.draw do
match 'customer/show/:id' => 'customer#show', :as => :show_customer
match 'credit_card_info/confirm' => 'credit_card_info#confirm', :as => :confirm_credit_card_info
- resources :subscriptions, :only => [:new, :create, :update, :destroy] # index and show are within users path
+ resources :subscriptions, :only => [:new, :create, :update] # index, show & destroy are within users path
#match 'transactions/:product_id/new' => 'transactions#new', :as => :new_transaction
#match 'transactions/confirm/:product_id' => 'transactions#confirm', :as => :confirm_transaction
diff --git a/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb
new file mode 100644
index 0000000..7410118
--- /dev/null
+++ b/billing/test/integration/subscription_test.rb
@@ -0,0 +1,48 @@
+require 'test_helper'
+require 'fake_braintree'
+require 'capybara/rails'
+
+class SubscriptionTest < ActionDispatch::IntegrationTest
+ include Warden::Test::Helpers
+ include Capybara::DSL
+
+ setup do
+ Warden.test_mode!
+ @admin = User.find_by_login('admin') || FactoryGirl.create(:user, login: 'admin')
+ @customer = FactoryGirl.create(:customer)
+ @braintree_customer = FactoryGirl.create(:braintree_customer)
+ @customer.braintree_customer_id = @braintree_customer.id
+ @customer.save
+ @subscription = FakeBraintree::Subscription.new({:payment_method_token => @braintree_customer.credit_cards.first, :plan_id => '5'}, {:id => @braintree_customer.id, :merchant_id => Braintree::Configuration.merchant_id})
+ # unfortunately @braintree_customer.credit_cards.first.subscriptions still returns empty array
+ end
+
+ teardown do
+ Warden.test_reset!
+ @admin.destroy
+ @customer.destroy
+ end
+
+ test "admin can cancel subscription for another" do
+ skip "not sure about testing admin cancelling subscription with fake_braintree"
+ login_as @admin
+ #visit user_subscriptions_path(@customer.user_id)
+ #delete :destroy, :id => @subscription.id
+ end
+
+ #test "admin cannot add subscription for another" do
+ #end
+
+ #test "authenticated user can cancel own subscription" do
+ #end
+
+ #test "user cannot add subscription if they have active one" do
+ #end
+
+ #test "user can view own subscriptions"
+ #end
+
+ #test "admin can view another user's subscriptions" do
+ #end
+
+end
diff --git a/config/application.rb b/config/application.rb
index e8bb2f4..8587ffc 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -54,7 +54,7 @@ module LeapWeb
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
- if APP_CONFIG[:logfile]
+ if APP_CONFIG[:logfile].present?
config.logger = Logger.new(APP_CONFIG[:logfile])
end
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 32b4558..73e98e5 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -33,11 +33,12 @@ LeapWeb::Application.configure do
# See everything in the log (default is :info)
# config.log_level = :debug
- # Prepend all log lines with the following tags
- # config.log_tags = [ :subdomain, :uuid ]
-
- # Use a different logger for distributed setups
- # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+ # Use syslog if no file has been specified
+ if APP_CONFIG[:logfile].blank?
+ # Prepend all log lines with the following tags
+ config.log_tags = [ :leap, :webapp ]
+ config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+ end
# Use a different cache store in production
# config.cache_store = :mem_cache_store
diff --git a/users/app/controllers/v1/users_controller.rb b/users/app/controllers/v1/users_controller.rb
index 01a1a2f..03a5a62 100644
--- a/users/app/controllers/v1/users_controller.rb
+++ b/users/app/controllers/v1/users_controller.rb
@@ -31,7 +31,7 @@ module V1
protected
def account
- Account.new(@user)
+ @user.account
end
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 310eecd..a14fcb5 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -82,6 +82,10 @@ class User < CouchRest::Model::Base
identity.keys[:pgp]
end
+ def account
+ Account.new(self)
+ end
+
def identity
@identity ||= Identity.for(self)
end
diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb
index ae4676c..8c2c997 100644
--- a/users/test/integration/browser/account_test.rb
+++ b/users/test/integration/browser/account_test.rb
@@ -13,9 +13,7 @@ class AccountTest < BrowserIntegrationTest
assert page.has_content?("Sign Up")
assert_equal '/', current_path
assert user = User.find_by_login(username)
- assert id = user.identity
- id.destroy
- user.destroy
+ user.account.destroy
end
test "successful login" do
diff --git a/users/test/unit/account_test.rb b/users/test/unit/account_test.rb
index 39969c0..94a9980 100644
--- a/users/test/unit/account_test.rb
+++ b/users/test/unit/account_test.rb
@@ -9,15 +9,14 @@ class AccountTest < ActiveSupport::TestCase
assert id = user.identity
assert_equal user.email_address, id.address
assert_equal user.email_address, id.destination
- id.destroy
- user.destroy
+ user.account.destroy
end
test "create and remove a user account" do
assert_no_difference "Identity.count" do
assert_no_difference "User.count" do
user = Account.create(FactoryGirl.attributes_for(:user))
- Account.new(user).destroy
+ user.account.destroy
end
end
end
@@ -26,7 +25,7 @@ class AccountTest < ActiveSupport::TestCase
user = Account.create(FactoryGirl.attributes_for(:user))
old_id = user.identity
old_email = user.email_address
- Account.new(user).update(FactoryGirl.attributes_for(:user))
+ user.account.update(FactoryGirl.attributes_for(:user))
user.reload
old_id.reload
assert user.valid?
@@ -37,9 +36,7 @@ class AccountTest < ActiveSupport::TestCase
assert_equal user.email_address, id.destination
assert_equal user.email_address, old_id.destination
assert_equal old_email, old_id.address
- old_id.destroy
- id.destroy
- user.destroy
+ user.account.destroy
end
end