gamifier 1.0.8 → 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.
@@ -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
- 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
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 => "1234@test.com", :site => "ibadgedyou.dev", :display_name => "John Doe"}
18
+ { :email => "user@foo.com", :site => "foo.com", :display_name => "Foo Bar" }
19
19
  end
20
20
 
21
21
  def user_attributes
22
- {:email => "1234@test.com"}
22
+ { :email => "user@foo.com" }
23
23
  end
24
24
 
25
25
  def find_or_create_test_user
26
- user = ENGINE.users.find(user_attributes[:email]) || ENGINE.users.build(user_attributes).save
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 = ENGINE.players.find_by_site_and_email(player_attributes[:site], player_attributes[:email])
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 = ENGINE.players.find_by_site_and_email(player_attributes[:site], player_attributes[:email])
40
+ player = Gamifier.engine.players.find_by_site_and_email(player_attributes[:site], player_attributes[:email])
41
41
  if player.nil?
42
- player = ENGINE.players.build(player_attributes).save
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
- before do
5
- @engine = mock(Gamifier::Engine)
6
- @collection = Gamifier::Collection.new(@engine, Gamifier::Model)
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
- @collection.should respond_to(method)
10
+ collection.should respond_to(method)
12
11
  end
13
12
  end
14
13
 
15
- it "should correctly build a new object with a correct reference to the current engine" do
16
- object = @collection.build(:key => "value")
17
- object.should be_a(Gamifier::Model)
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 raise an error if no site is given when calling #reset!" do
22
- expect{
23
- @collection.reset!
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
- @collection.should_receive(:all).with(:site => "xyz").and_yield model
31
- @collection.reset!(:site => "xyz")
29
+ collection.should_receive(:all).with(:site => "xyz").and_yield model
30
+ collection.reset!(:site => "xyz")
32
31
  end
33
- end
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 => "http://somewhere.ltd/path/", :key => "1234"
6
- @network = Gamifier::DSL::Network.new
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
- it "should be linked to the gamifier engine" do
9
- @network.engine.should == Gamifier.engine
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
- it "should have an empty list of sites" do
12
- @network.sites.should be_empty
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 "creating sites" do
16
- it "should add a new site to its list when calling #site" do
17
- expect {
18
- @network.site 'site-name'
19
- }.to change{ @network.sites.count }.by(1)
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
- it "creates a site with the given name" do
23
- new_site = @network.site 'site-name'
24
- new_site.name.should == 'site-name'
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
- @network.site 'site-name', &block
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
@@ -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
- @site = Gamifier::DSL::Site.new(:name => "site-name")
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
- it "adds a unit to the site" do
11
- expect{ @site.unit 'unit-name' }.to change{ @site.units.count }.by(1)
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 "creating behaviours" do
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 "adds a behavior to the site" do
18
- expect{ @site.behavior 'behavior-name' }.to change{ @site.behaviors.count }.by(1)
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
- @site.behavior 'behavior-name', &block
75
+ site.behavior('foo', &block)
25
76
  end
26
77
 
27
- it "should work" do
28
- new_behavior = @site.behavior 'behavior-name' do
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
- new_behavior.key.should == 'value'
33
- new_behavior.enable.should == true
82
+ o.key.should eq('value')
34
83
  end
84
+
35
85
  end
36
-
37
- describe "creating rewards" do
38
- it "adds a reward to the site" do
39
- expect{ @site.reward 'reward-name' }.to change{ @site.rewards.count }.by(1)
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 "creating missions" do
44
- it "adds a mission to the site" do
45
- expect{ @site.mission 'mission-name' }.to change{ @site.missions.count }.by(1)
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 "creating tracks" do
50
- it "adds a track to the site" do
51
- expect{ @site.track 'track-name' }.to change{ @site.tracks.count }.by(1)
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
- end
146
+
147
+ end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Gamifier::DSL do
4
-
4
+
5
5
  class Whatever
6
6
  include Gamifier::DSL
7
7
  end
8
8
 
9
- end
9
+ end