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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b43ac4cafa20bd1b818343d4dc265644772c6f2
4
- data.tar.gz: c02cd18e455a11856ca83ca2482ce36e7b96165c
3
+ metadata.gz: 217b8b45d967f02b6babaecf7fd500986e60438a
4
+ data.tar.gz: eb12679aaa201814133d26105e21199f3e9d6684
5
5
  SHA512:
6
- metadata.gz: 5a3e6db18805b1b92294dde90a434de664698aff1faa1c045f6ff29b1b0e2c965ed1eff53449cefb8be75a1677bf96a87cb637e028348ae55ea7df81ffa94b68
7
- data.tar.gz: ce9b61f747675965e4008507a09c218092a6bc6bf53f3833f6483c0ba9720533d19cafdba73b894adbb6722ca4662d498276a1c57fd5a443c20f3029cbab5d96
6
+ metadata.gz: 0a53d4edae2600388c547dd9bbd06fc138f1ab5f7a2963bb00d2346280fc5fa2aa698fc4876b3d3c6faf63565c242ff1059a70e5785fdeaeb56246bb5b77f150
7
+ data.tar.gz: 73e4ab6646e0d83854f23d9e9bb7e542c534a1eb33a910adaca2d01a560d08d3128e8680204c5c038502e8bda31d039e9bdefb4be82d37cf8e024c88cbc6cf78
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fraternity (0.0.2)
4
+ fraternity (0.0.3)
5
5
  lotus-model
6
6
  lotus-validations (~> 0.2.3)
7
7
  rake
data/README.md CHANGED
@@ -127,7 +127,7 @@ Fraternity::Pledge.find(token).crossed?
127
127
  Convert the pledge into a full member (accept the invitation).
128
128
 
129
129
  ```
130
- Fraternity::Pledge.cross! token
130
+ Fraternity::Pledge.find(token).cross! token
131
131
  ```
132
132
 
133
133
  ## CONTRIBUTING
@@ -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
@@ -11,6 +11,12 @@ module Fraternity
11
11
  end.first
12
12
  end
13
13
 
14
+ def self.find_by_email(email)
15
+ query do
16
+ where(email: email)
17
+ end.first
18
+ end
19
+
14
20
  def self.find_by_token(token)
15
21
  query do
16
22
  where(token: token)
@@ -1,3 +1,3 @@
1
1
  module Fraternity
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/fraternity.rb CHANGED
@@ -18,13 +18,19 @@ module Fraternity
18
18
  end
19
19
 
20
20
  def self.rush(params={})
21
- params[:token] ||= TemporaryToken.generate_random_token
22
- params[:initiation_number] ||= Time.now.to_i
23
- Fraternity::Pledge.new params
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.create self.rush(params)
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 }
@@ -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.2
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-19 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake