espace_membre-ruby 0.4.1 → 1.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.
- checksums.yaml +4 -4
- data/README.md +29 -11
- data/lib/espace_membre/incubator.rb +0 -2
- data/lib/espace_membre/mission.rb +0 -2
- data/lib/espace_membre/mission_startup.rb +0 -1
- data/lib/espace_membre/organization.rb +11 -0
- data/lib/espace_membre/phase.rb +16 -18
- data/lib/espace_membre/railtie.rb +1 -0
- data/lib/espace_membre/record.rb +1 -0
- data/lib/espace_membre/startup.rb +5 -9
- data/lib/espace_membre/team.rb +0 -2
- data/lib/espace_membre/user.rb +7 -0
- data/lib/espace_membre/version.rb +1 -1
- data/spec/dummy/spec/factories/startups.rb +8 -4
- data/spec/dummy/spec/factories/users.rb +12 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1e66c2d89ac50c90ae52377f4770cb6d040802a6280d42b0dac58ce3a026096e
|
|
4
|
+
data.tar.gz: 80e88388d15e162e942ca5d21b54d0471ac4a1ebd34e7f864a92924a7207dfc5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9733a430af728a4ae862f85533ca6a9b43fa8585afe2c876d39d243408e57c341429e927c173bd21018c8ac8cba8dd06dd4ab9474ee1091147659c8d604d12f6
|
|
7
|
+
data.tar.gz: 0c5023c0b4721818b9947c262655fb345578afcb2f279167f1f7d211f2bb14e0dcb290e64cc7406b85fe98fdbde17c04c83c0afa66a84a4abf3a77e141687102
|
data/README.md
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
1
|
# espace_membre-ruby
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- [X] restore RSpec
|
|
10
|
-
- [X] run the tests
|
|
11
|
-
- [X] distribute.
|
|
3
|
+
Cette gem fournit des classes ActiveRecord communes pour encapsuler et
|
|
4
|
+
partager la logique de l'Espace-Membre. Elle est [déjà
|
|
5
|
+
utilisée](https://github.com/betagouv/espace_membre-ruby/network/dependents)
|
|
6
|
+
par d'autres produits pour construire autour des données beta.gouv.fr
|
|
7
|
+
et leurs logique métier (ex: "est-ce qu'un produit est actif ?", "qui
|
|
8
|
+
est considéré alumni", etc).
|
|
12
9
|
|
|
13
10
|
## Installation
|
|
14
|
-
|
|
11
|
+
|
|
12
|
+
Dans votre Gemfile:
|
|
15
13
|
|
|
16
14
|
```ruby
|
|
17
15
|
gem "espace_membre-ruby"
|
|
18
16
|
```
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
Puis vous devez indiquer à Rails la base de données de Beta au travers
|
|
19
|
+
d'une nouvelle base `espace_membre_db`, c.f [la configuration de
|
|
20
|
+
standards.beta.gouv.fr](https://github.com/betagouv/standards-front/blob/main/config/database.yml#L1-L6).
|
|
21
|
+
|
|
22
|
+
Ensuite vous pouvez lancer votre console et vérifier que le connecteur
|
|
23
|
+
fonctionne bien :
|
|
21
24
|
|
|
22
25
|
```ruby
|
|
23
26
|
EspaceMembre::User.without(:active_missions).last(10)
|
|
24
27
|
```
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
Pas encore disponible mais vous pouvez [consulter la liste des
|
|
32
|
+
modèles](https://github.com/betagouv/espace_membre-ruby/tree/main/lib/espace_membre)
|
|
33
|
+
ou [les tests
|
|
34
|
+
associés](https://github.com/betagouv/espace_membre-ruby/blob/53e282c9e3afff9bd4fbaf7bd0cf15734756e9cc/spec/dummy/spec/models/user_spec.rb#L30)
|
|
35
|
+
pour explorer la gem.
|
|
36
|
+
|
|
37
|
+
## TODO
|
|
38
|
+
|
|
39
|
+
- [ ] allow configuration (database name)
|
|
40
|
+
- [X] restore RSpec
|
|
41
|
+
- [X] run the tests
|
|
42
|
+
- [X] distribute.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EspaceMembre
|
|
4
|
+
class Organization < Record
|
|
5
|
+
has_and_belongs_to_many :startups, join_table: "startups_organizations"
|
|
6
|
+
|
|
7
|
+
# EMDB has a `type` column which triggers ActiveRecord – but still
|
|
8
|
+
# it is still kind enough to provide the following fix:
|
|
9
|
+
self.inheritance_column = :null
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/espace_membre/phase.rb
CHANGED
|
@@ -2,20 +2,24 @@ module EspaceMembre
|
|
|
2
2
|
class Phase < Record
|
|
3
3
|
belongs_to :startup
|
|
4
4
|
|
|
5
|
-
PHASES = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
PHASES = %w[
|
|
6
|
+
investigation
|
|
7
|
+
abandon-investigation
|
|
8
|
+
construction
|
|
9
|
+
acceleration
|
|
10
|
+
consolidation
|
|
11
|
+
abandon
|
|
12
|
+
opere
|
|
13
|
+
transfere
|
|
12
14
|
]
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
ACTIVE_PHASES = %w[
|
|
17
|
+
acceleration
|
|
18
|
+
consolidation
|
|
19
|
+
construction
|
|
20
|
+
investigation
|
|
21
|
+
opere
|
|
22
|
+
].freeze
|
|
19
23
|
|
|
20
24
|
PHASES.each do |phase|
|
|
21
25
|
# define scopes for each state (Phase.success, Phase.alumni, etc.)
|
|
@@ -27,12 +31,6 @@ module EspaceMembre
|
|
|
27
31
|
end
|
|
28
32
|
end
|
|
29
33
|
|
|
30
|
-
scope :active_phase, -> { construction.or(acceleration) }
|
|
31
|
-
|
|
32
|
-
def terminate!
|
|
33
|
-
update!(end: Time.zone.now)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
34
|
def to_s
|
|
37
35
|
name
|
|
38
36
|
end
|
|
@@ -6,6 +6,7 @@ module EspaceMembre
|
|
|
6
6
|
require "espace_membre/incubator.rb"
|
|
7
7
|
require "espace_membre/mission.rb"
|
|
8
8
|
require "espace_membre/mission_startup.rb"
|
|
9
|
+
require "espace_membre/organization.rb"
|
|
9
10
|
require "espace_membre/phase.rb"
|
|
10
11
|
require "espace_membre/startup.rb"
|
|
11
12
|
require "espace_membre/user.rb"
|
data/lib/espace_membre/record.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
module EspaceMembre
|
|
2
2
|
class Startup < Record
|
|
3
|
-
self.primary_key = "uuid"
|
|
4
|
-
|
|
5
3
|
validates :ghid, presence: true
|
|
6
4
|
|
|
7
5
|
belongs_to :incubator
|
|
8
6
|
|
|
9
7
|
has_many :phases
|
|
10
8
|
|
|
9
|
+
has_and_belongs_to_many :organizations, join_table: "startups_organizations"
|
|
10
|
+
|
|
11
11
|
has_and_belongs_to_many :missions, join_table: "missions_startups"
|
|
12
12
|
|
|
13
13
|
has_many :users, through: :missions
|
|
@@ -19,6 +19,8 @@ module EspaceMembre
|
|
|
19
19
|
class_name: "Phase",
|
|
20
20
|
inverse_of: :startup
|
|
21
21
|
|
|
22
|
+
scope :active, -> { in_phase(EspaceMembre::Phase::ACTIVE_PHASES) }
|
|
23
|
+
|
|
22
24
|
# we must use this tragic hack because a startup can have one or
|
|
23
25
|
# more phases without an 'end' timestamp, which is wrong and
|
|
24
26
|
# misleading but that's how the data exists. So instead of
|
|
@@ -31,14 +33,8 @@ module EspaceMembre
|
|
|
31
33
|
.where("phases.start = (SELECT MAX(p2.start) FROM phases p2 WHERE p2.startup_id = startups.uuid)")
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
Phase::PHASES.each do |name|
|
|
35
|
-
define_method "in_#{name}?" do
|
|
36
|
-
latest_phase.send("#{name}?")
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
36
|
def in_phase?(name)
|
|
41
|
-
|
|
37
|
+
latest_phase.name == name.to_s
|
|
42
38
|
end
|
|
43
39
|
|
|
44
40
|
def to_s
|
data/lib/espace_membre/team.rb
CHANGED
data/lib/espace_membre/user.rb
CHANGED
|
@@ -28,6 +28,13 @@ module EspaceMembre
|
|
|
28
28
|
validates :username, :fullname, :role, :domaine, presence: true
|
|
29
29
|
validates :domaine, inclusion: { in: DOMAINES }
|
|
30
30
|
|
|
31
|
+
scope :expired, -> {
|
|
32
|
+
where(
|
|
33
|
+
"NOT EXISTS (:active_missions)",
|
|
34
|
+
active_missions: Mission.active.where("missions.user_id = users.uuid")
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
def self.identify_email!(email)
|
|
32
39
|
User.find_by!(primary_email: email)
|
|
33
40
|
rescue ActiveRecord::RecordNotFound
|
|
@@ -18,8 +18,6 @@ FactoryBot.define do
|
|
|
18
18
|
in_investigation
|
|
19
19
|
|
|
20
20
|
after(:create) do |startup|
|
|
21
|
-
startup.latest_phase.terminate!
|
|
22
|
-
|
|
23
21
|
FactoryBot.create(:phase, :construction, startup: startup)
|
|
24
22
|
end
|
|
25
23
|
end
|
|
@@ -28,10 +26,16 @@ FactoryBot.define do
|
|
|
28
26
|
in_construction
|
|
29
27
|
|
|
30
28
|
after(:create) do |startup|
|
|
31
|
-
startup.latest_phase.terminate!
|
|
32
|
-
|
|
33
29
|
FactoryBot.create(:phase, :acceleration, startup: startup)
|
|
34
30
|
end
|
|
35
31
|
end
|
|
32
|
+
|
|
33
|
+
trait :abandon_investigation do
|
|
34
|
+
in_investigation
|
|
35
|
+
|
|
36
|
+
after(:create) do |startup|
|
|
37
|
+
FactoryBot.create(:phase, :"abandon-investigation", startup: startup)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
36
40
|
end
|
|
37
41
|
end
|
|
@@ -18,6 +18,18 @@ FactoryBot.define do
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
trait :with_expired_mission do
|
|
22
|
+
with_active_mission
|
|
23
|
+
|
|
24
|
+
transient do
|
|
25
|
+
mission_end { Date.yesterday }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
after(:create) do |user, context|
|
|
29
|
+
user.missions.last.update!(end: context.mission_end)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
21
33
|
trait :with_active_startup do
|
|
22
34
|
with_active_mission
|
|
23
35
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: espace_membre-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0
|
|
4
|
+
version: '1.0'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stéphane Maniaci
|
|
@@ -36,6 +36,7 @@ files:
|
|
|
36
36
|
- lib/espace_membre/incubator.rb
|
|
37
37
|
- lib/espace_membre/mission.rb
|
|
38
38
|
- lib/espace_membre/mission_startup.rb
|
|
39
|
+
- lib/espace_membre/organization.rb
|
|
39
40
|
- lib/espace_membre/phase.rb
|
|
40
41
|
- lib/espace_membre/railtie.rb
|
|
41
42
|
- lib/espace_membre/record.rb
|