Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Cefin
OLIGAA
Commits
0105f357
Commit
0105f357
authored
Sep 21, 2018
by
David F.
Browse files
Merge branch '86-stats-admin-saison' into 'master'
Resolve "[Admin] Archivage des adhésions par saison sportive" See merge request
CDSA33/OLIGAA!94
parents
20627052
4e510f0e
Changes
21
Hide whitespace changes
Inline
Side-by-side
app/assets/stylesheets/application.scss
View file @
0105f357
...
...
@@ -65,6 +65,7 @@
@import
"emails"
;
@import
"partners"
;
@import
"events"
;
@import
"platform"
;
.danger
{
color
:
$oligaa-red
;
...
...
app/assets/stylesheets/members.scss
View file @
0105f357
...
...
@@ -44,29 +44,27 @@ form#search_contacts_form {
}
}
aside
#subscriptions
{
div
{
padding
:
0
1em
;
div
#internal
,
div
#external
,
div
#subscriptions-by-club
,
div
#subscriptions-by-org
{
padding
:
0
1em
;
a
.expendable
{
display
:
block
;
}
a
.expendable
{
display
:
block
;
}
ul
{
padding
:
0
.5em
0
;
ul
{
padding
:
0
.5em
0
;
li
.subscription
{
span
{
padding
:
0
0
.5em
;
&
.billed
{
@include
button-color
(
$oligaa-green
);
}
&
.not-billed
{
@include
button-color
;
}
&
.platform-number
{
font
:
caption
;}
&
.activities
{
display
:
none
;
}
li
.subscription
{
span
{
padding
:
0
0
.5em
;
&
.billed
{
@include
button-color
(
$oligaa-green
);
}
&
.not-billed
{
@include
button-color
;
}
&
.platform-number
{
font
:
caption
;}
&
.activities
{
display
:
none
;
}
i
.fa-info-circle
:hover
+
span
.activities
{
display
:
block
;}
}
i
.fa-info-circle
:hover
+
span
.activities
{
display
:
block
;}
}
}
}
app/assets/stylesheets/platform.scss
0 → 100644
View file @
0105f357
form
#season-selector
{
margin
:
0
.5em
auto
;
text-align
:
center
;
label
{
display
:
inline-block
;
}
}
div
#admin-platform
{
h3
a
{
color
:
inherit
;
}
}
app/controllers/platform_controller.rb
View file @
0105f357
...
...
@@ -23,16 +23,19 @@ class PlatformController < ApplicationController
before_action
:authorize
def
index
@collaborating_clubs
=
Member
.
of_member_groups
(
settings
.
platform_collaborating_clubs
).
by_name
@orgs_in_db_by_name
=
Member
.
of_member_groups
(
settings
.
platform_medicosocial_orgs
).
by_name
@orgs_in_db
=
{}
@orgs_in_db_by_name
.
each
do
|
org
|
subscriptions
=
Subscription
.
of_medicosocial_org
(
org
).
by_adherent_name
@orgs_in_db
[
org
]
=
subscriptions
unless
subscriptions
.
empty?
end
@orgs_not_in_db
=
{}
Adherent
.
where
.
not
(
other_medicosocial_org:
nil
).
group
(
:other_medicosocial_org
).
order
(
:other_medicosocial_org
).
count
.
each
do
|
org_name
,
result
|
@orgs_not_in_db
[
Member
.
new
({
name:
org_name
})]
=
Subscription
.
joins
(
:adherent
).
where
(
adherents:
{
other_medicosocial_org:
org_name
}).
by_adherent_name
.
all
if
session
[
:season
]
=
params
[
:season
]
@season
=
Season
.
from_short_label
(
params
[
:season
])
@collaborating_clubs
=
Member
.
of_member_groups
(
settings
.
platform_collaborating_clubs
).
by_name
@orgs_in_db_by_name
=
Member
.
of_member_groups
(
settings
.
platform_medicosocial_orgs
).
by_name
@orgs_in_db
=
{}
@orgs_in_db_by_name
.
each
do
|
org
|
subscriptions
=
Subscription
.
for_season
(
@season
).
of_medicosocial_org
(
org
).
by_adherent_name
.
all
@orgs_in_db
[
org
]
=
subscriptions
unless
subscriptions
.
empty?
end
@orgs_not_in_db
=
{}
Adherent
.
where
.
not
(
other_medicosocial_org:
nil
).
group
(
:other_medicosocial_org
).
order
(
:other_medicosocial_org
).
count
.
each
do
|
org_name
,
result
|
@orgs_not_in_db
[
Member
.
new
({
name:
org_name
})]
=
Subscription
.
for_season
(
@season
).
joins
(
:adherent
).
where
(
adherents:
{
other_medicosocial_org:
org_name
}).
by_adherent_name
.
all
end
end
end
end
app/controllers/subscriptions_controller.rb
View file @
0105f357
...
...
@@ -118,7 +118,7 @@ class SubscriptionsController < ApplicationController
def
toggle_billing
@subscription
.
toggle_billing
redirect_to
platform_path
,
notice:
"L'adhésion a bien été
#{
@subscription
.
billed_at
?
''
:
'dé'
}
facturée."
redirect_to
platform_path
(
season:
session
[
:season
])
,
notice:
"L'adhésion a bien été
#{
@subscription
.
billed_at
?
''
:
'dé'
}
facturée."
end
private
...
...
app/models/adherent.rb
View file @
0105f357
...
...
@@ -21,7 +21,7 @@
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
class
Adherent
<
ApplicationRecord
has_many
:subscriptions
,
dependent: :destroy
has_many
:subscriptions
belongs_to
:medico_social_org
,
class_name:
'Member'
,
optional:
true
validates
:last_name
,
:first_name
,
:born_on
,
:permit_number
,
presence:
true
...
...
app/models/season.rb
View file @
0105f357
...
...
@@ -24,6 +24,16 @@ class Season
FIRST_MONTH
=
8
FIRST_DAY
=
15
attr_reader
:beginning
attr_reader
:end
def
initialize
(
date
)
year
=
(
date
<
Season
.
birthdate
.
change
(
year:
date
.
year
)
?
date
.
year
-
1
:
date
.
year
)
@beginning
=
Season
.
birthdate
.
change
(
year:
year
)
@end
=
@beginning
+
1
.
year
-
1
.
day
return
self
end
def
self
.
default_birthdate
Date
.
new
(
1970
,
FIRST_MONTH
,
FIRST_DAY
)
end
...
...
@@ -32,6 +42,19 @@ class Season
Settings
.
instance
.
reload
.
season_birthdate
||
self
.
default_birthdate
end
def
self
.
all
(
klass
,
date_field
=
:begin_at
)
min_year
=
klass
.
send
(
:minimum
,
date_field
).
try
(
:year
)
max_year
=
klass
.
send
(
:maximum
,
date_field
).
try
(
:year
)
return
[]
unless
min_year
&&
max_year
[].
tap
do
|
years
|
(
min_year
..
max_year
).
each
do
|
year
|
season
=
self
.
new
(
self
.
birthdate
.
change
(
year:
year
))
years
<<
season
.
short_label
end
end
end
def
self
.
all_for
(
items
,
date_field
=
:begin_at
)
result
=
{}
items
.
each
do
|
item
|
...
...
@@ -45,18 +68,24 @@ class Season
result
.
sort
.
reverse
end
def
initialize
(
date
)
year
=
(
date
<
Season
.
birthdate
.
change
(
year:
date
.
year
)
?
date
.
year
-
1
:
date
.
year
)
@begining
=
Season
.
birthdate
.
change
(
year:
year
)
return
self
def
self
.
from_short_label
(
label
)
self
.
new
(
self
.
birthdate
.
change
(
year:
label
.
split
(
'-'
).
first
.
to_i
))
end
def
self
.
from_label
(
label
)
self
.
from_short_label
(
label
.
gsub
(
/Saison /
,
''
))
end
def
shorten
shorten_year
=
@begining
.
year
.
%
100
shorten_year
=
@begin
n
ing
.
year
.
%
100
"
#{
shorten_year
}#{
shorten_year
+
1
}
"
end
def
short_label
"
#{
@beginning
.
year
}
-
#{
@beginning
.
year
+
1
}
"
end
def
label
"Saison
#{
@begining
.
year
}
-
#{
@begining
.
year
+
1
}
"
"Saison
#{
short_label
}
"
end
end
app/models/statistics/billing/global.rb
View file @
0105f357
...
...
@@ -22,8 +22,8 @@
#
class
Statistics::Billing::Global
def
initialize
(
members
)
@member_units
=
members
.
map
{
|
member
|
Statistics
::
Billing
::
Unit
.
new
(
member
)
}
def
initialize
(
members
,
season
)
@member_units
=
members
.
map
{
|
member
|
Statistics
::
Billing
::
Unit
.
new
(
member
,
season
)
}
end
def
total
...
...
app/models/statistics/billing/unit.rb
View file @
0105f357
...
...
@@ -22,19 +22,20 @@
#
class
Statistics::Billing::Unit
def
initialize
(
member
)
def
initialize
(
member
,
season
)
@member
=
member
@season
=
season
end
def
total
check_collaboration_or_return
(
0
)
do
@member
.
subscriptions
.
with_multiactivities_pass
.
length
@member
.
subscriptions
.
for_season
(
@season
).
with_multiactivities_pass
.
length
end
end
def
billed
check_collaboration_or_return
(
0
)
do
@member
.
subscriptions
.
billed
.
count
@member
.
subscriptions
.
for_season
(
@season
).
billed
.
count
end
end
...
...
app/models/statistics/pass/global.rb
View file @
0105f357
...
...
@@ -22,8 +22,8 @@
#
class
Statistics::Pass::Global
def
initialize
(
members
)
@member_units
=
members
.
map
{
|
member
|
Statistics
::
Pass
::
Unit
.
new
(
member
)
}
def
initialize
(
members
,
season
)
@member_units
=
members
.
map
{
|
member
|
Statistics
::
Pass
::
Unit
.
new
(
member
,
season
)
}
end
def
total
...
...
app/models/statistics/pass/unit.rb
View file @
0105f357
...
...
@@ -22,15 +22,16 @@
#
class
Statistics::Pass::Unit
def
initialize
(
member
)
def
initialize
(
member
,
season
)
@member
=
member
@season
=
season
end
def
total
return_values
=
{
none:
0
,
club:
@member
.
subscriptions
.
count
,
medicosocial_org:
Subscription
.
of_medicosocial_org
(
@member
).
count
club:
@member
.
subscriptions
.
for_season
(
@season
).
count
,
medicosocial_org:
Subscription
.
for_season
(
@season
).
of_medicosocial_org
(
@member
).
count
}
check_collaboration_or_return
(
return_values
)
end
...
...
@@ -38,8 +39,8 @@ class Statistics::Pass::Unit
def
multi
return_values
=
{
none:
0
,
club:
@member
.
subscriptions
.
with_multiactivities_pass
.
length
,
medicosocial_org:
Subscription
.
of_medicosocial_org
(
@member
).
with_multiactivities_pass
.
length
club:
@member
.
subscriptions
.
for_season
(
@season
).
with_multiactivities_pass
.
length
,
medicosocial_org:
Subscription
.
for_season
(
@season
).
of_medicosocial_org
(
@member
).
with_multiactivities_pass
.
length
}
check_collaboration_or_return
(
return_values
)
end
...
...
app/models/subscription.rb
View file @
0105f357
...
...
@@ -22,17 +22,19 @@
#
class
Subscription
<
ApplicationRecord
belongs_to
:member
belongs_to
:adherent
,
dependent: :destroy
belongs_to
:adherent
accepts_nested_attributes_for
:adherent
has_many
:performance_subscriptions
,
dependent: :destroy
has_many
:performances
,
through: :performance_subscriptions
after_create
:set_platform_number
before_destroy
:destroy_adherent_if_necessary
scope
:for_performances
,
->
(
performance_ids
)
{
joins
(
:performances
).
where
(
performance_subscriptions:
{
performance_id:
performance_ids
}).
distinct
}
scope
:by_adherent_name
,
->
{
joins
(
:adherent
).
order
(
'adherents.first_name'
,
'adherents.last_name'
)
}
scope
:billed
,
->
{
where
.
not
(
billed_at:
nil
)
}
scope
:of_medicosocial_org
,
->
(
member
)
{
joins
(
:adherent
).
where
(
adherents:
{
medico_social_org:
member
})
}
scope
:for_season
,
->
(
season
)
{
where
(
created_at:
(
season
.
beginning
..
season
.
end
)
)}
def
self
.
with_multiactivities_pass
all
.
reject
{
|
sub
|
!
sub
.
multipass?
}
...
...
@@ -69,4 +71,8 @@ class Subscription < ApplicationRecord
def
set_platform_number
self
.
update_attribute
(
:platform_number
,
SubscriptionNumber
.
new
(
self
).
label
)
end
def
destroy_adherent_if_necessary
adherent
.
destroy
if
Subscription
.
where
(
adherent:
self
.
adherent
).
count
==
1
end
end
app/views/members/show/_subscriptions.html.erb
View file @
0105f357
...
...
@@ -35,12 +35,12 @@
<%-
end
%>
<h2>
Nos adhérents
<span>
<%=
Statistics
::
Pass
::
Unit
.
new
(
@member
).
label
%>
</span>
</h2>
<div
id=
"internal"
>
<%-
@seasoned_internal_subscriptions
.
each
do
|
season
,
subscriptions
|
%>
<%
season_label
=
season
.
downcase
.
gsub
(
/\s/
,
'_'
)
+
"_int"
%>
<%=
toggle_link
"
#{
season
}
(
#{
subscriptions
.
length
}
)"
,
"#
#{
season_label
}
"
%>
<%=
toggle_link
"
#{
season
}
#{
Statistics
::
Pass
::
Unit
.
new
(
@member
,
Season
.
from_label
(
season
)).
label
}
"
,
"#
#{
season_label
}
"
%>
<%=
%>
<ul
id=
"
<%=
season_label
%>
"
style=
"display:none;"
>
<%
subscriptions
.
each
do
|
subscription
|
%>
<li
class=
"subscription"
>
...
...
app/views/platform/index.html.erb
View file @
0105f357
...
...
@@ -22,7 +22,14 @@
%>
<%
title
"Plateforme Sports et Troubles psychiques"
%>
<div
class=
"tabs"
>
<%=
form_tag
platform_path
,
method: :get
,
id:
"season-selector"
do
%>
<%=
label_tag
:season
,
"Saison"
%>
<%=
select_tag
:season
,
options_for_select
(
Season
.
all
(
Subscription
,
:created_at
).
reverse
,
params
[
:season
])
%>
<%=
submit_tag
"Afficher"
%>
<%
end
%>
<%
if
@season
%>
<div
id=
"admin-platform"
class=
"tabs"
>
<ul>
<li><a
href=
"#subscriptions-by-club"
>
Adhésions par club
</a></li>
<li><a
href=
"#subscriptions-by-org"
>
Adhésions par structure
</a></li>
...
...
@@ -30,17 +37,17 @@
<div
id=
"subscriptions-by-club"
>
<h2>
Liste des adhésions par club partenaire
<span>
<%=
Statistics
::
Pass
::
Global
.
new
(
@collaborating_clubs
.
to_a
).
label
%>
</span>
<span>
<%=
Statistics
::
Billing
::
Global
.
new
(
@collaborating_clubs
.
to_a
).
label
%>
</span>
<span>
<%=
Statistics
::
Pass
::
Global
.
new
(
@collaborating_clubs
.
to_a
,
@season
).
label
%>
</span>
<span>
<%=
Statistics
::
Billing
::
Global
.
new
(
@collaborating_clubs
.
to_a
,
@season
).
label
%>
</span>
</h2>
<%-
@collaborating_clubs
.
each
do
|
club
|
%>
<h3>
<%=
club
.
name
%>
<span>
<%=
Statistics
::
Pass
::
Unit
.
new
(
club
).
label
%>
</span>
<span>
<%=
Statistics
::
Billing
::
Unit
.
new
(
club
).
label
%>
</span>
<%=
link_to
club
.
name
,
club
%>
<span>
<%=
Statistics
::
Pass
::
Unit
.
new
(
club
,
@season
).
label
%>
</span>
<span>
<%=
Statistics
::
Billing
::
Unit
.
new
(
club
,
@season
).
label
%>
</span>
</h3>
<ul
id=
"member-
<%=
club
.
id
%>
"
>
<%-
club
.
subscriptions
.
by_adherent_name
.
each
do
|
subscription
|
%>
<%-
club
.
subscriptions
.
for_season
(
@season
).
by_adherent_name
.
each
do
|
subscription
|
%>
<li
class=
"subscription"
>
<%=
custom_edit_link
edit_member_subscription_path
(
club
,
subscription
),
:short
,
class:
%w(tight)
%>
<%=
custom_bill_link
toggle_billing_member_subscription_path
(
club
,
subscription
),
:short
,
class:
[
'tight'
,
subscription
.
billing_status
]
if
subscription
.
multipass?
%>
...
...
@@ -54,13 +61,13 @@
<div
id=
"subscriptions-by-org"
>
<h2>
Liste des adhésions par structure
<span>
<%=
Statistics
::
Pass
::
Global
.
new
(
@orgs
.
to_a
).
label
%>
</span>
<span>
<%=
Statistics
::
Pass
::
Global
.
new
(
@orgs
.
to_a
,
@season
).
label
%>
</span>
</h2>
<h3>
Structures référencées
</h3>
<%-
@orgs_in_db
.
each
do
|
org
,
subscriptions
|
%>
<h4>
<%=
org
.
name
%>
<span>
<%=
Statistics
::
Pass
::
Unit
.
new
(
org
).
label
%>
</span>
<%=
link_to
org
.
name
,
org
%>
<span>
<%=
Statistics
::
Pass
::
Unit
.
new
(
org
,
@season
).
label
%>
</span>
</h4>
<ul
id=
"member-
<%=
org
.
id
%>
"
>
<%=
render
partial:
'subscription'
,
collection:
subscriptions
%>
...
...
@@ -70,7 +77,7 @@
<%-
@orgs_not_in_db
.
each
do
|
org
,
subscriptions
|
%>
<h4>
<%=
org
.
name
%>
<span>
<%=
Statistics
::
Pass
::
Unit
.
new
(
org
).
label
%>
</span>
<span>
<%=
Statistics
::
Pass
::
Unit
.
new
(
org
,
@season
).
label
%>
</span>
</h4>
<ul
id=
"member-
<%=
org
.
name
.
crypt
(
'name'
).
gsub
(
'/'
,
''
)
%>
"
>
<%=
render
partial:
'subscription'
,
collection:
subscriptions
%>
...
...
@@ -78,3 +85,4 @@
<%-
end
%>
</div>
</div>
<%
end
%>
spec/features/subscriptions_spec.rb
View file @
0105f357
...
...
@@ -150,6 +150,14 @@ feature "Manage subscriptions" do
within
"nav#admin_links"
do
click_link
"Plateforme"
end
expect
(
page
).
not_to
have_selector
(
"div#subscriptions-by-club"
)
within
"form#season-selector"
do
select
"2017-2018"
,
from:
"Saison"
click_button
"Afficher"
end
expect
(
current_path
).
to
eq
platform_path
click_link
"Adhésions par club"
expect
(
page
).
to
have_selector
(
"h2"
,
text:
"Liste des adhésions par club partenaire"
)
...
...
@@ -184,7 +192,8 @@ feature "Manage subscriptions" do
nb_club2_mono
=
4
.
times
{
create
:subscription
,
performances:
[
perf1
],
member_id:
club2
.
id
}
nb_club2_multi
=
6
.
times
{
create
:subscription
,
performances:
[
perf1
,
perf2
],
member_id:
club2
.
id
}
visit
platform_path
visit
platform_path
(
season:
"2017-2018"
)
expect
(
current_path
).
to
eq
platform_path
within
"h3"
,
text:
"USG"
do
expect
(
page
).
to
have_selector
(
"span"
,
text:
"(3 multi, 5 mono sur 8)"
)
end
...
...
@@ -204,10 +213,13 @@ feature "Manage subscriptions" do
perf2
=
create
:performance
,
member:
usg
jean_dupont
=
build
:adherent
,
last_name:
"Dupont"
,
first_name:
"Jean"
pascal_durand
=
build
:adherent
,
last_name:
"Durand"
,
first_name:
"Pascal"
create
:subscription
,
adherent:
jean_dupont
,
performances:
[
perf1
,
perf2
],
member_id:
usg
.
id
create
:subscription
,
adherent:
pascal_durand
,
performances:
[
perf1
],
member_id:
usg
.
id
create
:subscription
,
adherent:
jean_dupont
,
performances:
[
perf1
,
perf2
],
member_id:
usg
.
id
,
created_at:
"15/09/2017"
create
:subscription
,
adherent:
pascal_durand
,
performances:
[
perf1
],
member_id:
usg
.
id
,
created_at:
"15/09/2017"
visit
platform_path
(
season:
"2017-2018"
)
expect
(
current_path
).
to
eq
platform_path
visit
platform_path
click_link
"Adhésions par club"
within
"h2"
,
text:
"Liste des adhésions par club partenaire"
do
expect
(
page
).
to
have_selector
(
"span"
,
text:
"(€ : 0 / 1)"
)
end
...
...
@@ -270,15 +282,12 @@ feature "Manage subscriptions" do
pascal_durand
=
build
:adherent
,
last_name:
"Durand"
,
first_name:
"Pascal"
,
medico_social_org:
ime_machin
arthur_latrouille
=
build
:adherent
,
last_name:
"Latrouille"
,
first_name:
"Arthur"
,
medico_social_org:
nil
,
other_medicosocial_org:
"IME Bidule"
igor_jovovitch
=
build
:adherent
,
last_name:
"Jovovitch"
,
first_name:
"Igor"
,
medico_social_org:
nil
,
other_medicosocial_org:
"IME Bidule"
create
:subscription
,
adherent:
jean_dupont
,
performances:
[
perf1
,
perf2
],
member_id:
usg
.
id
create
:subscription
,
adherent:
pascal_durand
,
performances:
[
perf1
],
member_id:
usg
.
id
create
:subscription
,
adherent:
arthur_latrouille
,
performances:
[
perf1
,
perf2
],
member_id:
usg
.
id
create
:subscription
,
adherent:
igor_jovovitch
,
performances:
[
perf2
],
member_id:
usg
.
id
create
:subscription
,
adherent:
jean_dupont
,
performances:
[
perf1
,
perf2
],
member_id:
usg
.
id
,
created_at:
"15/09/2017"
create
:subscription
,
adherent:
pascal_durand
,
performances:
[
perf1
],
member_id:
usg
.
id
,
created_at:
"15/09/2017"
create
:subscription
,
adherent:
arthur_latrouille
,
performances:
[
perf1
,
perf2
],
member_id:
usg
.
id
,
created_at:
"15/09/2017"
create
:subscription
,
adherent:
igor_jovovitch
,
performances:
[
perf2
],
member_id:
usg
.
id
,
created_at:
"15/09/2017"
visit
root_path
within
"nav#admin_links"
do
click_link
"Plateforme"
end
visit
platform_path
(
season:
"2017-2018"
)
click_link
"Adhésions par structure"
expect
(
page
).
to
have_selector
(
"h2"
,
text:
"Liste des adhésions par structure"
)
...
...
@@ -544,12 +553,12 @@ feature "Manage subscriptions" do
scenario
"I can read the number of mono and multi activities ones"
do
perf1
=
create
:performance
,
member:
@member
perf2
=
create
:performance
,
member:
@member
nb_of_monoactivity_subscriptions
=
5
.
times
{
create
:subscription
,
performances:
[
perf1
],
member_id:
@member
.
id
}
nb_of_multiactivities_subscriptions
=
3
.
times
{
create
:subscription
,
performances:
[
perf1
,
perf2
],
member_id:
@member
.
id
}
nb_of_monoactivity_subscriptions
=
5
.
times
{
create
:subscription
,
performances:
[
perf1
],
member_id:
@member
.
id
,
created_at:
"15/09/2017"
}
nb_of_multiactivities_subscriptions
=
3
.
times
{
create
:subscription
,
performances:
[
perf1
,
perf2
],
member_id:
@member
.
id
,
created_at:
"15/09/2017"
}
visit
member_path
(
@member
)
within
"
h2"
,
text:
"Nos adhérents
"
do
expect
(
page
).
to
have_
selector
(
"span"
,
text:
"
(3 multi, 5 mono sur 8)"
)
within
"
aside#subscriptions div#internal
"
do
expect
(
page
).
to
have_
link
"Saison 2017-2018
(3 multi, 5 mono sur 8)"
end
end
...
...
@@ -641,12 +650,12 @@ feature "Manage subscriptions" do
pascal_durand
=
build
:adherent
,
last_name:
"Durand"
,
first_name:
"Pascal"
,
medico_social_org:
@member
perf_usg
=
create
:performance
,
member:
usg
,
activity:
athle
perf_mouettes
=
create
:performance
,
member:
mouettes
,
activity:
surf
create
:subscription
,
adherent:
jean_dupont
,
performances:
[
perf_usg
,
perf_mouettes
],
member_id:
usg
.
id
create
:subscription
,
adherent:
pascal_durand
,
performances:
[
perf_mouettes
],
member_id:
mouettes
.
id
create
:subscription
,
adherent:
jean_dupont
,
performances:
[
perf_usg
,
perf_mouettes
],
member_id:
usg
.
id
,
created_at:
"15/09/2017"
create
:subscription
,
adherent:
pascal_durand
,
performances:
[
perf_mouettes
],
member_id:
mouettes
.
id
,
created_at:
"15/09/2017"
visit
member_path
(
@member
)
within
"
h2"
,
text:
"Nos adhérents
"
do
expect
(
page
).
to
have_
selector
(
"span"
,
text:
"
(1 multi, 1 mono sur 2)"
)
within
"
aside#subscriptions div#internal
"
do
expect
(
page
).
to
have_
link
"Saison 2017-2018
(1 multi, 1 mono sur 2)"
end
within
"aside#subscriptions div#internal"
do
click_link
"Saison 2017-2018"
...
...
spec/models/season_spec.rb
View file @
0105f357
...
...
@@ -24,6 +24,51 @@ require 'rails_helper'
RSpec
.
describe
Season
,
type: :model
do
context
"regarding initialization"
do
context
"when season birthdate not provided"
do
context
"sets the beginning ot the season to"
do
scenario
"15/08/2017 when date 19/09/2017 is given"
do
season
=
Season
.
new
(
Date
.
new
(
2017
,
9
,
19
))
expect
(
season
.
beginning
).
to
eq
Date
.
new
(
2017
,
8
,
15
)
expect
(
season
.
end
).
to
eq
Date
.
new
(
2018
,
8
,
14
)
end
scenario
"15/08/2017 when date 15/08/2017 is given"
do
season
=
Season
.
new
(
Date
.
new
(
2017
,
8
,
15
))
expect
(
season
.
beginning
).
to
eq
Date
.
new
(
2017
,
8
,
15
)
expect
(
season
.
end
).
to
eq
Date
.
new
(
2018
,
8
,
14
)
end
scenario
"15/08/2016 when date 14/08/2017 is given"
do
season
=
Season
.
new
(
Date
.
new
(
2017
,
8
,
14
))
expect
(
season
.
beginning
).
to
eq
Date
.
new
(
2016
,
8
,
15
)
expect
(
season
.
end
).
to
eq
Date
.
new
(
2017
,
8
,
14
)
end
end
end
context
"when season birthdate set to 01/09/1970"
do
before
{
@settings
.
update_attribute
(
:season_birthdate
,
Date
.
new
(
1970
,
9
,
1
))
}
context
"sets the beginning ot the season to"
do
scenario
"01/09/2017 when date 19/09/2017 is given"
do
season
=
Season
.
new
(
Date
.
new
(
2017
,
9
,
19
))
expect
(
season
.
beginning
).
to
eq
Date
.
new
(
2017
,
9
,
1
)
expect
(
season
.
end
).
to
eq
Date
.
new
(
2018
,
8
,
31
)
end
scenario
"01/09/2017 when date 01/09/2017 is given"
do
season
=
Season
.
new
(
Date
.
new
(
2017
,
9
,
1
))
expect
(
season
.
beginning
).
to
eq
Date
.
new
(
2017
,
9
,
1
)
expect
(
season
.
end
).
to
eq
Date
.
new
(
2018
,
8
,
31
)
end
scenario
"01/09/2016 when date 31/08/2017 is given"
do
season
=
Season
.
new
(
Date
.
new
(
2017
,
8
,
31
))
expect
(
season
.
beginning
).
to
eq
Date
.
new
(
2016
,
9
,
1
)
expect
(
season
.
end
).
to
eq
Date
.
new
(
2017
,
8
,
31
)
end
end
end
end
context
"class methods"
do
it
".default_birthdate set to 15/08/1970"
do
...
...
@@ -54,6 +99,44 @@ RSpec.describe Season, type: :model do
end
end
context
".all returns available seasons"
do
before
{
allow
(
Settings
).
to
receive_message_chain
(
:instance
,
:reload
,
:season_birthdate
).
and_return
(
Date
.
new
(
1970
,
9
,
1
))
}
it
"returns empty array if none available"
do
# Given
expected
=
[]
# When
result
=
Season
.
all
(
Event
)
# Then
expect
(
result
).
to
eq
expected
end
it
"based on :begin_at if no field provided"
do
# Given
create
:event
,
begin_at:
Date
.
new
(
2016
,
9
,
1
)
create
:event
,
begin_at:
Date
.
new
(
2017
,
9
,
1
)
create
:event
,
begin_at:
Date
.
new
(
2018
,
9
,
1
)
expected
=
[
"2016-2017"
,
"2017-2018"
,
"2018-2019"
]
# When
result
=
Season
.
all
(
Event
)
# Then
expect
(
result
).
to
eq
expected
end
it
"based on the provided field"
do
# Given
create
:subscription
,
created_at:
Date
.
new
(
2016
,
9
,
1
)
create
:subscription
,
created_at:
Date
.
new
(
2017
,
9
,
1
)
create
:subscription
,
created_at:
Date
.
new
(
2018
,
9
,
1
)
expected
=
[
"2016-2017"
,
"2017-2018"
,
"2018-2019"
]
# When
result
=
Season
.
all
(
Subscription
,
:created_at
)
# Then
expect
(
result
).
to
eq
expected
end
end
context
".all_for returns items arranged by season"
do
before
{
allow
(
Settings
).
to
receive_message_chain
(
:instance
,
:reload
,
:season_birthdate
).
and_return
(
Date
.
new
(
1970
,
9
,
1
))
}
...
...
@@ -90,44 +173,17 @@ RSpec.describe Season, type: :model do
expect
(
result
).
to
eq
expected
end
end
end
context
"regarding initialization"
do
context
"when season birthdate not provided"
do
context
"sets the begining ot the season to"
do
scenario
"15/08/2017 when date 19/09/2017 is given"
do
season
=
Season
.
new
(
Date
.
new
(
2017
,
9
,
19
))
expect
(
season
.
instance_variable_get
(
:@begining
)).
to
eq
Date
.
new
(
2017
,
8
,
15
)
end
scenario
"15/08/2017 when date 15/08/2017 is given"
do