adherent 0.3.4 → 0.3.5
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.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/adherent/jcmenu.css +5 -0
- data/app/controllers/adherent/allpayments_controller.rb +1 -1
- data/app/controllers/adherent/application_controller.rb +12 -0
- data/app/controllers/adherent/members_controller.rb +6 -7
- data/app/controllers/adherent/payments_controller.rb +2 -2
- data/app/helpers/adherent/application_helper.rb +9 -5
- data/app/helpers/adherent/payments_helper.rb +2 -2
- data/app/models/adherent/member.rb +77 -9
- data/app/models/adherent/payment.rb +0 -10
- data/app/views/adherent/allpayments/_payment.html.haml +3 -2
- data/app/views/adherent/members/index.html.erb +7 -1
- data/app/views/adherent/payments/_payment.html.haml +3 -2
- data/app/views/adherent/payments/show.html.haml +2 -2
- data/lib/adherent/version.rb +2 -1
- data/spec/controllers/adherent/adhesions_controller_spec.rb +25 -57
- data/spec/controllers/adherent/allpayments_controller_spec.rb +4 -1
- data/spec/controllers/adherent/members_controller_spec.rb +33 -46
- data/spec/controllers/adherent/payments_controller_spec.rb +18 -31
- data/spec/dummy/log/development.log +21002 -0
- data/spec/dummy/log/test.log +135111 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/8259f3fc885403b4eea8dd12964c2ffc +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/c35251b000451b1b9f7274e0ae471704 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d88c0d3362ebdb47849b797a3ec1b355 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/ee6531726dfe6592fa84b42a420b6acd +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/fca89522784c8592001dc314a2361344 +0 -0
- data/spec/features/adhesions_spec.rb +3 -9
- data/spec/features/coord_spec.rb +3 -5
- data/spec/features/js_spec.rb +17 -15
- data/spec/features/members_spec.rb +26 -46
- data/spec/features/payments_spec.rb +15 -39
- data/spec/features/reglements_spec.rb +25 -31
- data/spec/models/adherent/adhesion_spec.rb +18 -40
- data/spec/models/adherent/coord_spec.rb +12 -9
- data/spec/models/adherent/member_spec.rb +144 -92
- data/spec/models/adherent/payment_spec.rb +20 -99
- data/spec/models/adherent/reglement_spec.rb +1 -1
- data/spec/rails_helper.rb +2 -1
- data/spec/spec_helper.rb +1 -0
- metadata +1 -6
- data/app/models/adherent/query_member.rb +0 -125
- data/spec/models/adherent/query_member_spec.rb +0 -169
- data/spec/support/fixtures.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9453a892990d0b8f648539d14f09ba379a24067
|
4
|
+
data.tar.gz: 3fb67efc34fd4e646e8243fa3b7d5ef33934673d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7a94e6b21b12fbe84b25352282c773a0aa7866b86c1479505a30bc51ac3bbd724f4f52d2a92fbd22a3ae11deb824bb5bb4d22f9425acd807d9438ca00eb088a
|
7
|
+
data.tar.gz: 6ac210132b30cc57195784567bfc49f6a193f0f08f5b65b02c5e5715b06503507476c92e2c72211b4aa93ab9ff3f32dc9a0a0a600a5e481c04108ae0ec4c45a5
|
@@ -3,6 +3,8 @@
|
|
3
3
|
# ainsi que la gestion des sessions et notamment la méthode find_organism
|
4
4
|
class Adherent::ApplicationController < ApplicationController
|
5
5
|
|
6
|
+
before_filter :spec_organism
|
7
|
+
|
6
8
|
# met en forme une date au format dd-mmm-yyyy en retirant le point
|
7
9
|
# par exemple 13-nov-2013 (et non 13-nov.-2016), ceci pour pouvoir
|
8
10
|
# facilement inclure la date dans le nom d'un fichier
|
@@ -10,6 +12,16 @@ class Adherent::ApplicationController < ApplicationController
|
|
10
12
|
I18n.l(date, format:'%d-%b-%Y').gsub('.', '')
|
11
13
|
end
|
12
14
|
|
15
|
+
private
|
16
|
+
|
17
|
+
# ne sert qu'à instancier @organism dans les tests
|
18
|
+
def spec_organism
|
19
|
+
if Rails.env == 'test'
|
20
|
+
@organism ||= Organism.first
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
13
25
|
|
14
26
|
|
15
27
|
|
@@ -5,22 +5,21 @@ require_dependency "adherent/application_controller"
|
|
5
5
|
module Adherent
|
6
6
|
class MembersController < ApplicationController
|
7
7
|
|
8
|
+
|
8
9
|
before_filter :find_member, :except=>[:index, :create, :new]
|
9
10
|
|
10
11
|
|
11
12
|
# GET /members
|
12
13
|
# GET /members.json
|
13
14
|
def index
|
14
|
-
|
15
|
-
|
16
15
|
|
17
16
|
respond_to do |format|
|
18
|
-
format.html {@members = Adherent::
|
17
|
+
format.html {@members = Adherent::Member.query_members(@organism) }
|
19
18
|
# index.html.erb
|
20
|
-
format.csv { send_data Adherent::
|
19
|
+
format.csv { send_data Adherent::Member.to_csv(@organism),
|
21
20
|
:filename=>"#{@organism.title}-#{dashed_date(Date.today)}-Membres.csv" }
|
22
21
|
|
23
|
-
format.xls { send_data Adherent::
|
22
|
+
format.xls { send_data Adherent::Member.to_xls(@organism),
|
24
23
|
:filename=>"#{@organism.title}-#{dashed_date(Date.today)}-Membres.csv" }
|
25
24
|
format.json { render json:@members }
|
26
25
|
end
|
@@ -88,9 +87,7 @@ module Adherent
|
|
88
87
|
# DELETE /members/1
|
89
88
|
# DELETE /members/1.json
|
90
89
|
def destroy
|
91
|
-
|
92
90
|
@member.destroy
|
93
|
-
|
94
91
|
respond_to do |format|
|
95
92
|
format.html { redirect_to members_url }
|
96
93
|
format.json { head :no_content }
|
@@ -99,6 +96,8 @@ module Adherent
|
|
99
96
|
|
100
97
|
private
|
101
98
|
|
99
|
+
|
100
|
+
|
102
101
|
def find_member
|
103
102
|
@member = @organism.members.find(params[:id])
|
104
103
|
end
|
@@ -6,11 +6,11 @@ module Adherent
|
|
6
6
|
before_filter :find_member
|
7
7
|
|
8
8
|
def index
|
9
|
-
@payments = @member.payments
|
9
|
+
@payments = @member.payments.includes(:reglements=>[:adhesion=>:member])
|
10
10
|
end
|
11
11
|
|
12
12
|
def show
|
13
|
-
@payment = @member.payments.find_by_id(params[:id])
|
13
|
+
@payment = @member.payments.includes(:reglements=>[:adhesion=>:member]).find_by_id(params[:id])
|
14
14
|
end
|
15
15
|
|
16
16
|
def new
|
@@ -29,21 +29,25 @@ module Adherent
|
|
29
29
|
|
30
30
|
def list_imputations(payment)
|
31
31
|
content_tag(:ul) do
|
32
|
-
payment.
|
32
|
+
payment.reglements.map do |r|
|
33
33
|
content_tag(:li) do
|
34
|
-
imputation_with_actions(payment,
|
34
|
+
imputation_with_actions(payment, r)
|
35
35
|
end
|
36
36
|
end.join.html_safe
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def imputation_with_actions(pay,
|
40
|
+
def imputation_with_actions(pay, r)
|
41
41
|
html = ''
|
42
|
-
html << "Adhésion #{
|
42
|
+
html << "Adhésion #{r.adhesion.member} pour #{number_to_currency(r.adhesion.amount, locale: :fr)}"
|
43
43
|
html << " "
|
44
|
-
html << "#{icon_to 'detail.png', payment_reglement_path(pay.id,
|
44
|
+
html << "#{icon_to 'detail.png', payment_reglement_path(pay.id, r.id)}"
|
45
45
|
html.html_safe
|
46
46
|
end
|
47
47
|
|
48
|
+
def non_impute(payment)
|
49
|
+
payment.amount - payment.reglements.to_a.sum(&:amount)
|
50
|
+
end
|
51
|
+
|
48
52
|
end
|
49
53
|
end
|
@@ -13,8 +13,8 @@ module Adherent
|
|
13
13
|
# Le payment reprend plusieurs règlements
|
14
14
|
# TODO A voir, il peut y avoir des paiements partiels ou total
|
15
15
|
def recu_cotisation(payment, member)
|
16
|
-
rs = payment.reglements
|
17
|
-
if rs.
|
16
|
+
rs = payment.reglements
|
17
|
+
if rs.count == 1 && rs.first.adhesion.member == member
|
18
18
|
adh = rs.first.adhesion
|
19
19
|
"votre adhésion pour la période #{du_au(adh.from_date, adh.to_date)}"
|
20
20
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require 'csv'
|
4
|
+
|
3
5
|
module Adherent
|
4
6
|
class Member < ActiveRecord::Base
|
5
7
|
|
@@ -19,6 +21,35 @@ module Adherent
|
|
19
21
|
validates :name, presence:true, :format=>{with:NAME_REGEX}, :length=>{:maximum=>LONG_NAME_LENGTH_MAX}
|
20
22
|
validates :forname, presence:true, :format=>{with:NAME_REGEX}, :length=>{:maximum=>LONG_NAME_LENGTH_MAX}
|
21
23
|
|
24
|
+
def self.query_members(organism)
|
25
|
+
sql = <<-eof
|
26
|
+
SELECT adherent_members.id, organism_id, number, name, forname, birthdate,
|
27
|
+
adherent_coords.mail AS mail,
|
28
|
+
adherent_coords.tel AS tel,
|
29
|
+
adherent_coords.gsm AS gsm,
|
30
|
+
adherent_coords.office AS office,
|
31
|
+
adherent_coords.address AS address,
|
32
|
+
adherent_coords.zip AS zip,
|
33
|
+
adherent_coords.city AS city,
|
34
|
+
(SELECT to_date FROM adherent_adhesions
|
35
|
+
WHERE adherent_adhesions.member_id = adherent_members.id
|
36
|
+
ORDER BY to_date DESC LIMIT 1 ) AS m_to_date,
|
37
|
+
(SELECT SUM(adherent_reglements.amount) FROM adherent_reglements,
|
38
|
+
adherent_adhesions
|
39
|
+
WHERE adherent_reglements.adhesion_id = adherent_adhesions.id AND
|
40
|
+
adherent_adhesions.member_id = adherent_members.id) AS t_reglements,
|
41
|
+
(SELECT SUM(amount) FROM adherent_adhesions
|
42
|
+
WHERE adherent_adhesions.member_id = adherent_members.id) AS t_adhesions,
|
43
|
+
(SELECT COUNT(*) FROM adherent_payments
|
44
|
+
WHERE adherent_payments.member_id = adherent_members.id) AS nb_payments
|
45
|
+
|
46
|
+
FROM adherent_members
|
47
|
+
LEFT JOIN adherent_coords ON adherent_members.id = adherent_coords.member_id
|
48
|
+
WHERE organism_id = #{organism.id}
|
49
|
+
eof
|
50
|
+
find_by_sql(sql)
|
51
|
+
end
|
52
|
+
|
22
53
|
# arel des adhésions impayées par ordre de date
|
23
54
|
def unpaid_adhesions
|
24
55
|
adhesions.order(:to_date).unpaid
|
@@ -34,6 +65,8 @@ module Adherent
|
|
34
65
|
unpaid_adhesions.to_a.sum(&:due)
|
35
66
|
end
|
36
67
|
|
68
|
+
|
69
|
+
|
37
70
|
# renvoie le prenom NOM
|
38
71
|
def to_s
|
39
72
|
[forname, name.upcase].join(' ')
|
@@ -64,23 +97,58 @@ module Adherent
|
|
64
97
|
adhesions.new(vals)
|
65
98
|
end
|
66
99
|
|
100
|
+
# montant dû par l'adhérent pour ses adhésions
|
101
|
+
def montant_du
|
102
|
+
tadh = t_adhesions ? BigDecimal.new(t_adhesions, 2) : BigDecimal.new(0.0, 2)
|
103
|
+
treg = t_reglements ? BigDecimal.new(t_reglements, 2) : BigDecimal.new(0.0, 2)
|
104
|
+
tadh - treg
|
105
|
+
end
|
106
|
+
|
107
|
+
# booléen indiquant si l'adhérent est à jour de ces cotisations
|
108
|
+
def a_jour?
|
109
|
+
montant_du <= 0.001
|
110
|
+
end
|
111
|
+
|
67
112
|
|
68
113
|
# Permet en une seule requête de récupérer les données de la vue index
|
69
114
|
# avec l'id, le number, name, forname, mail, tel, l'échande de l'adhésion
|
70
115
|
# (champ to_date), le montant des reglements reçus pour les adhésions de
|
71
116
|
# ce membre (champ t_reglements), le montant des adhésions de ce membre
|
72
117
|
# champ (t_adhesions)
|
73
|
-
def self.index_members
|
74
|
-
sql= <<EOF
|
75
|
-
SELECT adherent_members.id, number, name, forname, birthdate, adherent_coords.mail AS mail, adherent_coords.tel AS tel,
|
76
|
-
(SELECT to_date FROM adherent_adhesions WHERE adherent_adhesions.member_id = adherent_members.id ORDER BY to_date DESC LIMIT 1 ) AS m_to_date,
|
77
|
-
(SELECT SUM(adherent_reglements.amount) FROM adherent_reglements, adherent_adhesions WHERE adherent_reglements.adhesion_id = adherent_adhesions.id AND adherent_adhesions.member_id = adherent_members.id) AS t_reglements,
|
78
|
-
(SELECT SUM(amount) FROM adherent_adhesions WHERE adherent_adhesions.member_id = adherent_members.id) AS t_adhesions
|
79
|
-
FROM adherent_members LEFT JOIN adherent_coords ON adherent_members.id = adherent_coords.member_id;
|
80
|
-
EOF
|
81
|
-
Adherent::Member.connection.execute( sql.gsub("\n", ''))
|
118
|
+
# def self.index_members
|
119
|
+
# sql= <<EOF
|
120
|
+
# SELECT adherent_members.id, number, name, forname, birthdate, adherent_coords.mail AS mail, adherent_coords.tel AS tel,
|
121
|
+
# (SELECT to_date FROM adherent_adhesions WHERE adherent_adhesions.member_id = adherent_members.id ORDER BY to_date DESC LIMIT 1 ) AS m_to_date,
|
122
|
+
# (SELECT SUM(adherent_reglements.amount) FROM adherent_reglements, adherent_adhesions WHERE adherent_reglements.adhesion_id = adherent_adhesions.id AND adherent_adhesions.member_id = adherent_members.id) AS t_reglements,
|
123
|
+
# (SELECT SUM(amount) FROM adherent_adhesions WHERE adherent_adhesions.member_id = adherent_members.id) AS t_adhesions
|
124
|
+
# FROM adherent_members LEFT JOIN adherent_coords ON adherent_members.id = adherent_coords.member_id;
|
125
|
+
#EOF
|
126
|
+
# Adherent::Member.connection.execute( sql.gsub("\n", ''))
|
127
|
+
# end
|
128
|
+
#
|
129
|
+
# edition en csv des membres d'un organisme dont l'id est
|
130
|
+
# transmis en argument
|
131
|
+
def self.to_csv(organism, options = {col_sep:"\t"})
|
132
|
+
ms = query_members(organism)
|
133
|
+
CSV.generate(options) do |csv|
|
134
|
+
csv << ['Numero', 'Nom', 'Prénom', 'Date de naissance',
|
135
|
+
'Mail', 'Tél', 'Gsm', 'Bureau', 'Adresse', 'Code Postal', 'Ville', 'Doit', 'Fin Adh.']
|
136
|
+
ms.each do |m|
|
137
|
+
csv << [m.number, m.name, m.forname, m.birthdate, m.mail, m.tel,
|
138
|
+
m.gsm, m.office, m.address, m.zip, m.city,
|
139
|
+
ActiveSupport::NumberHelper.number_to_rounded(m.montant_du, precision:2),
|
140
|
+
m.m_to_date]
|
141
|
+
end
|
142
|
+
end
|
82
143
|
end
|
83
144
|
|
145
|
+
# Pour avoir l'encodage Windows, voir à mettre dans un module si
|
146
|
+
# répété avec d'autres modèles
|
147
|
+
def self.to_xls(organism, options = {col_sep:"\t"})
|
148
|
+
to_csv(organism, options).encode("windows-1252")
|
149
|
+
end
|
150
|
+
|
151
|
+
|
84
152
|
|
85
153
|
|
86
154
|
|
@@ -49,16 +49,6 @@ module Adherent
|
|
49
49
|
Adhesion.find(adh_id).add_reglement(id, non_impute)
|
50
50
|
end
|
51
51
|
|
52
|
-
# renvoie l'information sur le membre et le montant
|
53
|
-
# pour liste des imputations d'un paiement
|
54
|
-
def list_imputations
|
55
|
-
reglements.collect do |r|
|
56
|
-
name = r.try(:adhesion).try(:member).try(:to_s)
|
57
|
-
name ||= 'Inconnue'
|
58
|
-
{member:name, amount:r.amount, r_id:r.id}
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
52
|
# calcule le montant du paiement qui n'a pas été imputé, donc qui
|
63
53
|
# ne correspond pas à des réglements
|
64
54
|
def non_impute
|
@@ -6,9 +6,10 @@
|
|
6
6
|
%td.numeric= virgule payment.amount
|
7
7
|
%td= payment.mode
|
8
8
|
%td= list_imputations(payment)
|
9
|
-
|
9
|
+
- pni = non_impute(payment)
|
10
|
+
%td.numeric= virgule pni
|
10
11
|
|
11
12
|
%td
|
12
|
-
- if (
|
13
|
+
- if (pni != 0.0)
|
13
14
|
= icon_to 'imputation.png', new_payment_reglement_path(payment), title: 'Imputer le solde sur une adhésion'
|
14
15
|
= icon_to 'detail.png', member_payment_path(payment.member, payment)
|
@@ -43,7 +43,13 @@
|
|
43
43
|
<%= icon_to 'bandaid.png', member_adhesions_path(member), title:'Liste des adhésions', id:"adhesion_member_#{member.id}"%>
|
44
44
|
<%= icon_to 'payment.png', member_payments_path(member), title: 'Liste des paiements' , id:"payment_member_#{member.id}"%>
|
45
45
|
<%= icon_to 'modifier.png', edit_member_path(member) , id:"edit_member_#{member.id}" %>
|
46
|
-
|
46
|
+
<% if member.nb_payments == 0 %>
|
47
|
+
<%= icon_to 'supprimer.png', member_path(id:member.id), :method => :delete, data:{:confirm => 'Etes vous sûr ?'} %>
|
48
|
+
<% else %>
|
49
|
+
<%= image_tag 'adherent/icones/nb_supprimer.png',
|
50
|
+
title:'Suppression impossible car présence de paiements',
|
51
|
+
class:'inactive_icon_menu' %>
|
52
|
+
<% end %>
|
47
53
|
</td>
|
48
54
|
</tr>
|
49
55
|
<% end %>
|
@@ -4,9 +4,10 @@
|
|
4
4
|
%td= payment.comment
|
5
5
|
%td= payment.mode
|
6
6
|
%td= list_imputations(payment)
|
7
|
-
|
7
|
+
- pni = non_impute(payment)
|
8
|
+
%td.numeric= number_to_currency pni, locale: :fr
|
8
9
|
|
9
10
|
%td
|
10
|
-
- if (
|
11
|
+
- if (pni != 0.0)
|
11
12
|
= icon_to 'imputation.png', new_payment_reglement_path(payment), title: 'Imputer le solde sur une adhésion'
|
12
13
|
= icon_to 'detail.png', member_payment_path(payment.member, payment)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
= content_for :menu do
|
2
2
|
= icon_to 'payment.png', member_payments_path(@member), title:"Liste des paiements de #{@member.to_s}"
|
3
3
|
= icon_to 'money-plus.png', new_member_payment_path(@member), title:'Nouveau paiement'
|
4
|
-
- if (@payment
|
4
|
+
- if (non_impute(@payment) != 0.0)
|
5
5
|
= icon_to 'imputation.png', new_payment_reglement_path(@payment), title: 'Imputer le solde sur une autre adhésion'
|
6
6
|
%a.icon_menu{href:'#'}
|
7
7
|
= image_tag("adherent/icones/printer.png", title:'Imprimer un reçu',
|
@@ -35,7 +35,7 @@
|
|
35
35
|
= list_imputations(@payment)
|
36
36
|
%p
|
37
37
|
%b Reste à imputer :
|
38
|
-
= number_to_currency @payment
|
38
|
+
= number_to_currency non_impute(@payment), locale: :fr
|
39
39
|
|
40
40
|
|
41
41
|
= render 'receipt'
|
data/lib/adherent/version.rb
CHANGED
@@ -20,5 +20,6 @@ module Adherent
|
|
20
20
|
# VERSION = '0.3.1' # Modifications pour le passage de flc à noschema
|
21
21
|
# VERSION = '0.3.2' # find_member est maintenant défini dans ApplicationController
|
22
22
|
# VERSION = '0.3.3' # retour en arrière car find_member(id) et find_member(member_id)
|
23
|
-
VERSION = '0.3.4' # les règlements sans adhésion s'affichent
|
23
|
+
# VERSION = '0.3.4' # les règlements sans adhésion s'affichent
|
24
|
+
VERSION = '0.3.5' # Affichage plus rapide des paiements
|
24
25
|
end
|
@@ -2,35 +2,32 @@
|
|
2
2
|
|
3
3
|
require 'rails_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
describe Adherent::AdhesionsController, :type => :controller do
|
6
|
+
|
7
|
+
fixtures :all
|
7
8
|
|
8
9
|
before(:each) do
|
9
10
|
@routes = Adherent::Engine.routes
|
10
|
-
@member =
|
11
|
-
allow(Adherent::Member).to receive(:find).with(@member.to_param).and_return @member
|
11
|
+
@member = adherent_members(:Dupont)
|
12
12
|
end
|
13
13
|
|
14
14
|
|
15
15
|
describe "GET index" do
|
16
16
|
|
17
17
|
it 'rend la vue index' do
|
18
|
-
allow(@member).to receive(:adhesions).and_return [1,2]
|
19
18
|
get :index, member_id:@member.to_param
|
20
19
|
expect(response).to render_template("index")
|
21
20
|
end
|
22
21
|
|
23
22
|
it 'ou redirige vers new si pas d adhésion' do
|
24
|
-
|
25
|
-
get :index, member_id:@member.to_param
|
23
|
+
get :index, member_id:adherent_members(:Durand).to_param
|
26
24
|
expect(response).to redirect_to new_member_adhesion_url(assigns[:member])
|
27
25
|
end
|
28
26
|
|
29
27
|
|
30
28
|
it "assigns all coords as @coords" do
|
31
|
-
expect(@member).to receive(:adhesions).and_return [1,2]
|
32
29
|
get :index, member_id:@member.to_param
|
33
|
-
expect(assigns(:adhesions)).to eq(
|
30
|
+
expect(assigns(:adhesions)).to eq(@member.adhesions)
|
34
31
|
end
|
35
32
|
end
|
36
33
|
|
@@ -39,60 +36,42 @@ RSpec.describe Adherent::AdhesionsController, :type => :controller do
|
|
39
36
|
describe 'GET new' do
|
40
37
|
|
41
38
|
it 'assigne une adhésion et rend la vue new' do
|
42
|
-
expect(@member).to receive(:next_adhesion).and_return(@adh = double(Adherent::Adhesion))
|
43
39
|
get :new, member_id:@member.to_param
|
44
|
-
expect(assigns[:adhesion]).to
|
40
|
+
expect(assigns[:adhesion]).to be_an_instance_of(Adherent::Adhesion)
|
45
41
|
expect(response).to render_template('new')
|
46
42
|
end
|
47
43
|
|
48
44
|
end
|
49
45
|
|
50
|
-
describe "GET edit"
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
get :edit, {member_id:@member.to_param, id:
|
55
|
-
|
56
|
-
|
57
|
-
it 'assigne le payment et rend la vue' do
|
58
|
-
allow(@member).to receive(:adhesions).and_return @ar = double(Arel)
|
59
|
-
allow(@ar).to receive(:find).and_return(@adh = double(Adherent::Adhesion))
|
60
|
-
get :edit, {member_id:@member.to_param, id:'1'}
|
61
|
-
expect(assigns[:adhesion]).to eq(@adh)
|
46
|
+
describe "GET edit"do
|
47
|
+
|
48
|
+
it 'assigne l adhesion et rend la vue' do
|
49
|
+
a = @member.adhesions.first
|
50
|
+
get :edit, {member_id:@member.to_param, id:a.to_param}
|
51
|
+
expect(assigns[:adhesion]).to eq(a)
|
62
52
|
expect(response).to render_template('edit')
|
63
53
|
end
|
64
54
|
end
|
65
55
|
|
66
|
-
describe "POST create"
|
56
|
+
describe "POST create" do
|
67
57
|
|
68
58
|
before(:each) do
|
69
59
|
@attrib = {'amount'=>'57', 'to_date'=>I18n.l(Date.today >> 12), 'from_date'=>I18n.l(Date.today) }
|
70
60
|
end
|
71
61
|
|
72
62
|
it 'crée une nouvelle adhésion avec les params' do
|
73
|
-
expect(
|
74
|
-
|
75
|
-
and_return(@adh = double(Adherent::Adhesion, valid?:true))
|
76
|
-
expect(@adh).to receive(:save).and_return true
|
77
|
-
post :create, {member_id:@member.to_param, :adhesion=>@attrib}
|
63
|
+
expect{(post :create, {member_id:@member.to_param, :adhesion=>@attrib})}.
|
64
|
+
to change{Adherent::Adhesion.count}.by(1)
|
78
65
|
|
79
66
|
end
|
80
67
|
|
81
68
|
it 'renvoie vers la vue des adhésions' do
|
82
|
-
allow(@member).to receive(:adhesions).and_return(@ar = double(Arel))
|
83
|
-
allow(@ar).to receive(:new).
|
84
|
-
and_return(@adh = double(Adherent::Adhesion, valid?:true))
|
85
|
-
allow(@adh).to receive(:save).and_return true
|
86
69
|
post :create, {member_id:@member.to_param, :adhesion=>@attrib}
|
87
70
|
expect(response).to redirect_to(member_adhesions_url(assigns[:member]))
|
88
71
|
end
|
89
72
|
|
90
73
|
it 'et vers la vue new autrement' do
|
91
|
-
|
92
|
-
allow(@ar).to receive(:new).
|
93
|
-
and_return(@adh = Adherent::Adhesion.new) # qui est un invalide
|
94
|
-
allow(@adh).to receive(:save).and_return false
|
95
|
-
post :create, {member_id:@member.to_param, :adhesion=>@attrib}
|
74
|
+
post :create, {member_id:@member.to_param, :adhesion=>{montant:10} }
|
96
75
|
expect(response).to render_template('new')
|
97
76
|
end
|
98
77
|
|
@@ -102,38 +81,27 @@ RSpec.describe Adherent::AdhesionsController, :type => :controller do
|
|
102
81
|
describe "POST update" do
|
103
82
|
|
104
83
|
before(:each) do
|
105
|
-
@
|
106
|
-
|
84
|
+
@member = adherent_members(:Dupont)
|
85
|
+
@adh = @member.adhesions.first
|
107
86
|
end
|
108
87
|
|
109
|
-
it '
|
110
|
-
|
111
|
-
expect(
|
112
|
-
expect(@adh).to receive(:update_attributes).with({'amount'=>'125'}).and_return true
|
113
|
-
post :update, {member_id:@member.to_param, id:'1', :adhesion=>{:amount=>'125'} }
|
88
|
+
it 'met à jour le paiement' do
|
89
|
+
post :update, {member_id:@member.to_param, id:@adh.to_param, :adhesion=>{:amount=>'125'} }
|
90
|
+
expect(adherent_adhesions(:adh_1).amount).to eq 125
|
114
91
|
end
|
115
92
|
|
116
93
|
it 'redirige vers la liste des adhésions en cas de succès' do
|
117
|
-
|
118
|
-
allow(@ar).to receive(:find).and_return(@adh = double(Adherent::Adhesion))
|
119
|
-
allow(@adh).to receive(:update_attributes).with({'amount'=>'125'}).and_return true
|
120
|
-
post :update, {member_id:@member.to_param, id:'1', :adhesion=>{'amount'=>'125'} }
|
94
|
+
post :update, {member_id:@member.to_param, id:@adh.to_param, :adhesion=>{'amount'=>'125'} }
|
121
95
|
expect(response).to redirect_to(member_adhesions_url(assigns[:member]))
|
122
96
|
end
|
123
97
|
|
124
98
|
it 'et vers la vue edit autrement' do
|
125
|
-
|
126
|
-
allow(@ar).to receive(:find).and_return(@adh = double(Adherent::Adhesion))
|
127
|
-
allow(@adh).to receive(:update_attributes).with({'amount'=>'125'}).and_return false
|
128
|
-
post :update, {member_id:@member.to_param, id:'1', :adhesion=>{'amount'=>'125'} }
|
99
|
+
post :update, {member_id:@member.to_param, id:@adh.to_param, :adhesion=>{'amount'=>'bonjour'} }
|
129
100
|
expect(response).to render_template 'edit'
|
130
101
|
end
|
131
102
|
|
132
103
|
it 'la variable @adhesion est assignée' do
|
133
|
-
|
134
|
-
allow(@ar).to receive(:find).and_return(@adh = double(Adherent::Adhesion))
|
135
|
-
allow(@adh).to receive(:update_attributes).with({'amount'=>'125'}).and_return false
|
136
|
-
post :update, {member_id:@member.to_param, id:'1', :adhesion=>{'amount'=>'125'} }
|
104
|
+
post :update, {member_id:@member.to_param, id:@adh.to_param, :adhesion=>{'amount'=>'125'} }
|
137
105
|
expect(assigns[:adhesion]).to eq(@adh)
|
138
106
|
end
|
139
107
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
module Adherent
|
4
|
+
|
5
|
+
|
4
6
|
describe AllpaymentsController, :type => :controller do
|
7
|
+
fixtures :all
|
5
8
|
|
6
9
|
before(:each) do
|
7
10
|
@routes = Adherent::Engine.routes
|
@@ -10,7 +13,7 @@ module Adherent
|
|
10
13
|
describe "GET 'index'" do
|
11
14
|
it "returns http success" do
|
12
15
|
get 'index'
|
13
|
-
expect(response).to be_success
|
16
|
+
expect(response).to be_success
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|