Skip to content

Commit 24a7aa8

Browse files
iHiDampcode-com
andcommitted
Fix glossary entry proposal command signatures
- Update Approve and Reject commands to accept proposal directly instead of glossary_entry - Fix controller to pass @proposal to Approve/Reject commands - Update test expectations to match corrected command signatures - Resolves logical inconsistency where commands tried to find proposals through glossary entries Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-b0f4fc46-b5d8-47f8-899f-b9cab8f38b5f
1 parent a52070f commit 24a7aa8

4 files changed

Lines changed: 9 additions & 19 deletions

File tree

app/commands/localization/glossary_entry_proposal/approve.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Localization::GlossaryEntryProposal::Approve
22
include Mandate
33

4-
initialize_with :glossary_entry, :user
4+
initialize_with :proposal, :user
55

66
def call
77
ActiveRecord::Base.transaction do
@@ -30,16 +30,16 @@ def handle_addition!
3030
end
3131

3232
def handle_modification!
33-
raise "No glossary entry to modify" if glossary_entry.nil?
33+
raise "No glossary entry to modify" if proposal.glossary_entry.nil?
3434

35-
glossary_entry.update!(
35+
proposal.glossary_entry.update!(
3636
translation: proposal.translation,
3737
llm_instructions: proposal.llm_instructions
3838
)
3939
end
4040

4141
def handle_deletion!
42-
raise "No glossary entry to delete" if glossary_entry.nil?
42+
raise "No glossary entry to delete" if proposal.glossary_entry.nil?
4343

4444
# Retrieve this before destroying else we have a race
4545
glossary_entry = proposal.glossary_entry
@@ -48,9 +48,4 @@ def handle_deletion!
4848
proposal.update!(glossary_entry: nil)
4949
glossary_entry.destroy!
5050
end
51-
52-
memoize
53-
def proposal
54-
glossary_entry.proposals.pending.first
55-
end
5651
end
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Localization::GlossaryEntryProposal::Reject
22
include Mandate
33

4-
initialize_with :glossary_entry, :user
4+
initialize_with :proposal, :user
55

66
def call
77
ActiveRecord::Base.transaction do
@@ -11,9 +11,4 @@ def call
1111
)
1212
end
1313
end
14-
15-
memoize
16-
def proposal
17-
glossary_entry.proposals.pending.first
18-
end
1914
end

app/controllers/api/localization/glossary_entry_proposals_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ def create
1111
end
1212

1313
def approve
14-
Localization::GlossaryEntryProposal::Approve.(@glossary_entry, current_user)
14+
Localization::GlossaryEntryProposal::Approve.(@proposal, current_user)
1515

1616
render json: {
1717
glossary_entry: SerializeLocalizationGlossaryEntry.(@glossary_entry, current_user)
1818
}
1919
end
2020

2121
def reject
22-
Localization::GlossaryEntryProposal::Reject.(@glossary_entry, current_user)
22+
Localization::GlossaryEntryProposal::Reject.(@proposal, current_user)
2323

2424
render json: {
2525
glossary_entry: SerializeLocalizationGlossaryEntry.(@glossary_entry, current_user)

test/controllers/api/localization/glossary_entries_proposals_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class API::Localization::GlossaryEntriesProposalsControllerTest < API::BaseTestC
2222
glossary_entry = create :localization_glossary_entry
2323
proposal = create :localization_glossary_entry_proposal, :modification, glossary_entry: glossary_entry, proposer: @current_user
2424

25-
Localization::GlossaryEntryProposal::Approve.expects(:call).with(glossary_entry, @current_user)
25+
Localization::GlossaryEntryProposal::Approve.expects(:call).with(proposal, @current_user)
2626

2727
patch approve_api_localization_glossary_entry_proposal_path(glossary_entry, proposal), headers: @headers, as: :json
2828

@@ -36,7 +36,7 @@ class API::Localization::GlossaryEntriesProposalsControllerTest < API::BaseTestC
3636
glossary_entry = create :localization_glossary_entry
3737
proposal = create :localization_glossary_entry_proposal, :modification, glossary_entry: glossary_entry, proposer: @current_user
3838

39-
Localization::GlossaryEntryProposal::Reject.expects(:call).with(glossary_entry, @current_user)
39+
Localization::GlossaryEntryProposal::Reject.expects(:call).with(proposal, @current_user)
4040

4141
patch reject_api_localization_glossary_entry_proposal_path(glossary_entry, proposal), headers: @headers, as: :json
4242

0 commit comments

Comments
 (0)