Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
FIXBUG: Changed the scope of the Contact.reverse_proxy to user's cont…
Browse files Browse the repository at this point in the history
…acts
  • Loading branch information
jhbabon committed Dec 15, 2010
1 parent 5fdbfbd commit 42b87cf
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 33 deletions.
6 changes: 3 additions & 3 deletions app/controllers/debts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def create
def update
respond_to do |format|
if @debt.update_attributes(params[:debt])
@contact = Contact.reverse_proxy(@debt.partner(current_user))
@contact = current_user.contacts.reverse_proxy(@debt.partner(current_user))
format.html { redirect_to(@debt) }
else
format.html { render :action => "edit" }
Expand All @@ -64,7 +64,7 @@ def unpay

# DELETE /debts/1
def destroy
@contact = Contact.reverse_proxy(@debt.partner(current_user))
@contact = current_user.contacts.reverse_proxy(@debt.partner(current_user))
@debt.destroy

respond_to do |format|
Expand All @@ -77,7 +77,7 @@ def destroy
def pay_debt(value=true)
respond_to do |format|
@debt.update_attributes({ :paid => value })
@contact = Contact.reverse_proxy(@debt.partner(current_user))
@contact = current_user.contacts.reverse_proxy(@debt.partner(current_user))
format.html { redirect_to(@debt) }
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def proxy?

def self.reverse_proxy(person)
if person.is_a?(User)
Contact.where("friend_id = ?", person.id).first
where("friend_id = ?", person.id).first
elsif person.is_a?(Contact)
person
end
Expand All @@ -40,7 +40,7 @@ def #{method}

def keep_shared_debts
if proxy?
mirror = Contact.reverse_proxy(user)
mirror = User.find(friend_id).contacts.reverse_proxy(user)
mirror.update_attributes({ :friend => nil,
:email => user.email,
:first_name => user.first_name,
Expand Down
2 changes: 1 addition & 1 deletion app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def accept
protected

def is_necessary?
if Contact.reverse_proxy(User.find(self.receiver_id))
if User.find(self.sender_id).contacts.reverse_proxy(User.find(self.receiver_id))
raise Exceptions::Invitations::ContactExists
end

Expand Down
40 changes: 20 additions & 20 deletions app/views/contacts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
<h1><%= @contact.full_name %> <small>(<%= mail_to @contact.email %>)</small></h1>
</header>
<%= render 'shared/clear' %>
<section class="grid_8 suffix_4">
<div class="grid_2 alpha">
<h3><%= t "views.contacts.contact.total_loan" %></h3>
<p><%= mark_amount(number_to_currency(@debts_all.total_loan(current_user))) %></p>
</div>
<div class="grid_2">
<h3><%= t "views.contacts.contact.total_debt" %></h3>
<p><%= mark_amount(number_to_currency(@debts_all.total_debt(current_user))) %></p>
</div>
<div class="grid_2 omega suffix_2">
<h3><%= t "views.contacts.contact.total_sum" %></h3>
<p><%= mark_amount(number_to_currency(@debts_all.total_sum(current_user))) %></p>
</div>
</section>
<%= render 'shared/clear' %>

<header class="grid_12">
<h2><%= t "views.contacts.show.header" %></h2>
</header>
<%= render 'shared/clear' %>
<div class="grid_8">
<section class="grid_8 alpha omega">
<div class="grid_2 alpha">
<h3><%= t "views.contacts.contact.total_loan" %></h3>
<p><%= mark_amount(number_to_currency(@debts_all.total_loan(current_user))) %></p>
</div>
<div class="grid_2">
<h3><%= t "views.contacts.contact.total_debt" %></h3>
<p><%= mark_amount(number_to_currency(@debts_all.total_debt(current_user))) %></p>
</div>
<div class="grid_2 omega suffix_2">
<h3><%= t "views.contacts.contact.total_sum" %></h3>
<p><%= mark_amount(number_to_currency(@debts_all.total_sum(current_user))) %></p>
</div>
</section>
<%= render 'shared/clear' %>

<header class="grid_8 alpha omega">
<h2><%= t "views.contacts.show.header" %></h2>
</header>
<%= render 'shared/clear' %>
<section>
<%= render 'debts/table_header' %>
<%= render @debts %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/debts/_debt.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<span class="state <%= state %>"><%= t("views.debts.state.#{state}").downcase %></span>
</div>
<div class="grid_4 text <%= state %>">
<%= raw t("views.debts.info.#{debt.type(current_user)}", :amount => mark_amount(number_to_currency(debt.amount)), :contact => link_to(debt.partner(current_user).full_name, Contact.reverse_proxy(debt.partner(current_user)))) %>
<%= raw t("views.debts.info.#{debt.type(current_user)}", :amount => mark_amount(number_to_currency(debt.amount)), :contact => link_to(debt.partner(current_user).full_name, current_user.contacts.reverse_proxy(debt.partner(current_user)))) %>
</div>
<div class="grid_2 omega">
<%= link_to t("app.links.see_more"), debt, :class => "button main small" %>
Expand Down
2 changes: 1 addition & 1 deletion lib/debt_pursuit/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module DebtPursuit
module Version
MAYOR = "1"
MINOR = "0"
PATCH = "0"
PATCH = "1"

NUMBER = [MAYOR, MINOR, PATCH].join(".")

Expand Down
18 changes: 13 additions & 5 deletions test/unit/contact_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@ class ContactTest < ActiveSupport::TestCase
assert_equal contact, contact.proxy
end

test "should find contact if a friend" do
test "should find contact of a friend" do
user1 = Factory.create(:user)
user2 = Factory.create(:user)
friend = Factory.create(:user)
contact = Factory.create(:contact, :friend => friend)
contact1 = Factory.create(:contact, :user => user1, :friend => friend)
contact2 = Factory.create(:contact, :user => user2, :friend => friend)

assert_equal contact, Contact.reverse_proxy(friend)
assert_equal contact1, user1.contacts.reverse_proxy(friend)
assert_equal contact2, user2.contacts.reverse_proxy(friend)
end

test "should return contact when search for the proxy" do
user1 = Factory.create(:user)
user2 = Factory.create(:user)
friend = Factory.create(:user)
contact = Factory.create(:contact, :friend => friend)
contact1 = Factory.create(:contact, :user => user1, :friend => friend)
contact2 = Factory.create(:contact, :user => user2, :friend => friend)

assert_equal contact, Contact.reverse_proxy(contact)
assert_equal contact1, user1.contacts.reverse_proxy(contact1)
assert_equal contact2, user2.contacts.reverse_proxy(contact2)
end

test "should get polymorphic id" do
Expand Down

0 comments on commit 42b87cf

Please sign in to comment.