Skip to content

Commit 1393579

Browse files
committed
Made team delete operation an archive operation
1 parent 2f4f8b3 commit 1393579

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

app/controllers/teams_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'team_playbook/scenario/archive_team'
12
require 'team_playbook/scenario/create_team'
23
require 'team_playbook/scenario/change_plan_for_team'
34
require 'team_playbook/scenario/add_card_to_team'
@@ -24,7 +25,7 @@ def show
2425
def destroy
2526
if has_team_subdomain?
2627
authorize! :destroy, current_team
27-
TeamPlaybook::Scenario::DeleteTeam.new.call(team: current_team)
28+
TeamPlaybook::Scenario::ArchiveTeam.new.call(team: current_team)
2829
render nothing: true, status: 204
2930
else
3031
forbidden
@@ -47,4 +48,4 @@ def team_params
4748
def credit_card_required
4849
render json: {error: "A credit card is required for a paid plan."}, status: :unprocessable_entity
4950
end
50-
end
51+
end

app/models/team.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
class Team < ActiveRecord::Base
2+
enum status: [:archived, :active]
3+
24
validates :subdomain, presence: true, exclusion: { in: Settings.reserved_subdomains,
35
message: "%{value} is not a valid subdomain." }
46
validates :name, presence: true
57

68
belongs_to :owner, class_name: "User"
7-
has_many :team_memberships, dependent: :delete_all
9+
has_many :team_memberships
810
has_many :members, source: :user, through: :team_memberships
911

1012
has_one :subscription
@@ -13,4 +15,4 @@ class Team < ActiveRecord::Base
1315
delegate :name, to: :plan, prefix: true
1416
delegate :slug, to: :plan, prefix: true
1517

16-
end
18+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddStatusFieldToTeam < ActiveRecord::Migration
2+
def change
3+
add_column :teams, :status, :integer, default: 1
4+
end
5+
end

db/schema.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20150514124031) do
14+
ActiveRecord::Schema.define(version: 20150515071915) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
@@ -45,12 +45,13 @@
4545
end
4646

4747
create_table "teams", force: :cascade do |t|
48-
t.string "name", null: false
49-
t.string "subdomain", null: false
50-
t.datetime "created_at", null: false
51-
t.datetime "updated_at", null: false
48+
t.string "name", null: false
49+
t.string "subdomain", null: false
50+
t.datetime "created_at", null: false
51+
t.datetime "updated_at", null: false
5252
t.integer "owner_id"
5353
t.string "stripe_customer_id"
54+
t.integer "status", default: 1
5455
end
5556

5657
create_table "users", force: :cascade do |t|

lib/team_playbook/scenario/delete_team.rb renamed to lib/team_playbook/scenario/archive_team.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module TeamPlaybook
22
module Scenario
3-
class DeleteTeam
3+
class ArchiveTeam
44
def call(team:)
5-
team.destroy
5+
team.archived!
66
end
77
end
88
end

spec/lib/team_playbook/scenario/delete_team_spec.rb

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
require 'rails_helper'
2-
require 'team_playbook/scenario/delete_team'
2+
require 'team_playbook/scenario/archive_team'
33

44
module TeamPlaybook
55
module Scenario
6-
describe DeleteTeam do
7-
it "should delete team" do
6+
describe ArchiveTeam do
7+
it "should archive team" do
88
team = create(:team)
99

10-
DeleteTeam.new.call(team: team)
11-
expect(team).not_to be_persisted
12-
expect(Team.all.count).to be 0
13-
end
14-
15-
it "should delete associated memberships" do
16-
user = create(:user)
17-
team = create(:team)
18-
other_team = create(:team)
19-
create_list(:team_membership, 10, team: team)
20-
create_list(:team_membership, 5, team: other_team)
21-
22-
DeleteTeam.new.call(team: team)
23-
expect(TeamMembership.all.count).to eq 5
10+
ArchiveTeam.new.call(team: team)
11+
expect(team.archived?).to be true
12+
expect(Team.active.count).to be 0
2413
end
2514
end
2615
end

0 commit comments

Comments
 (0)