Skip to content

Commit dc1a958

Browse files
committed
Store ID in a decklist_slot, update things accordingly.
1 parent 48c2b76 commit dc1a958

File tree

5 files changed

+7
-19
lines changed

5 files changed

+7
-19
lines changed

app/models/decklist.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ def card_slots
2727
end
2828

2929
def num_cards
30-
decklist_cards.map(&:quantity).sum
30+
decklist_cards
31+
# Exclude identity
32+
.reject { |c| c.card_id == identity_card_id }
33+
.map(&:quantity).sum
3134
end
3235

3336
# TODO(plural): Extract this out to share between public and private decklists.
@@ -37,6 +40,8 @@ def num_cards
3740
def influence_spent
3841
qty = decklist_cards.each_with_object({}) { |c, h| h[c.card_id] = c.quantity }
3942
cards
43+
# Exclude identity
44+
.reject { |c| c.id == identity_card.id }
4045
.filter { |c| c.faction_id != identity_card.faction_id }
4146
.map { |c| c.influence_cost.nil? ? 0 : (c.influence_cost * qty[c.id]) }
4247
.sum

app/resources/decklist_resource.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,5 @@ class DecklistResource < ApplicationResource
5050
end
5151
end
5252

53-
# The rubocop warning is disabled because this relationship won't work
54-
# without it because there is no identity_card table.
55-
belongs_to :identity_card, resource: CardResource, foreign_key: :identity_card_id do # rubocop:disable Rails/RedundantForeignKey
56-
link do |decklist|
57-
format('%<url>s/%<id>s', url: Rails.application.routes.url_helpers.cards_url, id: decklist.identity_card_id)
58-
end
59-
end
60-
6153
many_to_many :cards
6254
end

lib/tasks/import_decklists.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ namespace :import_decklists do # rubocop:disable Metrics/BlockLength
6565

6666
# To allow overwriting, clear out the existing cards.
6767
d.decklist_cards.delete_all
68+
d.decklist_cards << d.decklist_cards.build(card_id: d.identity_card_id, quantity: 1)
6869
decklist['cards'].each do |printing_id, quantity|
6970
card = cards_by_id[printing_to_card[printing_id]]
7071
# Do not write identity cards to the decklist_cards table.

spec/acceptance/decklists_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
1717
* Side
1818
* Faction
19-
* Identity Card
2019
* Cards
2120
2221
EXPLANATION

spec/resources/decklist/reads_spec.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ def check_included_for_id(decklist_id, include_value, resource_type, id)
7676
end
7777
end
7878

79-
describe 'include identity card' do
80-
let!(:decklist) { Decklist.find('11111111-1111-1111-1111-111111111111') }
81-
let!(:card) { Card.find('asa_group_security_through_vigilance') }
82-
83-
it 'works' do
84-
check_included_for_id(decklist.id, 'identity_card', 'cards', card.id)
85-
end
86-
end
87-
8879
describe 'include cards' do
8980
let!(:decklist) { Decklist.find('22222222-2222-2222-2222-222222222222') }
9081
let!(:card) { Card.find('the_class_act') }

0 commit comments

Comments
 (0)