Skip to content

Commit

Permalink
closing invoice creation
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillen committed Jun 23, 2009
1 parent 883e9e9 commit 55489eb
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 72 deletions.
6 changes: 6 additions & 0 deletions app/controllers/invoices_controller.rb
Expand Up @@ -5,6 +5,12 @@ def create
@cart = Cart.find( params[:id] ) if admin?
@cart = current_user.carts.find( params[:id] ) if !admin?

# fguillen 2009-06-23:
# closing the invoice creation
flash[:alert] = 'Invoice generation proccess has been closed.'
redirect_to :controller => 'carts', :action => 'show', :id => @cart
return

record_not_found and return unless @cart.is_purchased?
record_not_found and return unless @cart.invoice.nil?

Expand Down
15 changes: 9 additions & 6 deletions app/views/carts/show.html.erb
Expand Up @@ -29,11 +29,14 @@
<h4>Invoice info</h4>
<p><%= simple_format(@cart.user.invoice_info) %></p>

<% if admin? and @cart.is_purchased? %>
<h4>Invoice</h4>
<% if @cart.invoice %>
<%= link_to 'Download invoice', @cart.invoice.url_path %>
<% else %>
<%= link_to 'Create invoice', invoices_path( :id => @cart.id ), :method => 'post' %>
<!-- Invoice creation closed -->
<% if false %>
<% if admin? and @cart.is_purchased? %>
<h4>Invoice</h4>
<% if @cart.invoice %>
<%= link_to 'Download invoice', @cart.invoice.url_path %>
<% else %>
<%= link_to 'Create invoice', invoices_path( :id => @cart.id ), :method => 'post' %>
<% end %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Expand Up @@ -50,6 +50,7 @@
<p><%= link_to "http://github.com/#{@user.github_user}", "http://github.com/#{@user.github_user}" %> <span class="tip">(github account)</span></p>
<% end %>
<% if admin_or_current_user?( @user ) && !@user.carts.purchased.empty? %>
<h6>Your purchases</h6>
<ul>
Expand All @@ -64,7 +65,6 @@
</li>
<% end %>
</ul>

<% end %>

</div>
133 changes: 68 additions & 65 deletions test/functional/invoices_controller_test.rb
Expand Up @@ -4,69 +4,72 @@ class InvoicesControllerTest < ActionController::TestCase
def setup
end

def test_on_create
@user = users(:user1)
login_as @user

cart = Factory(:cart, :user => @user, :status => Cart::STATUS[:COMPLETED] )
cart.update_attribute( :invoice_info, "My Compaty\nMy street" )

4.times do
cart.events << Factory(:event)
end

assert_difference('Invoice.count', 1) do
post(
:create,
:id => cart.id
)
end

assert_redirected_to cart_path( cart )
end

def test_on_create_with_not_logged_user_should_response_302
@user = users(:user1)
cart = Factory(:cart, :user => @user, :status => Cart::STATUS[:COMPLETED] )

assert_difference('Invoice.count', 0) do
post(
:create,
:id => cart.id
)
end
assert_redirected_to new_session_path
end

def test_on_create_with_not_admin_not_owner_cart_should_response_404
@user = users(:user1)
login_as users(:user2)

cart = Factory(:cart, :user => @user, :status => Cart::STATUS[:COMPLETED] )

assert_difference('Invoice.count', 0) do
post(
:create,
:id => cart.id
)
end

assert_response 404
end

def test_on_create_with_admin_not_owner_cart_should_create_invoice
@user = users(:user1)
login_as users(:user_admin)

cart = Factory(:cart, :user => @user, :status => Cart::STATUS[:COMPLETED] )

assert_difference('Invoice.count', 1) do
post(
:create,
:id => cart.id
)
end

assert_redirected_to cart_path( cart )
end
# fguillen 2009-06-23:
# invoice creation closed
#
# def test_on_create
# @user = users(:user1)
# login_as @user
#
# cart = Factory(:cart, :user => @user, :status => Cart::STATUS[:COMPLETED] )
# cart.update_attribute( :invoice_info, "My Compaty\nMy street" )
#
# 4.times do
# cart.events << Factory(:event)
# end
#
# assert_difference('Invoice.count', 1) do
# post(
# :create,
# :id => cart.id
# )
# end
#
# assert_redirected_to cart_path( cart )
# end
#
# def test_on_create_with_not_logged_user_should_response_302
# @user = users(:user1)
# cart = Factory(:cart, :user => @user, :status => Cart::STATUS[:COMPLETED] )
#
# assert_difference('Invoice.count', 0) do
# post(
# :create,
# :id => cart.id
# )
# end
# assert_redirected_to new_session_path
# end
#
# def test_on_create_with_not_admin_not_owner_cart_should_response_404
# @user = users(:user1)
# login_as users(:user2)
#
# cart = Factory(:cart, :user => @user, :status => Cart::STATUS[:COMPLETED] )
#
# assert_difference('Invoice.count', 0) do
# post(
# :create,
# :id => cart.id
# )
# end
#
# assert_response 404
# end
#
# def test_on_create_with_admin_not_owner_cart_should_create_invoice
# @user = users(:user1)
# login_as users(:user_admin)
#
# cart = Factory(:cart, :user => @user, :status => Cart::STATUS[:COMPLETED] )
#
# assert_difference('Invoice.count', 1) do
# post(
# :create,
# :id => cart.id
# )
# end
#
# assert_redirected_to cart_path( cart )
# end
end

0 comments on commit 55489eb

Please sign in to comment.