Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add invoice list sum with cucumber test

  • Loading branch information...
commit c422e5f40742e1e0d339a9bf4d72b3513851d9ed 1 parent 46288df
@grobie authored
View
2  app/models/doc.rb
@@ -2,7 +2,7 @@ class Doc < StoredFile
set_table_name "stored_files"
has_attachment :content_type => 'application/msword',
:max_size => 3.megabytes,
- :storage => :s3,
+ :storage => RAILS_ENV == 'production' ? :s3 : :file_system,
:s3_access => :private
validates_as_attachment
View
1  app/models/invoice.rb
@@ -7,6 +7,7 @@ class Invoice < ActiveRecord::Base
validates_numericality_of :invoice_num
validates_uniqueness_of :invoice_num
validates_presence_of :customer
+ validates_presence_of :date
validates_associated :pdf, :if => :pdf
validates_associated :doc, :if => :doc
View
2  app/models/pdf.rb
@@ -1,7 +1,7 @@
class Pdf < StoredFile
has_attachment :content_type => 'application/pdf',
:max_size => 3.megabytes,
- :storage => :s3,
+ :storage => RAILS_ENV == 'production' ? :s3 : :file_system,
:s3_access => :private
validates_as_attachment
View
5 app/views/invoices/_invoices.html.erb
@@ -20,4 +20,9 @@
<td><%= link_to 'Löschen', invoice, :confirm => 'Sind Sie sicher?', :method => :delete %></td>
</tr>
<%- end -%>
+ <tr>
+ <td colspan="2"></td>
+ <td class="right"><%= number_to_currency_with_euro invoices.sum(:sum) %></td>
+ <td colspan="3"></td>
+ </tr>
</table>
View
25 features/invoice_list_sum.feature
@@ -0,0 +1,25 @@
+Feature: Show the sum of all invoices
+ As a client
+ I want to see the sum of all invoices per year
+
+Scenario Outline: show sum
+ Given a invoice list consisting of invoice <amounts>
+ And I am logged in
+ When I go to invoice list
+ Then I should see the sum <sum>
+
+ Scenarios: one invoice
+ | amounts | sum |
+ | 1 | 1,00 € |
+ | 512 | 512,00 € |
+ Scenarios: two invoices
+ | amounts | sum |
+ | 1 4 | 5,00 € |
+ | 5 8 | 13,00 € |
+ | 512 1024 | 1.536,00 € |
+ Scenarios: three invoices
+ | amounts | sum |
+ | 75 3012 8 | 3.095,00 € |
+ | 11 90 | 101,00 € |
+ | 25 6 64 | 95,00 € |
+
View
10 features/step_definitions/invoice_list_sum_steps.rb
@@ -0,0 +1,10 @@
+Given /^a invoice list consisting of invoice ([\d ]+)$/ do |amounts|
+ customer = Customer.create(:customer_num => 1, :company_name => "dummy")
+ amounts.split(" ").each_with_index do |amount, i|
+ Invoice.create(:customer => customer, :invoice_num => i, :sum => amount, :date => Time.now)
+ end
+end
+
+Then /^I should see the sum ([\d ,\.€]+)$/ do |sum|
+ response.should contain(sum)
+end
View
16 features/step_definitions/session_steps.rb
@@ -0,0 +1,16 @@
+Given /^I am logged in$/ do
+ current_user = User.create(
+ :login => 'testuser',
+ :email => 'test@user.com',
+ :password => '123456',
+ :password_confirmation => '123456')
+ current_user.activate!
+
+
+ visit login_url
+ fill_in("login", :with => "testuser")
+ fill_in("password", :with => "123456")
+ click_button("Anmelden")
+ response.body.should =~ /Erfolgreich angemeldet./m
+end
+
View
4 features/support/paths.rb
@@ -8,8 +8,8 @@ module NavigationHelpers
def path_to(page_name)
case page_name
- when /the homepage/
- '/'
+ when /the homepage/ then '/'
+ when /invoice list/ then invoices_url()
# Add more mappings here.
# Here is a more fancy example:
Please sign in to comment.
Something went wrong with that request. Please try again.