diff --git a/app/controllers/invoices_controller.rb b/app/controllers/invoices_controller.rb index 0f3606de..a0f67af7 100644 --- a/app/controllers/invoices_controller.rb +++ b/app/controllers/invoices_controller.rb @@ -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? diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb index 469edf26..225e982f 100644 --- a/app/views/carts/show.html.erb +++ b/app/views/carts/show.html.erb @@ -29,11 +29,14 @@

Invoice info

<%= simple_format(@cart.user.invoice_info) %>

-<% if admin? and @cart.is_purchased? %> -

Invoice

- <% if @cart.invoice %> - <%= link_to 'Download invoice', @cart.invoice.url_path %> - <% else %> - <%= link_to 'Create invoice', invoices_path( :id => @cart.id ), :method => 'post' %> + +<% if false %> + <% if admin? and @cart.is_purchased? %> +

Invoice

+ <% 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 %> \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index a8622460..b7fe7a2c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -50,6 +50,7 @@

<%= link_to "http://github.com/#{@user.github_user}", "http://github.com/#{@user.github_user}" %> (github account)

<% end %> + <% if admin_or_current_user?( @user ) && !@user.carts.purchased.empty? %>
Your purchases
- <% end %> \ No newline at end of file diff --git a/test/functional/invoices_controller_test.rb b/test/functional/invoices_controller_test.rb index 8cfa40f0..978b10a4 100644 --- a/test/functional/invoices_controller_test.rb +++ b/test/functional/invoices_controller_test.rb @@ -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 \ No newline at end of file