promocode_generator 0.0.1 → 0.0.2
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
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWY2NzRkYjAwZDVjODhiMjU2OTA3ODc4YTIyMjcwOTNmOWM1MTJlNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzViMDVjMWU1ZmE3NGRiZGE0NWJhZTAxYjI1ZmQxNTgwZmM0YWJkMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWY5ZjdkZjhkNGNmMWUxZDhkOGFkOTNkNWNjNzEwZGE4ZDJmOWY3NjdiZmJi
|
10
|
+
ZTc1ODgwNGE0MGMzMjE3N2ZmZDc0MmZmMGE4NzJkOGY4ZmUwYTMwYWYzNzk3
|
11
|
+
ZTM0MzI5Y2U2YjYwMTBhNTVmZGQ5ZGMzNjQzNzJjNWRmYjM0NDg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGU5MjhlMWU3Nzg3MDliNmIwMjA3N2E0MzgzZGYyMDZjYWIyNzdlOTAxMDI1
|
14
|
+
ZDFlZmYyYmRhY2Q1ODVkNDgxNjg4MjZiZDMzYjE4ODc1Yzg3NDJkNWUwZDMz
|
15
|
+
ZjZmYTdjN2RiNDY4M2M2Njk2NmFlMWM0NjlmOTMyOWE4YjI5OWI=
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Without Rails:
|
|
24
24
|
|
25
25
|
With Rails:
|
26
26
|
|
27
|
-
In your model, use the promocode_attribute method to automatically generate a promotional code of length 8 in the
|
27
|
+
In your model, use the promocode_attribute method to automatically generate a promotional code of length 8 in the before_create hook:
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
class Campaign < ActiveRecord::Base
|
@@ -3,7 +3,7 @@ module PromocodeGenerator
|
|
3
3
|
def promocode_attribute(attribute, options = {})
|
4
4
|
options[:reject_if] ||= Proc.new { |code| self.where(attribute => code).any? }
|
5
5
|
|
6
|
-
|
6
|
+
before_create do
|
7
7
|
# Make sure not to generate the same code twice!
|
8
8
|
begin
|
9
9
|
self.code = PromocodeGenerator.generate
|
@@ -16,7 +16,7 @@ end
|
|
16
16
|
describe PromocodeGenerator::ModelAdditions do
|
17
17
|
let(:campaign) { Campaign.new(:name => "foo") }
|
18
18
|
|
19
|
-
context "when
|
19
|
+
context "when a new model is saved" do
|
20
20
|
it "generates a code" do
|
21
21
|
expect(PromocodeGenerator).to receive(:generate).once.and_return('ABCDEFG')
|
22
22
|
campaign.save!
|
@@ -28,6 +28,16 @@ describe PromocodeGenerator::ModelAdditions do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
context "when an existing model is saved" do
|
32
|
+
it "does not touch the code" do
|
33
|
+
campaign.save!
|
34
|
+
code = campaign.code
|
35
|
+
|
36
|
+
campaign.name = "blubb"
|
37
|
+
expect { campaign.save! }.not_to change { campaign.code }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
31
41
|
context "when the reject_if block returns false" do
|
32
42
|
before { RejectCondition.stub(:check).and_return(true, false) }
|
33
43
|
after { RejectCondition.unstub(:check) }
|