fulcrum 0.1.6 → 0.2.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.
- checksums.yaml +8 -8
- data/LICENSE +2 -2
- data/README.md +189 -70
- data/Rakefile +5 -0
- data/fulcrum.gemspec +2 -3
- data/lib/fulcrum.rb +22 -14
- data/lib/fulcrum/actions/create.rb +15 -0
- data/lib/fulcrum/actions/delete.rb +12 -0
- data/lib/fulcrum/actions/find.rb +11 -0
- data/lib/fulcrum/actions/list.rb +19 -0
- data/lib/fulcrum/actions/update.rb +11 -0
- data/lib/fulcrum/changeset.rb +12 -0
- data/lib/fulcrum/choice_list.rb +6 -35
- data/lib/fulcrum/classification_set.rb +6 -36
- data/lib/fulcrum/client.rb +120 -0
- data/lib/fulcrum/form.rb +6 -35
- data/lib/fulcrum/layer.rb +6 -0
- data/lib/fulcrum/media_resource.rb +47 -0
- data/lib/fulcrum/membership.rb +5 -0
- data/lib/fulcrum/page.rb +17 -0
- data/lib/fulcrum/photo.rb +9 -29
- data/lib/fulcrum/project.rb +3 -9
- data/lib/fulcrum/record.rb +6 -35
- data/lib/fulcrum/resource.rb +40 -0
- data/lib/fulcrum/signature.rb +15 -0
- data/lib/fulcrum/version.rb +1 -1
- data/lib/fulcrum/video.rb +23 -0
- data/spec/client_helper.rb +9 -0
- data/spec/data/test.jpg +0 -0
- data/spec/data/test.mp4 +0 -0
- data/spec/data/test.png +0 -0
- data/spec/lib/choice_list_spec.rb +10 -115
- data/spec/lib/classification_set_spec.rb +11 -114
- data/spec/lib/client_spec.rb +9 -0
- data/spec/lib/form_spec.rb +10 -111
- data/spec/lib/layer_spec.rb +13 -0
- data/spec/lib/membership_spec.rb +12 -0
- data/spec/lib/photo_spec.rb +9 -88
- data/spec/lib/project_spec.rb +7 -23
- data/spec/lib/record_spec.rb +10 -115
- data/spec/lib/signature_spec.rb +16 -0
- data/spec/lib/video_spec.rb +16 -0
- data/spec/resource_examples.rb +147 -0
- data/spec/spec_helper.rb +2 -0
- metadata +37 -41
- data/.rvmrc +0 -1
- data/lib/fulcrum/api.rb +0 -99
- data/lib/fulcrum/member.rb +0 -16
- data/lib/fulcrum/validators/base_validator.rb +0 -31
- data/lib/fulcrum/validators/choice_list_validator.rb +0 -30
- data/lib/fulcrum/validators/classification_set_validator.rb +0 -38
- data/lib/fulcrum/validators/form_validator.rb +0 -150
- data/lib/fulcrum/validators/record_validator.rb +0 -18
- data/spec/data/form_data.json +0 -175
- data/spec/lib/api_spec.rb +0 -42
- data/spec/lib/member_spec.rb +0 -52
- data/spec/lib/validators/choice_list_validator_spec.rb +0 -73
- data/spec/lib/validators/classification_set_validator_spec.rb +0 -88
- data/spec/lib/validators/form_validator_spec.rb +0 -4
- data/spec/lib/validators/record_validator_spec.rb +0 -53
data/lib/fulcrum/project.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
module Fulcrum
|
2
|
-
class Project <
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def all(opts = {})
|
7
|
-
params = parse_opts([:page, :updated_since], opts)
|
8
|
-
call(:get, 'projects.json', params)
|
9
|
-
end
|
10
|
-
end
|
2
|
+
class Project < Resource
|
3
|
+
include Actions::List
|
4
|
+
include Actions::Find
|
11
5
|
end
|
12
6
|
end
|
13
7
|
|
data/lib/fulcrum/record.rb
CHANGED
@@ -1,38 +1,9 @@
|
|
1
1
|
module Fulcrum
|
2
|
-
class Record <
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
call(:get, 'records.json', params)
|
9
|
-
end
|
10
|
-
|
11
|
-
def find(id)
|
12
|
-
call(:get, "records/#{id}.json")
|
13
|
-
end
|
14
|
-
|
15
|
-
def create(record)
|
16
|
-
validation = RecordValidator.new(record)
|
17
|
-
if validation.valid?
|
18
|
-
call(:post, 'records.json', record)
|
19
|
-
else
|
20
|
-
{ error: { validation: validation.errors } }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def update(id, record)
|
25
|
-
validation = RecordValidator.new(record)
|
26
|
-
if validation.valid?
|
27
|
-
call(:put, "records/#{id}.json", record)
|
28
|
-
else
|
29
|
-
{ error: { validation: validation.errors } }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def delete(id)
|
34
|
-
call(:delete, "records/#{id}.json")
|
35
|
-
end
|
36
|
-
end
|
2
|
+
class Record < Resource
|
3
|
+
include Actions::List
|
4
|
+
include Actions::Find
|
5
|
+
include Actions::Create
|
6
|
+
include Actions::Update
|
7
|
+
include Actions::Delete
|
37
8
|
end
|
38
9
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Fulcrum
|
2
|
+
class Resource
|
3
|
+
attr_accessor :client
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
self.client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def resource_name
|
10
|
+
self.class.to_s.split('::').last.underscore
|
11
|
+
end
|
12
|
+
|
13
|
+
def resources_name
|
14
|
+
resource_name.pluralize
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(method = :get, path = '', params = {})
|
18
|
+
client.call(method, path, params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def collection(format = 'json')
|
22
|
+
"#{resources_name}.#{format}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def member(id, format = 'json')
|
26
|
+
"#{resources_name}/#{id}.#{format}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def member_action(id, action, format = 'json')
|
30
|
+
"#{resources_name}/#{id}/#{action}.#{format}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def attributes_for_object(object)
|
34
|
+
attributes = {}
|
35
|
+
attributes[resource_name] = object
|
36
|
+
attributes
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Fulcrum
|
2
|
+
class Signature < MediaResource
|
3
|
+
def default_content_type
|
4
|
+
'image/png'
|
5
|
+
end
|
6
|
+
|
7
|
+
def large(id, &blk)
|
8
|
+
download_version(id, 'large', &blk)
|
9
|
+
end
|
10
|
+
|
11
|
+
def thumbnail(id, &blk)
|
12
|
+
download_version(id, 'thumbnail', &blk)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/fulcrum/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Fulcrum
|
2
|
+
class Video < MediaResource
|
3
|
+
def default_content_type
|
4
|
+
'video/mp4'
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_action
|
8
|
+
'videos/upload'
|
9
|
+
end
|
10
|
+
|
11
|
+
def small(id, &blk)
|
12
|
+
download_version(id, 'small', &blk)
|
13
|
+
end
|
14
|
+
|
15
|
+
def medium(id, &blk)
|
16
|
+
download_version(id, 'medium', &blk)
|
17
|
+
end
|
18
|
+
|
19
|
+
def track(id)
|
20
|
+
call(:get, member_action(id, 'track'))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/data/test.jpg
CHANGED
Binary file
|
data/spec/data/test.mp4
ADDED
Binary file
|
data/spec/data/test.png
ADDED
Binary file
|
@@ -1,121 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
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
|
3
|
+
include Support::ResourceExamples
|
50
4
|
|
51
|
-
|
52
|
-
|
53
|
-
|
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 => 204, :body => '{"choice_list":{}}')
|
68
|
-
c = Fulcrum::ChoiceList.delete(cl_id)
|
69
|
-
Fulcrum::ChoiceList.response.status.should eq(204)
|
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
|
5
|
+
describe Fulcrum::ChoiceList do
|
6
|
+
include_context 'with client'
|
7
|
+
include_context 'with resource'
|
98
8
|
|
99
|
-
|
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
|
9
|
+
let(:resource) { client.choice_lists }
|
109
10
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
c.keys.should include(:error)
|
116
|
-
c[:error][:status].should eq(404)
|
117
|
-
c[:error][:message].should eq({ :message => "error message" })
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
11
|
+
include_examples 'list resource'
|
12
|
+
include_examples 'find resource'
|
13
|
+
include_examples 'create resource'
|
14
|
+
include_examples 'update resource'
|
15
|
+
include_examples 'delete resource'
|
121
16
|
end
|
@@ -1,120 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
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
|
3
|
+
include Support::ResourceExamples
|
63
4
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/classification_sets/#{cs_id}.json").to_return(:status => 204, :body => '{"classification_set":{}}')
|
68
|
-
c = Fulcrum::ClassificationSet.delete(cs_id)
|
69
|
-
Fulcrum::ClassificationSet.response.status.should eq(204)
|
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
|
5
|
+
describe Fulcrum::ClassificationSet do
|
6
|
+
include_context 'with client'
|
7
|
+
include_context 'with resource'
|
97
8
|
|
98
|
-
|
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
|
9
|
+
let(:resource) { client.classification_sets }
|
108
10
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
c.keys.should include(:error)
|
115
|
-
c[:error][:status].should eq(404)
|
116
|
-
c[:error][:message].should eq({ :message => "error message" })
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
11
|
+
include_examples 'list resource'
|
12
|
+
include_examples 'find resource'
|
13
|
+
include_examples 'create resource'
|
14
|
+
include_examples 'update resource'
|
15
|
+
include_examples 'delete resource'
|
120
16
|
end
|
17
|
+
|
data/spec/lib/form_spec.rb
CHANGED
@@ -1,117 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
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
|
-
records = {"current_page" => 1,"total_pages" => 1,"total_count" => 1,"per_page" => 50,"forms" => []}
|
16
|
-
stub_request(:get, "#{Fulcrum::Api.configuration.uri}/forms.json").to_return(:status => 200, :body => records.to_json)
|
17
|
-
forms = Fulcrum::Form.all
|
18
|
-
Fulcrum::Form.response.status.should eq(200)
|
19
|
-
forms = JSON.parse(forms)
|
20
|
-
forms.should == records
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context '#retrieve' do
|
25
|
-
it 'should retrieve the specified record and return 200' do
|
26
|
-
form_id = "abc"
|
27
|
-
stub_request(:get, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 200, :body => '{"form":{}}')
|
28
|
-
f = Fulcrum::Form.find(form_id)
|
29
|
-
Fulcrum::Form.response.status.should eq(200)
|
30
|
-
f = JSON.parse(f)
|
31
|
-
f.keys.should include('form')
|
32
|
-
f['form'].should be_a(Hash)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context '#create' do
|
37
|
-
it 'should return created form with status 201' do
|
38
|
-
stub_request(:post, "#{Fulcrum::Api.configuration.uri}/forms.json").to_return(:status => 201, :body => '{"form":{}}')
|
39
|
-
Fulcrum::FormValidator.any_instance.stub(:validate!).and_return(true)
|
40
|
-
f = Fulcrum::Form.create({})
|
41
|
-
Fulcrum::Form.response.status.should eq(201)
|
42
|
-
f = JSON.parse(f)
|
43
|
-
f.keys.should include('form')
|
44
|
-
f['form'].should be_a(Hash)
|
45
|
-
end
|
46
|
-
end
|
3
|
+
include Support::ResourceExamples
|
47
4
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
stub_request(:put, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 200, :body => '{"form":{}}')
|
52
|
-
Fulcrum::FormValidator.any_instance.stub(:validate!).and_return(true)
|
53
|
-
f = Fulcrum::Form.update(form_id, {})
|
54
|
-
Fulcrum::Form.response.status.should eq(200)
|
55
|
-
f = JSON.parse(f)
|
56
|
-
f.keys.should include('form')
|
57
|
-
f['form'].should be_a(Hash)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context '#delete' do
|
62
|
-
it 'should return deleted form with status 200' do
|
63
|
-
form_id = 'abc'
|
64
|
-
stub_request(:delete, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 204, :body => '{"form":{}}')
|
65
|
-
f = Fulcrum::Form.delete(form_id)
|
66
|
-
Fulcrum::Form.response.status.should eq(204)
|
67
|
-
f = JSON.parse(f)
|
68
|
-
f.keys.should include('form')
|
69
|
-
f['form'].should be_a(Hash)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'unsuccessful requests' do
|
75
|
-
context '#retrieve' do
|
76
|
-
it 'should receive 404' do
|
77
|
-
form_id = 'abc'
|
78
|
-
stub_request(:get, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 404)
|
79
|
-
c = Fulcrum::Form.find(form_id)
|
80
|
-
c.keys.should include(:error)
|
81
|
-
c[:error][:status].should eq(404)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context '#create' do
|
86
|
-
it 'should receive a 422 response' do
|
87
|
-
stub_request(:post, "#{Fulcrum::Api.configuration.uri}/forms.json").to_return(:status => 422)
|
88
|
-
Fulcrum::FormValidator.any_instance.stub(:validate!).and_return(true)
|
89
|
-
c = Fulcrum::Form.create({})
|
90
|
-
c.keys.should include(:error)
|
91
|
-
c[:error][:status].should eq(422)
|
92
|
-
end
|
93
|
-
end
|
5
|
+
describe Fulcrum::Form do
|
6
|
+
include_context 'with client'
|
7
|
+
include_context 'with resource'
|
94
8
|
|
95
|
-
|
96
|
-
it 'should receive a 422 response' do
|
97
|
-
form_id = 'abc'
|
98
|
-
stub_request(:put, "#{Fulcrum::Api.configuration.uri}/forms/#{form_id}.json").to_return(:status => 422)
|
99
|
-
Fulcrum::FormValidator.any_instance.stub(:validate!).and_return(true)
|
100
|
-
c = Fulcrum::Form.update(form_id, {})
|
101
|
-
c.keys.should include(:error)
|
102
|
-
c[:error][:status].should eq(422)
|
103
|
-
end
|
104
|
-
end
|
9
|
+
let(:resource) { client.forms }
|
105
10
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
c.keys.should include(:error)
|
112
|
-
c[:error][:status].should eq(404)
|
113
|
-
c[:error][:message].should eq({ :message => "error message" })
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
11
|
+
include_examples 'list resource'
|
12
|
+
include_examples 'find resource'
|
13
|
+
include_examples 'create resource'
|
14
|
+
include_examples 'update resource'
|
15
|
+
include_examples 'delete resource'
|
117
16
|
end
|