fulcrum 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fulcrum::Api do
4
+ before(:all) do
5
+ @uri = 'http://foo.bar/api/v2'
6
+ @key = 'foobar'
7
+ Fulcrum::Api.configure do |config|
8
+ config.uri = 'http://foo.bar/api/v2'
9
+ config.key = 'foobar'
10
+ end
11
+ end
12
+
13
+ it 'should be configured' do
14
+ Fulcrum::Api.configuration.uri.should eq(@uri)
15
+ Fulcrum::Api.configuration.key.should eq(@key)
16
+ end
17
+
18
+ it 'should get the key' do
19
+ user = "foo@bar.com"
20
+ pass = "foobar"
21
+ stub_request(:get, /.*\/users.json/).to_return(:status => 200, :body => '{ "user": { "api_token": "foobar" }}')
22
+ Fulcrum::Api.get_key(user, pass).should eq('foobar')
23
+ end
24
+
25
+ it 'parse_opts should return only expected opts' do
26
+ params = Fulcrum::Api.parse_opts([:foo], { foo: 'bar', bar: 'foo'})
27
+ params.has_key?(:foo).should be(true)
28
+ params[:foo].should eq('bar')
29
+ params.has_key?(:bar).should be(false)
30
+ end
31
+
32
+ it 'call should raise ArgumentError with invalid method' do
33
+ expect { Fulcrum::Api.call(:foo) }.to raise_error(ArgumentError)
34
+ end
35
+
36
+ it 'call should not raise ArgumentError with valid method' do
37
+ expect { Fulcrum::Api.call(:get) }.to_not raise_error(ArgumentError)
38
+ end
39
+ end
@@ -0,0 +1,120 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fulcrum::ChoiceList do
4
+ before(:all) do
5
+ Fulcrum::Api.configure do |config|
6
+ config.uri = 'http://foo.bar/api/v2'
7
+ config.key = 'foobar'
8
+ end
9
+ end
10
+
11
+ describe 'successful requests' do
12
+ context '#all' do
13
+ it 'should retrieve all choice_lists' do
14
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/choice_lists.json").to_return(:status => 200, :body => '{"current_page":1,"total_pages":1,"total_count":1,"per_page":50,"choice_lists":[]}')
15
+ cls = Fulcrum::ChoiceList.all
16
+ Fulcrum::ChoiceList.response.status.should eq(200)
17
+ cls = JSON.parse(cls)
18
+ cls.keys.should include('current_page')
19
+ cls.keys.should include('total_pages')
20
+ cls.keys.should include('total_count')
21
+ cls.keys.should include('per_page')
22
+ cls.keys.should include('choice_lists')
23
+ cls['choice_lists'].should be_a(Array)
24
+ end
25
+ end
26
+
27
+ context '#retrieve' do
28
+ it 'should retrieve the specified choice_list and return 200' do
29
+ cl_id = "abc"
30
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/choice_lists/#{cl_id}.json").to_return(:status => 200, :body => '{"choice_list":{}}')
31
+ c = Fulcrum::ChoiceList.find(cl_id)
32
+ Fulcrum::ChoiceList.response.status.should eq(200)
33
+ c = JSON.parse(c)
34
+ c.keys.should include('choice_list')
35
+ c['choice_list'].should be_a(Hash)
36
+ end
37
+ end
38
+
39
+ context '#create' do
40
+ it 'should return created choice_list with status 201' do
41
+ stub_request(:post, "#{Fulcrum::Api.configuration.uri}/choice_lists.json").to_return(:status => 201, :body => '{"choice_list":{}}')
42
+ Fulcrum::ChoiceListValidator.any_instance.stub(:validate!).and_return(true)
43
+ c = Fulcrum::ChoiceList.create({})
44
+ Fulcrum::ChoiceList.response.status.should eq(201)
45
+ c = JSON.parse(c)
46
+ c.keys.should include('choice_list')
47
+ c['choice_list'].should be_a(Hash)
48
+ end
49
+ end
50
+
51
+ context '#update' do
52
+ it 'should return updated choice_list with status 200' do
53
+ cl_id = 'abc'
54
+ stub_request(:put, "#{Fulcrum::Api.configuration.uri}/choice_lists/#{cl_id}.json").to_return(:status => 200, :body => '{"choice_list":{}}')
55
+ Fulcrum::ChoiceListValidator.any_instance.stub(:validate!).and_return(true)
56
+ c = Fulcrum::ChoiceList.update(cl_id, {})
57
+ Fulcrum::ChoiceList.response.status.should eq(200)
58
+ c = JSON.parse(c)
59
+ c.keys.should include('choice_list')
60
+ c['choice_list'].should be_a(Hash)
61
+ end
62
+ end
63
+
64
+ context '#delete' do
65
+ it 'should return deleted choice_list with status 200' do
66
+ cl_id = 'abc'
67
+ stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/choice_lists/#{cl_id}.json").to_return(:status => 200, :body => '{"choice_list":{}}')
68
+ c = Fulcrum::ChoiceList.delete(cl_id)
69
+ Fulcrum::ChoiceList.response.status.should eq(200)
70
+ c = JSON.parse(c)
71
+ c.keys.should include('choice_list')
72
+ c['choice_list'].should be_a(Hash)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe 'unsuccessful requests' do
78
+ context '#retrieve' do
79
+ it 'should receive 404' do
80
+ cl_id = 'abc'
81
+ body = { :a => 'b' }
82
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/choice_lists/#{cl_id}.json").to_return(:status => 404, :body => body)
83
+ c = Fulcrum::ChoiceList.find(cl_id)
84
+ c.keys.should include(:error)
85
+ c[:error][:status].should eq(404)
86
+ end
87
+ end
88
+
89
+ context '#create' do
90
+ it 'should receive a 422 response' do
91
+ stub_request(:post, "#{Fulcrum::Api.configuration.uri}/choice_lists.json").to_return(:status => 422)
92
+ Fulcrum::ChoiceListValidator.any_instance.stub(:validate!).and_return(true)
93
+ c = Fulcrum::ChoiceList.create({})
94
+ c.keys.should include(:error)
95
+ c[:error][:status].should eq(422)
96
+ end
97
+ end
98
+
99
+ context '#update' do
100
+ it 'should receive a 422 response' do
101
+ cl_id = 'abc'
102
+ stub_request(:put, "#{Fulcrum::Api.configuration.uri}/choice_lists/#{cl_id}.json").to_return(:status => 422)
103
+ Fulcrum::ChoiceListValidator.any_instance.stub(:validate!).and_return(true)
104
+ c = Fulcrum::ChoiceList.update(cl_id, {})
105
+ c.keys.should include(:error)
106
+ c[:error][:status].should eq(422)
107
+ end
108
+ end
109
+
110
+ context '#delete' do
111
+ it 'should receive a 404 response' do
112
+ cl_id = 'abc'
113
+ stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/choice_lists/#{cl_id}.json").to_return(:status => 404)
114
+ c = Fulcrum::ChoiceList.delete(cl_id)
115
+ c.keys.should include(:error)
116
+ c[:error][:status].should eq(404)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fulcrum::ClassificationSet do
4
+ before(:all) do
5
+ Fulcrum::Api.configure do |config|
6
+ config.uri = 'http://foo.bar/api/v2'
7
+ config.key = 'foobar'
8
+ end
9
+ end
10
+
11
+ describe 'successful requests' do
12
+ context '#all' do
13
+ it 'should retrieve all classification_sets' do
14
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/classification_sets.json").to_return(:status => 200, :body => '{"current_page":1,"total_pages":1,"total_count":1,"per_page":50,"classification_sets":[]}')
15
+ css = Fulcrum::ClassificationSet.all
16
+ Fulcrum::ClassificationSet.response.status.should eq(200)
17
+ css = JSON.parse(css)
18
+ css.keys.should include('current_page')
19
+ css.keys.should include('total_pages')
20
+ css.keys.should include('total_count')
21
+ css.keys.should include('per_page')
22
+ css.keys.should include('classification_sets')
23
+ css['classification_sets'].should be_a(Array)
24
+ end
25
+ end
26
+
27
+ context '#retrieve' do
28
+ it 'should retrieve the specified classification_set and return 200' do
29
+ cs_id = "abc"
30
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/classification_sets/#{cs_id}.json").to_return(:status => 200, :body => '{"classification_set":{}}')
31
+ c = Fulcrum::ClassificationSet.find(cs_id)
32
+ Fulcrum::ClassificationSet.response.status.should eq(200)
33
+ c = JSON.parse(c)
34
+ c.keys.should include('classification_set')
35
+ c['classification_set'].should be_a(Hash)
36
+ end
37
+ end
38
+
39
+ context '#create' do
40
+ it 'should return created classification_set with status 201' do
41
+ stub_request(:post, "#{Fulcrum::Api.configuration.uri}/classification_sets.json").to_return(:status => 201, :body => '{"classification_set":{}}')
42
+ Fulcrum::ClassificationSetValidator.any_instance.stub(:validate!).and_return(true)
43
+ c = Fulcrum::ClassificationSet.create({})
44
+ Fulcrum::ClassificationSet.response.status.should eq(201)
45
+ c = JSON.parse(c)
46
+ c.keys.should include('classification_set')
47
+ c['classification_set'].should be_a(Hash)
48
+ end
49
+ end
50
+
51
+ context '#update' do
52
+ it 'should return updated classification_set with status 200' do
53
+ cs_id = 'abc'
54
+ stub_request(:put, "#{Fulcrum::Api.configuration.uri}/classification_sets/#{cs_id}.json").to_return(:status => 200, :body => '{"classification_set":{}}')
55
+ Fulcrum::ClassificationSetValidator.any_instance.stub(:validate!).and_return(true)
56
+ c = Fulcrum::ClassificationSet.update(cs_id, {})
57
+ Fulcrum::ClassificationSet.response.status.should eq(200)
58
+ c = JSON.parse(c)
59
+ c.keys.should include('classification_set')
60
+ c['classification_set'].should be_a(Hash)
61
+ end
62
+ end
63
+
64
+ context '#delete' do
65
+ it 'should return deleted classification_set with status 200' do
66
+ cs_id = 'abc'
67
+ stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/classification_sets/#{cs_id}.json").to_return(:status => 200, :body => '{"classification_set":{}}')
68
+ c = Fulcrum::ClassificationSet.delete(cs_id)
69
+ Fulcrum::ClassificationSet.response.status.should eq(200)
70
+ c = JSON.parse(c)
71
+ c.keys.should include('classification_set')
72
+ c['classification_set'].should be_a(Hash)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe 'unsuccessful requests' do
78
+ context '#retrieve' do
79
+ it 'should receive 404' do
80
+ cs_id = 'abc'
81
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/classification_sets/#{cs_id}.json").to_return(:status => 404)
82
+ c = Fulcrum::ClassificationSet.find(cs_id)
83
+ c.keys.should include(:error)
84
+ c[:error][:status].should eq(404)
85
+ end
86
+ end
87
+
88
+ context '#create' do
89
+ it 'should receive a 422 response' do
90
+ stub_request(:post, "#{Fulcrum::Api.configuration.uri}/classification_sets.json").to_return(:status => 422)
91
+ Fulcrum::ClassificationSetValidator.any_instance.stub(:validate!).and_return(true)
92
+ c = Fulcrum::ClassificationSet.create({})
93
+ c.keys.should include(:error)
94
+ c[:error][:status].should eq(422)
95
+ end
96
+ end
97
+
98
+ context '#update' do
99
+ it 'should receive a 422 response' do
100
+ cs_id = 'abc'
101
+ stub_request(:put, "#{Fulcrum::Api.configuration.uri}/classification_sets/#{cs_id}.json").to_return(:status => 422)
102
+ Fulcrum::ClassificationSetValidator.any_instance.stub(:validate!).and_return(true)
103
+ c = Fulcrum::ClassificationSet.update(cs_id, {})
104
+ c.keys.should include(:error)
105
+ c[:error][:status].should eq(422)
106
+ end
107
+ end
108
+
109
+ context '#delete' do
110
+ it 'should receive a 404 response' do
111
+ cs_id = 'abc'
112
+ stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/classification_sets/#{cs_id}.json").to_return(:status => 404)
113
+ c = Fulcrum::ClassificationSet.delete(cs_id)
114
+ c.keys.should include(:error)
115
+ c[:error][:status].should eq(404)
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,120 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fulcrum::Form do
4
+
5
+ before(:all) do
6
+ Fulcrum::Api.configure do |config|
7
+ config.uri = 'http://foo.bar/api/v2'
8
+ config.key = 'foobar'
9
+ end
10
+ end
11
+
12
+ describe 'successful requests' do
13
+ context '#all' do
14
+ it 'should retrieve all records' do
15
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/forms.json").to_return(:status => 200, :body => '{"current_page":1,"total_pages":1,"total_count":1,"per_page":50,"forms":[]}')
16
+ forms = Fulcrum::Form.all
17
+ Fulcrum::Form.response.status.should eq(200)
18
+ forms = JSON.parse(forms)
19
+ forms.keys.should include('current_page')
20
+ forms.keys.should include('total_pages')
21
+ forms.keys.should include('total_count')
22
+ forms.keys.should include('per_page')
23
+ forms.keys.should include('forms')
24
+ forms['forms'].should be_a(Array)
25
+ end
26
+ end
27
+
28
+ context '#retrieve' do
29
+ it 'should retrieve the specified record and return 200' do
30
+ form_id = "abc"
31
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 200, :body => '{"form":{}}')
32
+ f = Fulcrum::Form.find(form_id)
33
+ Fulcrum::Form.response.status.should eq(200)
34
+ f = JSON.parse(f)
35
+ f.keys.should include('form')
36
+ f['form'].should be_a(Hash)
37
+ end
38
+ end
39
+
40
+ context '#create' do
41
+ it 'should return created form with status 201' do
42
+ stub_request(:post, "#{Fulcrum::Api.configuration.uri}/forms.json").to_return(:status => 201, :body => '{"form":{}}')
43
+ Fulcrum::FormValidator.any_instance.stub(:validate!).and_return(true)
44
+ f = Fulcrum::Form.create({})
45
+ Fulcrum::Form.response.status.should eq(201)
46
+ f = JSON.parse(f)
47
+ f.keys.should include('form')
48
+ f['form'].should be_a(Hash)
49
+ end
50
+ end
51
+
52
+ context '#update' do
53
+ it 'should return updated form with status 200' do
54
+ form_id = 'abc'
55
+ stub_request(:put, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 200, :body => '{"form":{}}')
56
+ Fulcrum::FormValidator.any_instance.stub(:validate!).and_return(true)
57
+ f = Fulcrum::Form.update(form_id, {})
58
+ Fulcrum::Form.response.status.should eq(200)
59
+ f = JSON.parse(f)
60
+ f.keys.should include('form')
61
+ f['form'].should be_a(Hash)
62
+ end
63
+ end
64
+
65
+ context '#delete' do
66
+ it 'should return deleted form with status 200' do
67
+ form_id = 'abc'
68
+ stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 200, :body => '{"form":{}}')
69
+ f = Fulcrum::Form.delete(form_id)
70
+ Fulcrum::Form.response.status.should eq(200)
71
+ f = JSON.parse(f)
72
+ f.keys.should include('form')
73
+ f['form'].should be_a(Hash)
74
+ end
75
+ end
76
+ end
77
+
78
+ describe 'unsuccessful requests' do
79
+ context '#retrieve' do
80
+ it 'should receive 404' do
81
+ form_id = 'abc'
82
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 404)
83
+ c = Fulcrum::Form.find(form_id)
84
+ c.keys.should include(:error)
85
+ c[:error][:status].should eq(404)
86
+ end
87
+ end
88
+
89
+ context '#create' do
90
+ it 'should receive a 422 response' do
91
+ stub_request(:post, "#{Fulcrum::Api.configuration.uri}/forms.json").to_return(:status => 422)
92
+ Fulcrum::FormValidator.any_instance.stub(:validate!).and_return(true)
93
+ c = Fulcrum::Form.create({})
94
+ c.keys.should include(:error)
95
+ c[:error][:status].should eq(422)
96
+ end
97
+ end
98
+
99
+ context '#update' do
100
+ it 'should receive a 422 response' do
101
+ form_id = 'abc'
102
+ stub_request(:put, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 422)
103
+ Fulcrum::FormValidator.any_instance.stub(:validate!).and_return(true)
104
+ c = Fulcrum::Form.update(form_id, {})
105
+ c.keys.should include(:error)
106
+ c[:error][:status].should eq(422)
107
+ end
108
+ end
109
+
110
+ context '#delete' do
111
+ it 'should receive a 404 response' do
112
+ form_id = 'abc'
113
+ stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 404)
114
+ c = Fulcrum::Form.delete(form_id)
115
+ c.keys.should include(:error)
116
+ c[:error][:status].should eq(404)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fulcrum::Member do
4
+
5
+ before(:all) do
6
+ Fulcrum::Api.configure do |config|
7
+ config.uri = 'http://foo.bar/api/v2'
8
+ config.key = 'foobar'
9
+ end
10
+ end
11
+
12
+ describe 'successful requests' do
13
+ context '#all' do
14
+ it 'should retrieve all members' do
15
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/members.json").to_return(:status => 200, :body => '{"current_page":1,"total_pages":1,"total_count":1,"per_page":50,"members":[]}')
16
+ members = Fulcrum::Member.all
17
+ Fulcrum::Member.response.status.should eq(200)
18
+ members = JSON.parse(members)
19
+ members.keys.should include('current_page')
20
+ members.keys.should include('total_pages')
21
+ members.keys.should include('total_count')
22
+ members.keys.should include('per_page')
23
+ members.keys.should include('members')
24
+ members['members'].should be_a(Array)
25
+ end
26
+ end
27
+
28
+ context '#retrieve' do
29
+ it 'should retrieve the specified member' do
30
+ member_id = 'abc'
31
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/members/#{member_id}.json").to_return(:status => 200, :body => '{"member":{}}')
32
+ m = Fulcrum::Member.find('abc')
33
+ Fulcrum::Member.response.status.should eq(200)
34
+ m = JSON.parse(m)
35
+ m.keys.should include('member')
36
+ m['member'].should be_a(Hash)
37
+ end
38
+ end
39
+ end
40
+
41
+ describe 'unsuccessful requests' do
42
+ context '#retrieve' do
43
+ it 'should receive 404' do
44
+ member_id = 'abc'
45
+ stub_request(:get, "#{Fulcrum::Api.configuration.uri}/members/#{member_id}.json").to_return(:status => 404)
46
+ m = Fulcrum::Member.find(member_id)
47
+ m.keys.should include(:error)
48
+ m[:error][:status].should eq(404)
49
+ end
50
+ end
51
+ end
52
+ end