Skip to content

remove destination accountable from transfer sources options #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def display_name_with_uid
# @params _destination_accountable used to keep the same API as
# Organization#display_id
# @return [Integer]
def display_id(_destination_accountable)
def display_id
member_uid
end

Expand Down
8 changes: 2 additions & 6 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ def display_name_with_uid
#
# @params destination_accountable [Organization | Object] target of a transfer
# @return [Integer | String]
def display_id(destination_accountable)
if destination_accountable.is_a?(Organization)
account.accountable_id
else
''
end
def display_id
account.accountable_id
end

def ensure_reg_number_seq!
Expand Down
12 changes: 3 additions & 9 deletions app/models/transfer_sources_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ class TransferSourcesOptions
# Constructor
#
# @param sources [Array<Account>]
# @param destination_accountable [Member | Organization]
def initialize(sources, destination_accountable)
def initialize(sources)
@sources = sources
@destination_accountable = destination_accountable
end

# Returns the collection as an Array containing pairs of <option>'s text and
Expand All @@ -22,7 +20,7 @@ def to_a

private

attr_reader :sources, :destination_accountable
attr_reader :sources

def to_accountable_type_and_uid(account)
[account.accountable_type, account.accountable.try(:member_uid)]
Expand All @@ -32,12 +30,8 @@ def to_text_and_value(account)
accountable = account.accountable

[
"#{display_id(accountable)} #{accountable.class} #{accountable}",
"#{accountable.display_id} #{accountable.class} #{accountable}",
account.id
]
end

def display_id(accountable)
accountable.display_id(destination_accountable)
end
end
2 changes: 1 addition & 1 deletion app/views/transfers/_sources.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= form.label :source %>
<%= form.select :source,
options_for_select(
TransferSourcesOptions.new(sources, accountable).to_a,
TransferSourcesOptions.new(sources).to_a,
selected: current_user.member(current_organization).account.id
), {}, id: "select2-time", class: "form-control"
%>
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/transfers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
get :new, params

expect(response.body).to include("<select id=\"select2-time\" class=\"form-control\" name=\"transfer[source]\"><option selected=\"selected\" value=\"#{member_admin.account.id}\">#{member_admin.member_uid} Member #{member_admin}</option>")
expect(response.body).to include("<option value=\"#{test_organization.account.id}\"> Organization #{test_organization}</option></select>")
expect(response.body).to include("<option value=\"#{test_organization.account.id}\">#{test_organization.id} Organization #{test_organization}</option></select>")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/member_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
end

describe '#display_id' do
subject { member.display_id(nil) }
subject { member.display_id }

it { is_expected.to eq(member.member_uid) }
end
Expand Down
12 changes: 2 additions & 10 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@
let(:organization) { Fabricate(:organization) }

describe '#display_id' do
subject { organization.display_id(destination_accountable) }
subject { organization.display_id }

context 'when the destination_accountable is an organization' do
let(:destination_accountable) { Fabricate(:organization) }
it { is_expected.to eq(organization.account.accountable_id) }
end

context 'when the destination_accountable is not an organization' do
let(:destination_accountable) { Fabricate(:member) }
it { is_expected.to eq('') }
end
it { is_expected.to eq(organization.account.accountable_id) }
end

describe 'ensure_url validation' do
Expand Down
4 changes: 1 addition & 3 deletions spec/models/transfer_sources_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe TransferSourcesOptions do
let(:transfer_sources_options) do
described_class.new(sources, destination_accountable)
described_class.new(sources)
end

describe '#to_a' do
Expand All @@ -14,8 +14,6 @@
Fabricate(:member, organization: organization, member_uid: 1)
end

let(:destination_accountable) { Fabricate(:organization) }

let(:sources) do
[organization.account, member.account, newer_member.account]
end
Expand Down