gamifier 1.0.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/README.md +55 -3
- data/examples/dev.rb +18 -7
- data/lib/gamifier/dsl/api_key.rb +19 -0
- data/lib/gamifier/dsl/network.rb +60 -6
- data/lib/gamifier/dsl/site.rb +5 -0
- data/lib/gamifier/dsl.rb +3 -2
- data/lib/gamifier/engine.rb +8 -4
- data/lib/gamifier/models/api_key.rb +10 -0
- data/lib/gamifier/models/network.rb +10 -0
- data/lib/gamifier/version.rb +1 -1
- data/lib/gamifier.rb +3 -4
- data/spec/integration/collection_integration_spec.rb +6 -6
- data/spec/integration/dsl_integration_spec.rb +59 -63
- data/spec/integration/player_integration_spec.rb +8 -5
- data/spec/integration/user_integration_spec.rb +21 -12
- data/spec/spec_integration_helper.rb +12 -12
- data/spec/unit/collection_spec.rb +17 -17
- data/spec/unit/dsl/api_key_spec.rb +42 -0
- data/spec/unit/dsl/network_spec.rb +130 -17
- data/spec/unit/dsl/site_spec.rb +120 -27
- data/spec/unit/dsl_spec.rb +2 -2
- data/spec/unit/engine_spec.rb +98 -10
- data/spec/unit/gamifier_spec.rb +9 -7
- data/spec/unit/model_spec.rb +29 -0
- data/spec/unit/models/activity_definition_spec.rb +15 -15
- data/spec/unit/models/player_spec.rb +21 -14
- metadata +8 -2
@@ -4,31 +4,31 @@ require 'webmock/rspec'
|
|
4
4
|
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
5
5
|
require 'gamifier'
|
6
6
|
|
7
|
-
WebMock.allow_net_connect!
|
7
|
+
# WebMock.allow_net_connect!
|
8
8
|
|
9
9
|
RSpec.configure do |config|
|
10
10
|
|
11
|
-
config.before :all do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
11
|
+
# config.before :all do
|
12
|
+
# Gamifier.set :uri, ENV.fetch("BADGEVILLE_URI") { "http://sandbox.v2.badgeville.com/api/berlin/" }
|
13
|
+
# Gamifier.set :key, ENV.fetch("BADGEVILLE_KEY") { "1234" }
|
14
|
+
# ENGINE = Gamifier.engine if !defined?(ENGINE)
|
15
|
+
# end
|
16
16
|
|
17
17
|
def player_attributes
|
18
|
-
{:email => "
|
18
|
+
{ :email => "user@foo.com", :site => "foo.com", :display_name => "Foo Bar" }
|
19
19
|
end
|
20
20
|
|
21
21
|
def user_attributes
|
22
|
-
{:email => "
|
22
|
+
{ :email => "user@foo.com" }
|
23
23
|
end
|
24
24
|
|
25
25
|
def find_or_create_test_user
|
26
|
-
user =
|
26
|
+
user = Gamifier.engine.users.find(user_attributes[:email]) || Gamifier.engine.users.build(user_attributes).save
|
27
27
|
user.should_not be_nil
|
28
28
|
end
|
29
29
|
|
30
30
|
def destroy_test_player!
|
31
|
-
player =
|
31
|
+
player = Gamifier.engine.players.find_by_site_and_email(player_attributes[:site], player_attributes[:email])
|
32
32
|
if player
|
33
33
|
puts "Found player #{player}. Deleting..."
|
34
34
|
player.destroy.should be_true
|
@@ -37,9 +37,9 @@ RSpec.configure do |config|
|
|
37
37
|
|
38
38
|
def find_or_create_test_player
|
39
39
|
find_or_create_test_user
|
40
|
-
player =
|
40
|
+
player = Gamifier.engine.players.find_by_site_and_email(player_attributes[:site], player_attributes[:email])
|
41
41
|
if player.nil?
|
42
|
-
player =
|
42
|
+
player = Gamifier.engine.players.build(player_attributes).save
|
43
43
|
player.should_not be_false
|
44
44
|
player
|
45
45
|
else
|
@@ -1,33 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gamifier::Collection do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
4
|
+
|
5
|
+
let(:engine) { mock(Gamifier::Engine) }
|
6
|
+
let(:collection) { Gamifier::Collection.new(engine, Gamifier::Model) }
|
8
7
|
|
9
8
|
it "should have included the FinderMethods of the model" do
|
10
9
|
Gamifier::Model::FinderMethods.public_instance_methods.each do |method|
|
11
|
-
|
10
|
+
collection.should respond_to(method)
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
|
-
it "should
|
16
|
-
|
17
|
-
|
18
|
-
object.key.should == "value"
|
14
|
+
it "should build a new object" do
|
15
|
+
o = collection.build(:key => 'value')
|
16
|
+
o.should be_a(Gamifier::Model)
|
19
17
|
end
|
20
18
|
|
21
|
-
it "should
|
22
|
-
|
23
|
-
|
24
|
-
}.to raise_error(ArgumentError)
|
19
|
+
it "should have the correct value" do
|
20
|
+
o = collection.build(:key => 'value')
|
21
|
+
o.key.should eq('value')
|
25
22
|
end
|
26
|
-
|
23
|
+
|
24
|
+
it { expect { collection.reset! }.to raise_error(ArgumentError) }
|
25
|
+
|
27
26
|
it "should call destroy on each entry of the collection when calling #reset!" do
|
28
27
|
model = mock(Gamifier::Model)
|
29
28
|
model.should_receive(:destroy)
|
30
|
-
|
31
|
-
|
29
|
+
collection.should_receive(:all).with(:site => "xyz").and_yield model
|
30
|
+
collection.reset!(:site => "xyz")
|
32
31
|
end
|
33
|
-
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gamifier::DSL::ApiKey do
|
4
|
+
|
5
|
+
let(:api_key) { Gamifier::DSL::ApiKey.new }
|
6
|
+
let(:url) { 'http://foo.com' }
|
7
|
+
let(:key) { '1234' }
|
8
|
+
let(:enterprise_key) { '5678' }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Gamifier.set :uri => url, :key => key, :enterprise_key => enterprise_key
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#initialize" do
|
15
|
+
|
16
|
+
subject { api_key }
|
17
|
+
|
18
|
+
its(:source) { should_not be_nil }
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#engine" do
|
23
|
+
|
24
|
+
subject { api_key.engine }
|
25
|
+
|
26
|
+
it { should_not eq(Gamifier.engine) }
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#method_missing" do
|
31
|
+
|
32
|
+
let(:args) { 'bar' }
|
33
|
+
let(:block) { lambda {|x| x} }
|
34
|
+
|
35
|
+
it "should call on source" do
|
36
|
+
api_key.source.should_receive(:foo).with(args, &block)
|
37
|
+
api_key.foo(args, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -1,34 +1,147 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gamifier::DSL::Network do
|
4
|
+
|
5
|
+
let(:network) { Gamifier::DSL::Network.new }
|
6
|
+
let(:url) { 'http://foo.com' }
|
7
|
+
let(:key) { '1234' }
|
8
|
+
let(:enterprise_key) { '5678' }
|
9
|
+
|
4
10
|
before do
|
5
|
-
Gamifier.set :uri =>
|
6
|
-
|
11
|
+
Gamifier.set :uri => url, :key => key, :enterprise_key => enterprise_key
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#initialize" do
|
15
|
+
|
16
|
+
subject { network }
|
17
|
+
|
18
|
+
its(:source) { should_not be_nil }
|
19
|
+
its(:sites) { should be_empty }
|
20
|
+
its(:api_keys) { should be_empty }
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#engine" do
|
25
|
+
|
26
|
+
subject { network.engine }
|
27
|
+
|
28
|
+
it { should_not eq(Gamifier.engine) }
|
29
|
+
it { should_not eq(network.enterprise_engine) }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#enterprise_engine" do
|
34
|
+
|
35
|
+
subject { network.enterprise_engine }
|
36
|
+
|
37
|
+
it { should_not eq(Gamifier.engine) }
|
38
|
+
it { should_not eq(network.engine) }
|
39
|
+
|
7
40
|
end
|
8
|
-
|
9
|
-
|
41
|
+
|
42
|
+
describe "#method_missing" do
|
43
|
+
|
44
|
+
let(:args) { 'bar' }
|
45
|
+
let(:block) { lambda {|x| x} }
|
46
|
+
|
47
|
+
it "should call on source" do
|
48
|
+
network.source.should_receive(:foo).with(args, &block)
|
49
|
+
network.foo(args, &block)
|
50
|
+
end
|
51
|
+
|
10
52
|
end
|
11
|
-
|
12
|
-
|
53
|
+
|
54
|
+
describe "#enterprise_engine" do
|
55
|
+
|
56
|
+
subject { network.enterprise_engine }
|
57
|
+
|
58
|
+
it { should_not eq(Gamifier.engine) }
|
59
|
+
it { subject.config[:enterprise_key].should eq(enterprise_key) }
|
60
|
+
|
13
61
|
end
|
14
62
|
|
15
|
-
describe "
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
63
|
+
describe "#get_key" do
|
64
|
+
|
65
|
+
let(:public_key) { Gamifier::ApiKey.new(:access => 'public', :key => 'public_0000') }
|
66
|
+
let(:private_key) { Gamifier::ApiKey.new(:access => 'private', :key => 'private_0000') }
|
67
|
+
|
68
|
+
subject { network.get_key }
|
69
|
+
|
70
|
+
context "without keys" do
|
71
|
+
|
72
|
+
it { should be_nil }
|
73
|
+
|
20
74
|
end
|
21
75
|
|
22
|
-
|
23
|
-
|
24
|
-
|
76
|
+
context "with a public key" do
|
77
|
+
|
78
|
+
before do
|
79
|
+
network.stub(:api_keys).and_return([public_key])
|
80
|
+
end
|
81
|
+
|
82
|
+
it { should be_nil }
|
83
|
+
|
25
84
|
end
|
26
85
|
|
86
|
+
context "with a private key" do
|
87
|
+
|
88
|
+
before do
|
89
|
+
network.stub(:api_keys).and_return([private_key])
|
90
|
+
end
|
91
|
+
|
92
|
+
it { should eq('private_0000') }
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
context "with both public and private key" do
|
97
|
+
|
98
|
+
before do
|
99
|
+
network.stub(:api_keys).and_return([public_key, private_key])
|
100
|
+
end
|
101
|
+
|
102
|
+
it { should eq('private_0000') }
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#site" do
|
109
|
+
|
110
|
+
it { expect { network.site('foo') }.to change{ network.sites.count }.by(1) }
|
111
|
+
it { subject.site('foo').name.should eq('foo') }
|
112
|
+
|
27
113
|
it "should call eval_with_context" do
|
28
|
-
block = proc{}
|
114
|
+
block = proc {}
|
29
115
|
Gamifier::DSL.should_receive(:eval_with_context).with(instance_of(Gamifier::DSL::Site), &block)
|
30
|
-
|
116
|
+
network.site('foo', &block)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should set values" do
|
120
|
+
o = network.site('foo') do
|
121
|
+
set :key, 'value'
|
122
|
+
end
|
123
|
+
o.key.should eq('value')
|
31
124
|
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#api_key" do
|
129
|
+
|
130
|
+
it { expect { network.api_key }.to change{ network.api_keys.count }.by(1) }
|
131
|
+
|
132
|
+
it "should call eval_with_context" do
|
133
|
+
block = proc {}
|
134
|
+
Gamifier::DSL.should_receive(:eval_with_context).with(instance_of(Gamifier::DSL::ApiKey), &block)
|
135
|
+
network.api_key(&block)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should set values" do
|
139
|
+
o = network.api_key do
|
140
|
+
set :key, 'value'
|
141
|
+
end
|
142
|
+
o.key.should eq('value')
|
143
|
+
end
|
144
|
+
|
32
145
|
end
|
33
146
|
|
34
|
-
end
|
147
|
+
end
|
data/spec/unit/dsl/site_spec.rb
CHANGED
@@ -1,54 +1,147 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gamifier::DSL::Site do
|
4
|
+
|
5
|
+
let(:site) { Gamifier::DSL::Site.new }
|
6
|
+
let(:url) { 'http://foo.com' }
|
7
|
+
let(:key) { '1234' }
|
8
|
+
let(:enterprise_key) { '5678' }
|
9
|
+
|
4
10
|
before do
|
5
|
-
|
11
|
+
Gamifier.set :uri => url, :key => key, :enterprise_key => enterprise_key
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#initialize" do
|
15
|
+
|
16
|
+
subject { site }
|
17
|
+
|
18
|
+
its(:source) { should_not be_nil }
|
19
|
+
its(:units) { should be_empty }
|
20
|
+
its(:behaviors) { should be_empty }
|
21
|
+
its(:rewards) { should be_empty }
|
22
|
+
its(:missions) { should be_empty }
|
23
|
+
its(:tracks) { should be_empty }
|
24
|
+
|
6
25
|
end
|
7
|
-
|
8
|
-
describe "creating units" do
|
9
26
|
|
10
|
-
|
11
|
-
|
27
|
+
describe "#engine" do
|
28
|
+
|
29
|
+
subject { site.engine }
|
30
|
+
|
31
|
+
it { should eq(Gamifier.engine) }
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#method_missing" do
|
36
|
+
|
37
|
+
let(:args) { 'bar' }
|
38
|
+
let(:block) { lambda {|x| x} }
|
39
|
+
|
40
|
+
it "should call on source" do
|
41
|
+
site.source.should_receive(:foo).with(args, &block)
|
42
|
+
site.foo(args, &block)
|
12
43
|
end
|
44
|
+
|
13
45
|
end
|
14
46
|
|
15
|
-
describe "
|
47
|
+
describe "#unit" do
|
48
|
+
|
49
|
+
it { expect { site.unit('foo') }.to change{ site.units.count }.by(1) }
|
50
|
+
it { subject.unit('foo').name.should eq('foo') }
|
16
51
|
|
17
|
-
it "
|
18
|
-
|
52
|
+
it "should call eval_with_context" do
|
53
|
+
block = proc {}
|
54
|
+
Gamifier::DSL.should_receive(:eval_with_context).with(instance_of(Gamifier::Unit), &block)
|
55
|
+
site.unit('foo', &block)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set values" do
|
59
|
+
o = site.unit('foo') do
|
60
|
+
set :key, 'value'
|
61
|
+
end
|
62
|
+
o.key.should eq('value')
|
19
63
|
end
|
20
64
|
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#behavior" do
|
68
|
+
|
69
|
+
it { expect { site.behavior('foo') }.to change{ site.behaviors.count }.by(1) }
|
70
|
+
it { subject.behavior('foo').name.should eq('foo') }
|
71
|
+
|
21
72
|
it "should call eval_with_context" do
|
22
|
-
block = proc{}
|
73
|
+
block = proc {}
|
23
74
|
Gamifier::DSL.should_receive(:eval_with_context).with(instance_of(Gamifier::ActivityDefinition), &block)
|
24
|
-
|
75
|
+
site.behavior('foo', &block)
|
25
76
|
end
|
26
77
|
|
27
|
-
it "should
|
28
|
-
|
78
|
+
it "should set values" do
|
79
|
+
o = site.behavior('foo') do
|
29
80
|
set :key, 'value'
|
30
|
-
set :enable, true
|
31
81
|
end
|
32
|
-
|
33
|
-
new_behavior.enable.should == true
|
82
|
+
o.key.should eq('value')
|
34
83
|
end
|
84
|
+
|
35
85
|
end
|
36
|
-
|
37
|
-
describe "
|
38
|
-
|
39
|
-
|
86
|
+
|
87
|
+
describe "#reward" do
|
88
|
+
|
89
|
+
it { expect { site.reward('foo') }.to change{ site.rewards.count }.by(1) }
|
90
|
+
it { subject.reward('foo').name.should eq('foo') }
|
91
|
+
|
92
|
+
it "should call eval_with_context" do
|
93
|
+
block = proc {}
|
94
|
+
Gamifier::DSL.should_receive(:eval_with_context).with(instance_of(Gamifier::RewardDefinition), &block)
|
95
|
+
site.reward('foo', &block)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should set values" do
|
99
|
+
o = site.reward('foo') do
|
100
|
+
set :key, 'value'
|
101
|
+
end
|
102
|
+
o.key.should eq('value')
|
40
103
|
end
|
104
|
+
|
41
105
|
end
|
42
|
-
|
43
|
-
describe "
|
44
|
-
|
45
|
-
|
106
|
+
|
107
|
+
describe "#mission" do
|
108
|
+
|
109
|
+
it { expect { site.mission('foo') }.to change{ site.missions.count }.by(1) }
|
110
|
+
it { subject.mission('foo').name.should eq('foo') }
|
111
|
+
|
112
|
+
it "should call eval_with_context" do
|
113
|
+
block = proc {}
|
114
|
+
Gamifier::DSL.should_receive(:eval_with_context).with(instance_of(Gamifier::Group), &block)
|
115
|
+
site.mission('foo', &block)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should set values" do
|
119
|
+
o = site.mission('foo') do
|
120
|
+
set :key, 'value'
|
121
|
+
end
|
122
|
+
o.key.should eq('value')
|
46
123
|
end
|
124
|
+
|
47
125
|
end
|
48
126
|
|
49
|
-
describe "
|
50
|
-
|
51
|
-
|
127
|
+
describe "#track" do
|
128
|
+
|
129
|
+
it { expect { site.track('foo') }.to change{ site.tracks.count }.by(1) }
|
130
|
+
it { subject.track('foo').label.should eq('foo') }
|
131
|
+
|
132
|
+
it "should call eval_with_context" do
|
133
|
+
block = proc {}
|
134
|
+
Gamifier::DSL.should_receive(:eval_with_context).with(instance_of(Gamifier::Track), &block)
|
135
|
+
site.track('foo', &block)
|
52
136
|
end
|
137
|
+
|
138
|
+
it "should set values" do
|
139
|
+
o = site.track('foo') do
|
140
|
+
set :key, 'value'
|
141
|
+
end
|
142
|
+
o.key.should eq('value')
|
143
|
+
end
|
144
|
+
|
53
145
|
end
|
54
|
-
|
146
|
+
|
147
|
+
end
|