adherent 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/adherent/jcmenu.css +5 -0
  3. data/app/controllers/adherent/allpayments_controller.rb +1 -1
  4. data/app/controllers/adherent/application_controller.rb +12 -0
  5. data/app/controllers/adherent/members_controller.rb +6 -7
  6. data/app/controllers/adherent/payments_controller.rb +2 -2
  7. data/app/helpers/adherent/application_helper.rb +9 -5
  8. data/app/helpers/adherent/payments_helper.rb +2 -2
  9. data/app/models/adherent/member.rb +77 -9
  10. data/app/models/adherent/payment.rb +0 -10
  11. data/app/views/adherent/allpayments/_payment.html.haml +3 -2
  12. data/app/views/adherent/members/index.html.erb +7 -1
  13. data/app/views/adherent/payments/_payment.html.haml +3 -2
  14. data/app/views/adherent/payments/show.html.haml +2 -2
  15. data/lib/adherent/version.rb +2 -1
  16. data/spec/controllers/adherent/adhesions_controller_spec.rb +25 -57
  17. data/spec/controllers/adherent/allpayments_controller_spec.rb +4 -1
  18. data/spec/controllers/adherent/members_controller_spec.rb +33 -46
  19. data/spec/controllers/adherent/payments_controller_spec.rb +18 -31
  20. data/spec/dummy/log/development.log +21002 -0
  21. data/spec/dummy/log/test.log +135111 -0
  22. data/spec/dummy/tmp/cache/assets/test/sprockets/8259f3fc885403b4eea8dd12964c2ffc +0 -0
  23. data/spec/dummy/tmp/cache/assets/test/sprockets/c35251b000451b1b9f7274e0ae471704 +0 -0
  24. data/spec/dummy/tmp/cache/assets/test/sprockets/d88c0d3362ebdb47849b797a3ec1b355 +0 -0
  25. data/spec/dummy/tmp/cache/assets/test/sprockets/ee6531726dfe6592fa84b42a420b6acd +0 -0
  26. data/spec/dummy/tmp/cache/assets/test/sprockets/fca89522784c8592001dc314a2361344 +0 -0
  27. data/spec/features/adhesions_spec.rb +3 -9
  28. data/spec/features/coord_spec.rb +3 -5
  29. data/spec/features/js_spec.rb +17 -15
  30. data/spec/features/members_spec.rb +26 -46
  31. data/spec/features/payments_spec.rb +15 -39
  32. data/spec/features/reglements_spec.rb +25 -31
  33. data/spec/models/adherent/adhesion_spec.rb +18 -40
  34. data/spec/models/adherent/coord_spec.rb +12 -9
  35. data/spec/models/adherent/member_spec.rb +144 -92
  36. data/spec/models/adherent/payment_spec.rb +20 -99
  37. data/spec/models/adherent/reglement_spec.rb +1 -1
  38. data/spec/rails_helper.rb +2 -1
  39. data/spec/spec_helper.rb +1 -0
  40. metadata +1 -6
  41. data/app/models/adherent/query_member.rb +0 -125
  42. data/spec/models/adherent/query_member_spec.rb +0 -169
  43. data/spec/support/fixtures.rb +0 -29
@@ -1,125 +0,0 @@
1
- require 'csv'
2
-
3
- module Adherent
4
- # La classe QueryMember s'appuie sur une view de SQL appelée
5
- # adherent_query_members.
6
- #
7
- # Elle reprend les principaux éléments de Member (organism_id, id, name,
8
- # forname, birthdate, et rajoute la date de la dernière adhésion (champ
9
- # m_to_date), le montant total des adhésions dues (t_adhesions) et le montant
10
- # total des règlements (t_reglements).
11
- #
12
- # Ces deux derniers champs sont utilisés pour savoir si le membre est à
13
- # jour de ses paiements (méthode #a_jour?)
14
- #
15
- class QueryMember < ActiveRecord::Base
16
-
17
- def self.columns() @columns ||= []; end
18
-
19
- def self.column(name, sql_type = nil, default = nil, null = true)
20
- columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
21
- end
22
-
23
- column :id, :integer
24
- column :organism_id, :integer
25
- column :number, :string
26
- column :name, :string
27
- column :mail, :string
28
- column :tel, :string
29
- column :gsm, :string
30
- column :office, :string
31
- column :address, :string
32
- column :zip, :string
33
- column :city, :string
34
- column :forname, :string
35
- column :birthdate, :date
36
- column :m_to_date, :date
37
- column :t_adhesions, :decimal
38
- column :t_reglements, :decimal
39
-
40
-
41
- # juste pour avoir la remise en forme du champ birthdate
42
- # pour l'affichage
43
- pick_date_for :birthdate
44
-
45
- # booléen indiquant si l'adhérent est à jour de ces cotisations
46
- def a_jour?
47
- montant_du <= 0.001
48
- end
49
-
50
- def self.query_sql(organism)
51
- %Q(SELECT adherent_members.id, organism_id, number, name, forname, birthdate,
52
- adherent_coords.mail AS mail,
53
- adherent_coords.tel AS tel,
54
- adherent_coords.gsm AS gsm,
55
- adherent_coords.office AS office,
56
- adherent_coords.address AS address,
57
- adherent_coords.zip AS zip,
58
- adherent_coords.city AS city,
59
- (SELECT to_date FROM adherent_adhesions
60
- WHERE adherent_adhesions.member_id = adherent_members.id
61
- ORDER BY to_date DESC LIMIT 1 ) AS m_to_date,
62
- (SELECT SUM(adherent_reglements.amount) FROM adherent_reglements,
63
- adherent_adhesions
64
- WHERE adherent_reglements.adhesion_id = adherent_adhesions.id AND
65
- adherent_adhesions.member_id = adherent_members.id) AS t_reglements,
66
- (SELECT SUM(amount) FROM adherent_adhesions
67
- WHERE adherent_adhesions.member_id = adherent_members.id) AS t_adhesions
68
- FROM adherent_members
69
-
70
- LEFT JOIN adherent_coords ON adherent_members.id = adherent_coords.member_id
71
- WHERE organism_id = #{organism.id};
72
- )
73
- end
74
-
75
- def self.query_members(organism)
76
- find_by_sql(query_sql(organism))
77
- end
78
-
79
- # ici on aurait pu utiliser pick_date_for mais cela pose le problème
80
- # des dates non remplies. Ce qui a son tour est gênant pour le tri dans
81
- # les tables.
82
- def m_to_date
83
- td = read_attribute(:m_to_date)
84
- td.is_a?(Date) ? (I18n::l td) : '31/12/2099'
85
- end
86
-
87
- # montant dû par l'adhérent pour ses adhésions
88
- def montant_du
89
- tadh = t_adhesions ? BigDecimal.new(t_adhesions, 2) : BigDecimal.new(0.0, 2)
90
- treg = t_reglements ? BigDecimal.new(t_reglements, 2) : BigDecimal.new(0.0, 2)
91
- tadh - treg
92
- end
93
-
94
- # edition en csv des membres d'un organisme dont l'id est
95
- # transmis en argument
96
- def self.to_csv(organism, options = {col_sep:"\t"})
97
- ms = query_members(organism)
98
- CSV.generate(options) do |csv|
99
- csv << ['Numero', 'Nom', 'Prénom', 'Date de naissance',
100
- 'Mail', 'Tél', 'Gsm', 'Bureau', 'Adresse', 'Code Postal', 'Ville', 'Doit', 'Fin Adh.']
101
- ms.each do |m|
102
- csv << [m.number, m.name, m.forname, m.birthdate, m.mail, m.tel,
103
- m.gsm, m.office, m.address, m.zip, m.city,
104
- ActiveSupport::NumberHelper.number_to_rounded(m.montant_du, precision:2),
105
- m.m_to_date]
106
- end
107
- end
108
- end
109
-
110
- # Pour avoir l'encodage Windows, voir à mettre dans un module si
111
- # répété avec d'autres modèles
112
- def self.to_xls(organism, options = {col_sep:"\t"})
113
- to_csv(organism, options).encode("windows-1252")
114
- end
115
-
116
-
117
-
118
- protected
119
-
120
- # forcément car basé sur une view sql
121
- def readonly?
122
- true
123
- end
124
- end
125
- end
@@ -1,169 +0,0 @@
1
- # coding utf-8
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.configure do |c|
6
- # c.exclusion_filter = {js:true}
7
- # c.filter = {wip:true}
8
- end
9
-
10
-
11
- describe Adherent::QueryMember, :type => :model do
12
-
13
- def valid_attributes
14
- {name:'Dupont', forname:'Jules', number:'Adh 001',
15
- birthdate:Date.civil(1955,6,6)}
16
- end
17
-
18
- let(:org) {double(Organism, id:1)}
19
-
20
- before(:each) do
21
- @m = Adherent::Member.new(valid_attributes)
22
- @m.organism_id = 1
23
- @m.save!
24
- @m.build_coord(tel:'01.02.03.04.05', mail:'bonjour@example.com')
25
- @m.save
26
- end
27
-
28
- after(:each) do
29
- Adherent::Member.delete_all
30
- Adherent::Coord.delete_all
31
- end
32
-
33
- it 'on peut initier un query_member' do
34
- expect(Adherent::QueryMember.query_members(org).size).to eq(1)
35
- end
36
-
37
- it 'dont les champs sont corrects' do
38
- m = Adherent::QueryMember.query_members(org).first
39
- expect(m.birthdate).to eq('06/06/1955')
40
- expect(m.name).to eq(@m.name)
41
- expect(m.forname).to eq(@m.forname)
42
- expect(m.tel).to eq(@m.coord.tel)
43
- expect(m.mail).to eq(@m.coord.mail)
44
-
45
- end
46
-
47
- context 'avec deux adhésions' do
48
-
49
- before(:each) do
50
- d = Date.today.beginning_of_year
51
- @m.adhesions.new(from_date:d, to_date:(d>>1) -1, amount:12.25)
52
- @m.adhesions.new(from_date:(d>>1), to_date:(d>>2)-1, amount:10.01)
53
- @m.save
54
-
55
- end
56
-
57
- it 'donne la bonne fin d adhésion' do
58
- m = Adherent::QueryMember.query_members(org).first
59
- expect(m.m_to_date).to eq(I18n::l((Date.today.beginning_of_year>>2) -1))
60
- end
61
-
62
- context 'avec des règlements' do
63
-
64
- before(:each) do
65
- @p = @m.payments.new(date:Date.today, amount:8, mode:'CB')
66
- allow(@p).to receive(:correct_range_date).and_return true
67
- @p.save
68
-
69
-
70
- end
71
-
72
- after(:each) do
73
- Adherent::Reglement.delete_all
74
- Adherent::Adhesion.delete_all
75
- Adherent::Payment.delete_all
76
-
77
- end
78
-
79
- it 'le membre doit encore 14.26 ' do
80
- m = Adherent::QueryMember.query_members(org).first
81
- expect(m.t_reglements).to eq(8)
82
- expect(m.t_adhesions).to eq(22.26)
83
- expect(m.montant_du).to eq(14.26)
84
- end
85
-
86
- it 'après un paiement de 10.26 €, il doit encore 4' do
87
- @p = @m.payments.new(date:Date.today, amount:10.26, mode:'CB')
88
- allow(@p).to receive(:correct_range_date).and_return true
89
- @p.save
90
- m = Adherent::QueryMember.query_members(org).first
91
- expect(m.montant_du).to eq(4)
92
- expect(m.a_jour?).to be false
93
- end
94
-
95
- it 'avec de paiements, l un de 10, l autre de 14.26 € il ne doit plus rien' do
96
- @p = @m.payments.new(date:Date.today, amount:10, mode:'CB')
97
- @q = @m.payments.new(date:Date.today, amount:14.26, mode:'CB')
98
- allow(@p).to receive(:correct_range_date).and_return true
99
- allow(@q).to receive(:correct_range_date).and_return true
100
- @p.save; @q.save
101
- m = Adherent::QueryMember.query_members(org).first
102
- expect(m.montant_du).to eq(0)
103
- expect(m.a_jour?).to be true
104
- end
105
-
106
- it 's il paye plus il ne doit rien non plus' do
107
- @p = @m.payments.new(date:Date.today, amount:25, mode:'CB')
108
-
109
- allow(@p).to receive(:correct_range_date).and_return true
110
-
111
- @p.save
112
- m = Adherent::QueryMember.query_members(org).first
113
- expect(m.montant_du).to eq(0)
114
- expect(m.a_jour?).to be true
115
- end
116
-
117
-
118
- end
119
-
120
-
121
- describe 'export' do
122
-
123
- def two_lines
124
- [Adherent::QueryMember.new(number:'Adh 001', name:'Dupont', forname:'Jules',
125
- birthdate:Date.civil(1955,6,6), mail:'bonjour@example.com',
126
- tel:'01.02.03.04.05', t_adhesions:22.26, t_reglements:0,
127
- office:'03.20.14.64.30',
128
- zip:'59000',
129
- address:'Place de la Mairie',
130
- city:'LILLE',
131
- m_to_date:((Date.today.beginning_of_year >> 2) -1))
132
- ]
133
- end
134
-
135
-
136
- describe 'to_csv' do
137
-
138
- before(:each) do
139
- @organism = double(Organism, id:1)
140
- allow(Adherent::QueryMember).to receive(:query_members).with(@organism).
141
- and_return(two_lines)
142
- csv = Adherent::QueryMember.to_csv(@organism)
143
- @lignes = csv.split("\n")
144
- end
145
- it 'la ligne de titre' do
146
- expect(@lignes[0]).to eq("Numero\tNom\tPrénom\tDate de naissance\tMail\tTél\tGsm\tBureau\tAdresse\tCode Postal\tVille\tDoit\tFin Adh.")
147
- end
148
-
149
- it 'une ligne de valeurs' do
150
- expect(@lignes[1]).to eq("Adh 001\tDupont\tJules\t06/06/1955\tbonjour@example.com\t01.02.03.04.05\t\t03.20.14.64.30\tPlace de la Mairie\t59000\tLILLE\t22,26\t#{I18n::l((Date.today.beginning_of_year>>2) -1)}")
151
- end
152
-
153
- end
154
-
155
- describe 'to_xls' do
156
- before(:each) do
157
- @organism = double(Organism, id:1)
158
- allow(Adherent::QueryMember).to receive(:query_members).with(@organism).
159
- and_return(two_lines)
160
- end
161
-
162
- it 'to_xls doit marcher également' do
163
- expect {Adherent::QueryMember.to_xls(@organism)}.not_to raise_error
164
- end
165
- end
166
- end
167
- end
168
-
169
- end
@@ -1,29 +0,0 @@
1
- # coding utf-8
2
-
3
- # ce module a pour objet de fournir quelques méthodes pour créer des
4
- # enregistrements utilisés dans les requests
5
- module Fixtures
6
-
7
- def create_organism
8
- @organism = Organism.find_or_create_by(title:'Mon association')
9
- end
10
-
11
- # crée des membres, 5 étant le nombre par défaut. Il est possible d'avoir un
12
- # nombre différent en fournissant en argument un nombre quelconque.
13
- def create_members(n = 5)
14
- Adherent::Member.delete_all
15
- create_organism unless @organism
16
- n.times do |i|
17
- m = Adherent::Member.new(name:"Nom_#{i}", forname:'le prénom', number:"Adh00#{i}")
18
- m.organism_id = @organism.id
19
- puts m.errors.messages unless m.valid?
20
- m.save!
21
- end
22
- @members = Adherent::Member.all
23
- end
24
-
25
- def create_payment(member, amount=50)
26
- member.payments.create!(amount:amount, date:Date.today,
27
- mode:'CB')
28
- end
29
- end