fraternity 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/fraternity/pledge.rb +8 -1
- data/lib/fraternity/repositories/pledge_repository.rb +6 -0
- data/lib/fraternity/version.rb +1 -1
- data/lib/fraternity.rb +10 -4
- data/spec/fraternity/pledge_spec.rb +20 -0
- data/spec/fraternity/repositories/pledge_repository_spec.rb +15 -0
- data/spec/fraternity_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 217b8b45d967f02b6babaecf7fd500986e60438a
|
4
|
+
data.tar.gz: eb12679aaa201814133d26105e21199f3e9d6684
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a53d4edae2600388c547dd9bbd06fc138f1ab5f7a2963bb00d2346280fc5fa2aa698fc4876b3d3c6faf63565c242ff1059a70e5785fdeaeb56246bb5b77f150
|
7
|
+
data.tar.gz: 73e4ab6646e0d83854f23d9e9bb7e542c534a1eb33a910adaca2d01a560d08d3128e8680204c5c038502e8bda31d039e9bdefb4be82d37cf8e024c88cbc6cf78
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/fraternity/pledge.rb
CHANGED
@@ -11,7 +11,6 @@ module Fraternity
|
|
11
11
|
validates :initiation_number, presence: true
|
12
12
|
|
13
13
|
def initialize(attributes={})
|
14
|
-
|
15
14
|
@id, @email, @first_name, @last_name, @token, @initiation_number, @invited_at, @accepted_at =
|
16
15
|
attributes.values_at :id, :email, :first_name, :last_name, :token, :initiation_number, :invited_at, :accepted_at
|
17
16
|
end
|
@@ -32,6 +31,7 @@ module Fraternity
|
|
32
31
|
raise Fraternity::PerpError if !invited?
|
33
32
|
raise Fraternity::TokenMismatchError.new(self.token, token) if token != self.token
|
34
33
|
self.accepted_at = DateTime.now
|
34
|
+
Repositories::PledgeRepository.persist self
|
35
35
|
end
|
36
36
|
|
37
37
|
def crossed?
|
@@ -41,5 +41,12 @@ module Fraternity
|
|
41
41
|
def ready?
|
42
42
|
self.invited? && !self.crossed?
|
43
43
|
end
|
44
|
+
|
45
|
+
def merge(attributes={})
|
46
|
+
attributes.each_pair do |attribute, value|
|
47
|
+
method = "#{attribute}="
|
48
|
+
self.public_send method, value if self.respond_to? method
|
49
|
+
end
|
50
|
+
end
|
44
51
|
end
|
45
52
|
end
|
data/lib/fraternity/version.rb
CHANGED
data/lib/fraternity.rb
CHANGED
@@ -18,13 +18,19 @@ module Fraternity
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.rush(params={})
|
21
|
-
params[:
|
22
|
-
|
23
|
-
|
21
|
+
pledge = Repositories::PledgeRepository.find_by_email params[:email]
|
22
|
+
if pledge
|
23
|
+
pledge.merge params
|
24
|
+
pledge
|
25
|
+
else
|
26
|
+
params[:token] ||= TemporaryToken.generate_random_token
|
27
|
+
params[:initiation_number] ||= Time.now.to_i
|
28
|
+
Fraternity::Pledge.new params
|
29
|
+
end
|
24
30
|
end
|
25
31
|
|
26
32
|
def self.rush!(params)
|
27
|
-
Repositories::PledgeRepository.
|
33
|
+
Repositories::PledgeRepository.persist self.rush(params)
|
28
34
|
end
|
29
35
|
|
30
36
|
def self.bid!(quota)
|
@@ -102,4 +102,24 @@ describe Fraternity::Pledge do
|
|
102
102
|
expect(pledge).to_not be_ready
|
103
103
|
end
|
104
104
|
end
|
105
|
+
|
106
|
+
describe "#merge" do
|
107
|
+
it "updates attributes that were not set" do
|
108
|
+
pledge = Fraternity::Pledge.new token: "1234"
|
109
|
+
pledge.merge email: "jimmy@example.com"
|
110
|
+
expect(pledge.email).to eq "jimmy@example.com"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "updates attributes that were already set" do
|
114
|
+
pledge = Fraternity::Pledge.new token: "1234"
|
115
|
+
pledge.merge token: "5678"
|
116
|
+
expect(pledge.token).to eq "5678"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "does not delete attributes that were not set" do
|
120
|
+
pledge = Fraternity::Pledge.new token: "1234", first_name: "Jimmy"
|
121
|
+
pledge.merge email: "jimmy@example.com"
|
122
|
+
expect(pledge.first_name).to eq "Jimmy"
|
123
|
+
end
|
124
|
+
end
|
105
125
|
end
|
@@ -32,6 +32,21 @@ describe Fraternity::Repositories::PledgeRepository do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe ".find_by_email" do
|
36
|
+
let(:pledge) { Fraternity::Repositories::PledgeRepository.create(Fraternity::Pledge.new(email: "jimmy@example.com", token: "12345", initiation_number: Time.now.to_i)) }
|
37
|
+
|
38
|
+
it "returns the first pledge with the email" do
|
39
|
+
pledge
|
40
|
+
actual = Fraternity::Repositories::PledgeRepository.find_by_email pledge.email
|
41
|
+
expect(actual.id).to eq pledge.id
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns nil if the pledge does not exist" do
|
45
|
+
actual = Fraternity::Repositories::PledgeRepository.find_by_email "blah@blah.com"
|
46
|
+
expect(actual).to be_nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
35
50
|
describe ".oldest_univited_by_initiation_number" do
|
36
51
|
let(:four_days_ago) { Time.now.to_i - 24 * 60 * 60 * 4 }
|
37
52
|
let(:six_days_ago) { Time.now.to_i - 24 * 60 * 60 * 6 }
|
data/spec/fraternity_spec.rb
CHANGED
@@ -81,6 +81,23 @@ describe Fraternity do
|
|
81
81
|
pledge = Fraternity.rush initiation_number: 12345
|
82
82
|
expect(pledge.initiation_number).to eq 12345
|
83
83
|
end
|
84
|
+
|
85
|
+
context "with an existing pledge" do
|
86
|
+
let(:email) { "jimmy@example.com" }
|
87
|
+
let(:pledge) { Fraternity::Pledge.new id: 123, token: "12345", email: email }
|
88
|
+
|
89
|
+
before { allow(Fraternity::Repositories::PledgeRepository).to receive(:find_by_email).and_return pledge }
|
90
|
+
|
91
|
+
it "returns an existing pledge based on their email" do
|
92
|
+
actual = Fraternity.rush email: email
|
93
|
+
expect(actual.id).to eq pledge.id
|
94
|
+
end
|
95
|
+
|
96
|
+
it "merges the parameters for updating the pledge" do
|
97
|
+
actual = Fraternity.rush email: email, first_name: "Robert"
|
98
|
+
expect(actual.first_name).to eq "Robert"
|
99
|
+
end
|
100
|
+
end
|
84
101
|
end
|
85
102
|
|
86
103
|
describe ".rush!" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fraternity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Wright
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|