From 3035175c4fc64d471d16636f36e1efd86acca512 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Fri, 21 Aug 2015 14:42:05 -0700 Subject: [PATCH] ability to set custom maximum space --- migrations/074_add_custom_max_space.rb | 9 +++++++++ models/site.rb | 6 +++++- tests/site_tests.rb | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 migrations/074_add_custom_max_space.rb diff --git a/migrations/074_add_custom_max_space.rb b/migrations/074_add_custom_max_space.rb new file mode 100644 index 00000000..1bc09b18 --- /dev/null +++ b/migrations/074_add_custom_max_space.rb @@ -0,0 +1,9 @@ +Sequel.migration do + up { + DB.add_column :sites, :custom_max_space, :bigint, default: 0 + } + + down { + DB.drop_column :sites, :custom_max_space + } +end diff --git a/models/site.rb b/models/site.rb index 6b9fc9e7..49df0bfa 100644 --- a/models/site.rb +++ b/models/site.rb @@ -960,7 +960,11 @@ class Site < Sequel::Model end def maximum_space - PLAN_FEATURES[(parent? ? self : parent).plan_type.to_sym][:space] + plan_space = PLAN_FEATURES[(parent? ? self : parent).plan_type.to_sym][:space] + + return custom_max_space if custom_max_space > plan_space + + plan_space end def space_percentage_used diff --git a/tests/site_tests.rb b/tests/site_tests.rb index e72a685e..9fbb8ef1 100644 --- a/tests/site_tests.rb +++ b/tests/site_tests.rb @@ -5,6 +5,16 @@ def app end describe Site do + describe 'custom_max_space' do + it 'should use the custom max space if it is more' do + site = Fabricate :site + site.maximum_space.must_equal Site::PLAN_FEATURES[:free][:space] + site.custom_max_space = 10**9 + site.save_changes + site.maximum_space.must_equal 10**9 + end + end + describe 'can_email' do it 'should fail if send_emails is false' do site = Fabricate :site