expense_gun 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +34 -0
  3. data/app/assets/javascripts/expense_gun/application.js +4 -0
  4. data/app/assets/stylesheets/expense_gun/application.sass +4 -0
  5. data/app/assets/stylesheets/expense_gun/expenses.sass +20 -0
  6. data/app/assets/stylesheets/expense_gun/layout.sass +2 -0
  7. data/app/controllers/expense_gun/application_controller.rb +7 -0
  8. data/app/controllers/expense_gun/expense_lines_controller.rb +64 -0
  9. data/app/controllers/expense_gun/expenses_controller.rb +107 -0
  10. data/app/helpers/expense_gun/application_helper.rb +4 -0
  11. data/app/helpers/expense_gun/form_helper.rb +11 -0
  12. data/app/models/expense_gun/ability.rb +30 -0
  13. data/app/models/expense_gun/category.rb +5 -0
  14. data/app/models/expense_gun/expense.rb +62 -0
  15. data/app/models/expense_gun/expense_line.rb +26 -0
  16. data/app/views/expense_gun/expense_lines/_form.html.slim +16 -0
  17. data/app/views/expense_gun/expense_lines/edit.html.slim +4 -0
  18. data/app/views/expense_gun/expense_lines/new.html.slim +4 -0
  19. data/app/views/expense_gun/expenses/_form.html.slim +5 -0
  20. data/app/views/expense_gun/expenses/edit.html.slim +4 -0
  21. data/app/views/expense_gun/expenses/index.html.slim +63 -0
  22. data/app/views/expense_gun/expenses/new.html.slim +4 -0
  23. data/app/views/expense_gun/expenses/show.html.slim +84 -0
  24. data/app/views/kaminari/bootstrap3/_gap.html.slim +2 -0
  25. data/app/views/kaminari/bootstrap3/_page.html.slim +6 -0
  26. data/app/views/kaminari/bootstrap3/_paginator.html.slim +8 -0
  27. data/config/cucumber.yml +8 -0
  28. data/config/initializers/formtastic.rb +78 -0
  29. data/config/routes.rb +13 -0
  30. data/db/migrate/20141201092102_create_expense_gun_expenses.rb +8 -0
  31. data/db/migrate/20141201100548_expenses_add_state.rb +5 -0
  32. data/db/migrate/20141201111528_create_expense_gun_expense_lines.rb +13 -0
  33. data/db/migrate/20141201115918_create_expense_gun_categories.rb +9 -0
  34. data/db/migrate/20141201145608_expense_lines_add_category_id.rb +5 -0
  35. data/db/migrate/20141202143656_categories_rename_tax.rb +5 -0
  36. data/db/migrate/20141202151845_expenses_add_date.rb +5 -0
  37. data/db/migrate/20141203153649_field_names_like_billing_machine.rb +7 -0
  38. data/lib/expense_gun/admin/category.rb +12 -0
  39. data/lib/expense_gun/engine.rb +9 -0
  40. data/lib/expense_gun/version.rb +3 -0
  41. data/lib/expense_gun.rb +8 -0
  42. data/lib/tasks/cucumber.rake +65 -0
  43. data/lib/tasks/expense_gun_tasks.rake +4 -0
  44. data/spec/dummy/README.rdoc +28 -0
  45. data/spec/dummy/Rakefile +6 -0
  46. data/spec/dummy/app/admin/dashboard.rb +33 -0
  47. data/spec/dummy/app/assets/javascripts/active_admin.js.coffee +1 -0
  48. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  49. data/spec/dummy/app/assets/stylesheets/active_admin.css.scss +17 -0
  50. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  51. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  52. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  53. data/spec/dummy/app/views/layouts/expense_gun/application.html.slim +20 -0
  54. data/spec/dummy/bin/bundle +3 -0
  55. data/spec/dummy/bin/rails +4 -0
  56. data/spec/dummy/bin/rake +4 -0
  57. data/spec/dummy/config/application.rb +23 -0
  58. data/spec/dummy/config/boot.rb +5 -0
  59. data/spec/dummy/config/database.yml +25 -0
  60. data/spec/dummy/config/environment.rb +5 -0
  61. data/spec/dummy/config/environments/development.rb +37 -0
  62. data/spec/dummy/config/environments/production.rb +78 -0
  63. data/spec/dummy/config/environments/test.rb +39 -0
  64. data/spec/dummy/config/initializers/active_admin.rb +233 -0
  65. data/spec/dummy/config/initializers/assets.rb +8 -0
  66. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  67. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  68. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  69. data/spec/dummy/config/initializers/inflections.rb +16 -0
  70. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  71. data/spec/dummy/config/initializers/session_store.rb +3 -0
  72. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  73. data/spec/dummy/config/locales/en.yml +23 -0
  74. data/spec/dummy/config/routes.rb +4 -0
  75. data/spec/dummy/config/secrets.yml +22 -0
  76. data/spec/dummy/config.ru +4 -0
  77. data/spec/dummy/db/schema.rb +42 -0
  78. data/spec/dummy/public/404.html +67 -0
  79. data/spec/dummy/public/422.html +67 -0
  80. data/spec/dummy/public/500.html +66 -0
  81. data/spec/dummy/public/favicon.ico +0 -0
  82. data/spec/factories/expense_gun_category.rb +7 -0
  83. data/spec/factories/expense_gun_expense.rb +11 -0
  84. data/spec/factories/expense_gun_expense_line.rb +10 -0
  85. data/spec/factories.rb +5 -0
  86. data/spec/models/category_spec.rb +12 -0
  87. data/spec/models/expense_line_spec.rb +81 -0
  88. data/spec/models/expense_spec.rb +171 -0
  89. data/spec/rails_helper.rb +52 -0
  90. data/spec/spec_helper.rb +85 -0
  91. metadata +319 -0
data/spec/factories.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "faker"
2
+
3
+ Dir.glob(File.expand_path("../factories/**/*", __FILE__)).map do |file|
4
+ require file
5
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "../rails_helper"
2
+ require "shoulda/matchers"
3
+
4
+ describe ExpenseGun::Category do
5
+ it "category factory should be valid?" do
6
+ expect(FactoryGirl.build(:category)).to be_valid
7
+ end
8
+
9
+ it "#name should be present" do
10
+ expect(FactoryGirl.build(:category)).to validate_presence_of :name
11
+ end
12
+ end
@@ -0,0 +1,81 @@
1
+ require_relative "../rails_helper"
2
+ require "shoulda/matchers"
3
+
4
+ describe ExpenseGun::ExpenseLine do
5
+ it "expense line factory should be valid?" do
6
+ expense_line = FactoryGirl.build :expense_line, expense: FactoryGirl.build(:expense)
7
+ expect(expense_line).to be_valid
8
+ end
9
+
10
+ # TODO: refactoring
11
+
12
+ it "#expense should be present" do
13
+ expect(FactoryGirl.build(:expense_line)).to validate_presence_of :expense
14
+ end
15
+
16
+ it "#category should be present" do
17
+ expect(FactoryGirl.build(:expense_line)).to validate_presence_of :category
18
+ end
19
+
20
+ it "#name should be present" do
21
+ expect(FactoryGirl.build(:expense_line)).to validate_presence_of :name
22
+ end
23
+
24
+ it "#date should be present" do
25
+ expect(FactoryGirl.build(:expense_line)).to validate_presence_of :date
26
+ end
27
+
28
+ it "#total_all_taxes should be present" do
29
+ expect(FactoryGirl.build(:expense_line)).to validate_presence_of :total_all_taxes
30
+ end
31
+
32
+ it "#total_all_taxes should be >0" do
33
+ expect(FactoryGirl.build(:expense_line)).to validate_numericality_of(:total_all_taxes).is_greater_than_or_equal_to(1.0)
34
+ end
35
+
36
+ it "#vat should be present" do
37
+ expect(FactoryGirl.build(:expense_line)).to validate_presence_of :vat
38
+ end
39
+
40
+ it "#vat should be decimal" do
41
+ expense_line = FactoryGirl.build(:expense_line, vat: 123)
42
+ expect(expense_line.valid?).to be false
43
+ expect(expense_line.vat).to be 123.0
44
+ end
45
+
46
+ it "#company_part should be present" do
47
+ expect(FactoryGirl.build(:expense_line)).to validate_presence_of :company_part
48
+ end
49
+
50
+ it "#company_part should be >=0 and <= 100" do
51
+ expect(FactoryGirl.build(:expense_line)).to validate_numericality_of(:company_part).is_greater_than_or_equal_to(1.0).is_less_than_or_equal_to(100.0)
52
+ end
53
+
54
+ it "#company_part should be 100 as default" do
55
+ expense_line = ExpenseGun::ExpenseLine.new
56
+ expect(expense_line.company_part).to be 100.0
57
+ end
58
+
59
+ it "#employee_payback should be correct" do
60
+ expense_line = ExpenseGun::ExpenseLine.new(total_all_taxes: 100, company_part: 100)
61
+ expect(expense_line.employee_payback).to be 100.0
62
+
63
+ expense_line = ExpenseGun::ExpenseLine.new(total_all_taxes: 250, company_part: 50)
64
+ expect(expense_line.employee_payback).to be 125.0
65
+
66
+ expense_line = ExpenseGun::ExpenseLine.new(total_all_taxes: 200, company_part: 80)
67
+ expect(expense_line.employee_payback).to be 160.0
68
+ end
69
+
70
+ it "#total_vat_deductible should be #vat if categorie is vat_decuctible" do
71
+ category = FactoryGirl.build(:category, vat_deductible: true)
72
+ expense_line = FactoryGirl.build(:expense_line, category: category)
73
+ expect(expense_line.total_vat_deductible).to be expense_line.vat
74
+ end
75
+
76
+ it "#total_vat_deductible should be 0 if categorie is non vat_decuctible" do
77
+ category = FactoryGirl.build(:category, vat_deductible: false)
78
+ expense_line = FactoryGirl.build(:expense_line, category: category)
79
+ expect(expense_line.total_vat_deductible).to be 0.0
80
+ end
81
+ end
@@ -0,0 +1,171 @@
1
+ require_relative "../rails_helper"
2
+ require "shoulda/matchers"
3
+
4
+ describe ExpenseGun::Expense do
5
+ it "expense factory should be valid?" do
6
+ expect(FactoryGirl.build(:expense)).to be_valid
7
+ end
8
+
9
+ it "shoud validates presence of name" do
10
+ expect(FactoryGirl.build(:expense)).to validate_presence_of :name
11
+ end
12
+
13
+ it "shoud validates presence of date" do
14
+ expect(FactoryGirl.build(:expense)).to validate_presence_of :date
15
+ end
16
+
17
+ it "default #date should be tody" do
18
+ expect(ExpenseGun::Expense.new.date).to eq Date.today
19
+ end
20
+
21
+ it "new expense should have new state" do
22
+ expect(ExpenseGun::Expense.new.current_state).to be :new
23
+ end
24
+
25
+ describe "new state" do
26
+ before :each do
27
+ @expense = FactoryGirl.build(:expense)
28
+ end
29
+
30
+ it "new expense can be submited" do
31
+ expect(@expense.submit).to be true
32
+ expect(@expense.current_state).to be :submited
33
+ end
34
+
35
+ it "new expense can't be accepted" do
36
+ expect(@expense.accept).to be false
37
+ expect(@expense.current_state).to be :new
38
+ end
39
+
40
+ it "new expense can't be refused" do
41
+ expect(@expense.refuse).to be false
42
+ expect(@expense.current_state).to be :new
43
+ end
44
+
45
+ it "new expense can be canceled" do
46
+ expect(@expense.cancel).to be true
47
+ expect(@expense.current_state).to be :canceled
48
+ end
49
+ end
50
+
51
+ describe "submited state" do
52
+ before :each do
53
+ @expense = FactoryGirl.build(:expense)
54
+ @expense.submit
55
+ end
56
+
57
+ it "submitted expense can be accepted" do
58
+ expect(@expense.accept).to be true
59
+ expect(@expense.current_state).to be :accepted
60
+ end
61
+
62
+ it "submitted expense can be refused" do
63
+ expect(@expense.refuse).to be true
64
+ expect(@expense.current_state).to be :refused
65
+ end
66
+
67
+ it "submitted expense can be canceled" do
68
+ expect(@expense.cancel).to be true
69
+ expect(@expense.current_state).to be :canceled
70
+ end
71
+ end
72
+
73
+ describe "acceped state" do
74
+ before :each do
75
+ @expense = FactoryGirl.build(:expense)
76
+ @expense.submit
77
+ @expense.accept
78
+ end
79
+
80
+ it "acceped expense can't be submited" do
81
+ expect(@expense.submit).to be false
82
+ expect(@expense.current_state).to be :accepted
83
+ end
84
+
85
+ it "acceped expense can't be refused" do
86
+ expect(@expense.refuse).to be false
87
+ expect(@expense.current_state).to be :accepted
88
+ end
89
+
90
+ it "acceped expense can be canceled" do
91
+ expect(@expense.cancel).to be true
92
+ expect(@expense.current_state).to be :canceled
93
+ end
94
+ end
95
+
96
+ describe "refused state" do
97
+ before :each do
98
+ @expense = FactoryGirl.build(:expense)
99
+ @expense.submit
100
+ @expense.refuse
101
+ end
102
+
103
+ it "refused expense can't be submited" do
104
+ expect(@expense.submit).to be false
105
+ expect(@expense.current_state).to be :refused
106
+ end
107
+
108
+ it "refused expense can't be acceped" do
109
+ expect(@expense.accept).to be false
110
+ expect(@expense.current_state).to be :refused
111
+ end
112
+
113
+ it "refused expense can't be canceled" do
114
+ expect(@expense.cancel).to be false
115
+ expect(@expense.current_state).to be :refused
116
+ end
117
+ end
118
+
119
+ describe "canceled state" do
120
+ before :each do
121
+ @expense = FactoryGirl.build(:expense)
122
+ @expense.cancel
123
+ end
124
+
125
+ it "canceled expense can't be submited" do
126
+ expect(@expense.submit).to be false
127
+ expect(@expense.current_state).to be :canceled
128
+ end
129
+
130
+ it "canceled expense can't be acceped" do
131
+ expect(@expense.accept).to be false
132
+ expect(@expense.current_state).to be :canceled
133
+ end
134
+
135
+ it "canceled expense can't be refused" do
136
+ expect(@expense.refuse).to be false
137
+ expect(@expense.current_state).to be :canceled
138
+ end
139
+ end
140
+
141
+ it "#total_all_taxes should return sum of lines" do
142
+ expense = FactoryGirl.build(:expense, expense_lines: [])
143
+ expense.expense_lines << FactoryGirl.build(:expense_line, total_all_taxes: 10)
144
+ expense.expense_lines << FactoryGirl.build(:expense_line, total_all_taxes: 10)
145
+ expect(expense.total_all_taxes).to be 20.0
146
+ end
147
+
148
+ it "#total_employee_payback should return sum of lines" do
149
+ expense = FactoryGirl.build(:expense, expense_lines: [])
150
+ expense.expense_lines << FactoryGirl.build(:expense_line, total_all_taxes: 10, company_part: 100)
151
+ expense.expense_lines << FactoryGirl.build(:expense_line, total_all_taxes: 10, company_part: 50)
152
+ expect(expense.total_employee_payback).to be 15.0
153
+ end
154
+
155
+ it "#total_vat_deductible should return sum of lines" do
156
+ expense = FactoryGirl.build(:expense, expense_lines: [])
157
+ category1 = FactoryGirl.build(:category, vat_deductible: true)
158
+ category2 = FactoryGirl.build(:category, vat_deductible: false)
159
+ expense.expense_lines << FactoryGirl.build(:expense_line, vat: 10, category: category1)
160
+ expense.expense_lines << FactoryGirl.build(:expense_line, vat: 10, category: category2)
161
+ expect(expense.total_vat_deductible).to be 10.0
162
+ end
163
+
164
+ it "#may_edit? should return false unless expense is not submited" do
165
+ expect(ExpenseGun::Expense.new(state: :new).may_edit?).to be true
166
+ expect(ExpenseGun::Expense.new(state: :submited).may_edit?).to be false
167
+ expect(ExpenseGun::Expense.new(state: :acceped).may_edit?).to be false
168
+ expect(ExpenseGun::Expense.new(state: :refused).may_edit?).to be false
169
+ expect(ExpenseGun::Expense.new(state: :canceled).may_edit?).to be false
170
+ end
171
+ end
@@ -0,0 +1,52 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] = 'test'
3
+ require 'spec_helper'
4
+ require File.expand_path("../dummy/config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+ # Add additional requires below this line. Rails is not loaded until this point!
7
+
8
+ require_relative "factories.rb"
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc, in
11
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12
+ # run as spec files by default. This means that files in spec/support that end
13
+ # in _spec.rb will both be required and run as specs, causing the specs to be
14
+ # run twice. It is recommended that you do not name files matching this glob to
15
+ # end with _spec.rb. You can configure this pattern with the --pattern
16
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17
+ #
18
+ # The following line is provided for convenience purposes. It has the downside
19
+ # of increasing the boot-up time by auto-requiring all files in the support
20
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
21
+ # require only the support files necessary.
22
+ #
23
+ # Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
24
+
25
+ # Checks for pending migrations before tests are run.
26
+ # If you are not using ActiveRecord, you can remove this line.
27
+ ActiveRecord::Migration.maintain_test_schema!
28
+
29
+ RSpec.configure do |config|
30
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
31
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
32
+
33
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
34
+ # examples within a transaction, remove the following line or assign false
35
+ # instead of true.
36
+ config.use_transactional_fixtures = true
37
+
38
+ # RSpec Rails can automatically mix in different behaviours to your tests
39
+ # based on their file location, for example enabling you to call `get` and
40
+ # `post` in specs under `spec/controllers`.
41
+ #
42
+ # You can disable this behaviour by removing the line below, and instead
43
+ # explicitly tag your specs with their type, e.g.:
44
+ #
45
+ # RSpec.describe UsersController, :type => :controller do
46
+ # # ...
47
+ # end
48
+ #
49
+ # The different available types are documented in the features, such as in
50
+ # https://relishapp.com/rspec/rspec-rails/docs
51
+ config.infer_spec_type_from_file_location!
52
+ end
@@ -0,0 +1,85 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # Many RSpec users commonly either run the entire suite or an individual
59
+ # file, and it's useful to allow more verbose output when running an
60
+ # individual spec file.
61
+ if config.files_to_run.one?
62
+ # Use the documentation formatter for detailed output,
63
+ # unless a formatter has already been configured
64
+ # (e.g. via a command-line flag).
65
+ config.default_formatter = 'doc'
66
+ end
67
+
68
+ # Print the 10 slowest examples and example groups at the
69
+ # end of the spec run, to help surface which specs are running
70
+ # particularly slow.
71
+ config.profile_examples = 10
72
+
73
+ # Run specs in random order to surface order dependencies. If you find an
74
+ # order dependency and want to debug it, you can fix the order by providing
75
+ # the seed, which is printed after each run.
76
+ # --seed 1234
77
+ config.order = :random
78
+
79
+ # Seed global randomization in this process using the `--seed` CLI option.
80
+ # Setting this allows you to use `--seed` to deterministically reproduce
81
+ # test failures related to randomization by passing the same `--seed` value
82
+ # as the one that triggered the failure.
83
+ Kernel.srand config.seed
84
+ =end
85
+ end