supplejack_client 1.0.4 → 1.0.5
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 +4 -4
- data/.rubocop.yml +21 -0
- data/.rubocop_todo.yml +506 -0
- data/.travis.yml +15 -0
- data/Gemfile +5 -1
- data/Guardfile +5 -5
- data/lib/supplejack/concept.rb +87 -0
- data/lib/supplejack/config.rb +5 -1
- data/lib/supplejack/controllers/helpers.rb +2 -0
- data/lib/supplejack/engine.rb +1 -0
- data/lib/supplejack/exceptions.rb +3 -0
- data/lib/supplejack/item_relation.rb +3 -1
- data/lib/supplejack/log_subscriber.rb +2 -0
- data/lib/supplejack/record.rb +9 -23
- data/lib/supplejack/request.rb +14 -4
- data/lib/supplejack/search.rb +17 -11
- data/lib/supplejack/url_formats/item_hash.rb +43 -37
- data/lib/supplejack/user.rb +5 -0
- data/lib/supplejack/user_set.rb +12 -8
- data/lib/supplejack/util.rb +1 -1
- data/lib/supplejack/version.rb +1 -1
- data/lib/supplejack_client.rb +2 -1
- data/spec/spec_helper.rb +6 -0
- data/spec/supplejack/concept_spec.rb +130 -0
- data/spec/supplejack/user_set_spec.rb +8 -8
- data/supplejack_client.gemspec +2 -1
- metadata +31 -5
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# The Supplejack Client code is Crown copyright (C) 2014, New Zealand Government,
|
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
|
3
|
+
# See https://github.com/DigitalNZ/supplejack_client for details.
|
|
4
|
+
#
|
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ
|
|
6
|
+
# and the Department of Internal Affairs. http://digitalnz.org/supplejack
|
|
7
|
+
|
|
8
|
+
require 'spec_helper'
|
|
9
|
+
|
|
10
|
+
class SupplejackConcept
|
|
11
|
+
include Supplejack::Concept
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Search < Supplejack::Search
|
|
15
|
+
def initialize(params={})
|
|
16
|
+
super
|
|
17
|
+
self.or = {:type => ['Person']}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class SpecialSearch < Supplejack::Search
|
|
22
|
+
def initialize(params={})
|
|
23
|
+
super(params)
|
|
24
|
+
if self.api_params && self.api_params[:and]
|
|
25
|
+
self.api_params[:and].delete(:format)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
module Supplejack
|
|
31
|
+
describe Concept do
|
|
32
|
+
it 'initializes its attributes from a JSON string' do
|
|
33
|
+
concept = SupplejackConcept.new(%{{"name": "Name", "prefLabel": "Label"}})
|
|
34
|
+
concept.attributes.should eq({name: 'Name', prefLabel: 'Label'})
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'handles nil params' do
|
|
38
|
+
concept = SupplejackConcept.new(nil)
|
|
39
|
+
concept.attributes.should eq({})
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'handles a string as params' do
|
|
43
|
+
concept = SupplejackConcept.new('')
|
|
44
|
+
concept.attributes.should eq({})
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'handles a array as params' do
|
|
48
|
+
concept = SupplejackConcept.new([])
|
|
49
|
+
concept.attributes.should eq({})
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'raises a NoMethodError for every method call that doesn\'t have a key in the attributes' do
|
|
53
|
+
concept = SupplejackConcept.new
|
|
54
|
+
expect { concept.something }.to raise_error(NoMethodError)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'should return the value when is present in the attributes' do
|
|
58
|
+
concept = SupplejackConcept.new(:weird_method => 'Something')
|
|
59
|
+
concept.weird_method.should eq 'Something'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe 'id' do
|
|
63
|
+
it 'returns the concept_id' do
|
|
64
|
+
concept = SupplejackConcept.new({'concept_id' => '95'})
|
|
65
|
+
concept.id.should eq 95
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'returns the id' do
|
|
69
|
+
concept = SupplejackConcept.new({'id' => '96'})
|
|
70
|
+
concept.id.should eq 96
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe '#name' do
|
|
75
|
+
it 'returns the title attribute value' do
|
|
76
|
+
SupplejackConcept.new(name: 'Name').name.should eq 'Name'
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'returns "Unknown" for concepts without a title' do
|
|
80
|
+
SupplejackConcept.new(name: nil).name.should eq 'Unknown'
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
[:next_concept, :previous_concept, :next_page, :previous_page].each do |attr|
|
|
85
|
+
describe "#{attr}" do
|
|
86
|
+
it "returns the #{attr}" do
|
|
87
|
+
concept = SupplejackConcept.new({attr => 1})
|
|
88
|
+
concept.send(attr).should eq 1
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "returns the nil" do
|
|
92
|
+
concept = SupplejackConcept.new({})
|
|
93
|
+
concept.send(attr).should be_nil
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe '#find' do
|
|
99
|
+
context 'single concept' do
|
|
100
|
+
it 'raises a Supplejack::ConceptNotFound' do
|
|
101
|
+
SupplejackConcept.stub(:get).and_raise(RestClient::ResourceNotFound)
|
|
102
|
+
expect { SupplejackConcept.find(1) }.to raise_error(Supplejack::ConceptNotFound)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'raises a Supplejack::MalformedRequest' do
|
|
106
|
+
expect { SupplejackConcept.find('replace_this') }.to raise_error(Supplejack::MalformedRequest)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'requests the concept from the API' do
|
|
110
|
+
SupplejackConcept.should_receive(:get).with('/concepts/1', {}).and_return({'concept' => {}})
|
|
111
|
+
SupplejackConcept.find(1)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'initializes a new SupplejackConcept object' do
|
|
115
|
+
SupplejackConcept.stub(:get).and_return({'concept_id' => '1', 'name' => 'Wellington'})
|
|
116
|
+
concept = SupplejackConcept.find(1)
|
|
117
|
+
concept.class.should eq SupplejackConcept
|
|
118
|
+
concept.id.should eq 1
|
|
119
|
+
concept.name.should eq 'Wellington'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'send the fields defined in the configuration' do
|
|
123
|
+
Supplejack.stub(:fields) { [:verbose,:default] }
|
|
124
|
+
SupplejackConcept.should_receive(:get).with('/concepts/1', {}).and_return({'concept' => {}})
|
|
125
|
+
SupplejackConcept.find(1)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -21,7 +21,7 @@ module Supplejack
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
describe '#initialize' do
|
|
24
|
-
[:id, :name, :description, :privacy, :url, :priority, :count, :tag_list, :
|
|
24
|
+
[:id, :name, :description, :privacy, :url, :priority, :count, :tag_list, :featured, :approved].each do |attribute|
|
|
25
25
|
it "initializes the #{attribute}" do
|
|
26
26
|
Supplejack::UserSet.new({attribute => 'value'}).send(attribute).should eq 'value'
|
|
27
27
|
end
|
|
@@ -69,9 +69,9 @@ module Supplejack
|
|
|
69
69
|
supplejack_set.api_attributes
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
-
it 'should send the
|
|
73
|
-
supplejack_set.
|
|
74
|
-
supplejack_set.api_attributes.should include(
|
|
72
|
+
it 'should send the featured value' do
|
|
73
|
+
supplejack_set.featured = true
|
|
74
|
+
supplejack_set.api_attributes.should include(featured: true)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
it 'returns a array of records with only id and position' do
|
|
@@ -443,20 +443,20 @@ module Supplejack
|
|
|
443
443
|
end
|
|
444
444
|
end
|
|
445
445
|
|
|
446
|
-
describe '#
|
|
446
|
+
describe '#featured_sets' do
|
|
447
447
|
before :each do
|
|
448
448
|
Supplejack::UserSet.stub(:get) { {'sets' => [{'id' => '123', 'name' => 'Dog'}]} }
|
|
449
449
|
end
|
|
450
450
|
|
|
451
451
|
it 'fetches the public sets from the api' do
|
|
452
|
-
Supplejack::UserSet.should_receive(:get).with('/sets/
|
|
453
|
-
Supplejack::UserSet.
|
|
452
|
+
Supplejack::UserSet.should_receive(:get).with('/sets/featured')
|
|
453
|
+
Supplejack::UserSet.featured_sets
|
|
454
454
|
end
|
|
455
455
|
|
|
456
456
|
it 'returns an array of user set objects' do
|
|
457
457
|
@set = supplejack_set
|
|
458
458
|
Supplejack::UserSet.should_receive(:new).once.with({'id' => '123', 'name' => 'Dog'}) { @set }
|
|
459
|
-
sets = Supplejack::UserSet.
|
|
459
|
+
sets = Supplejack::UserSet.featured_sets
|
|
460
460
|
sets.should be_a Array
|
|
461
461
|
sets.size.should eq 1
|
|
462
462
|
end
|
data/supplejack_client.gemspec
CHANGED
|
@@ -22,9 +22,10 @@ Gem::Specification.new do |gem|
|
|
|
22
22
|
gem.require_paths = ['lib']
|
|
23
23
|
gem.version = Supplejack::VERSION
|
|
24
24
|
|
|
25
|
-
gem.add_dependency 'rails', '
|
|
25
|
+
gem.add_dependency 'rails', '>= 3.2.12', '< 5.0'
|
|
26
26
|
gem.add_dependency 'rest-client', '~> 1.6'
|
|
27
27
|
gem.add_dependency 'rails_autolink', '~> 1.0'
|
|
28
28
|
|
|
29
29
|
gem.add_development_dependency 'rspec', '~> 2.8'
|
|
30
|
+
gem.add_development_dependency 'codeclimate-test-reporter'
|
|
30
31
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: supplejack_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Supplejack
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: 3.2.12
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '5.0'
|
|
20
23
|
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
24
|
-
- - "
|
|
27
|
+
- - ">="
|
|
25
28
|
- !ruby/object:Gem::Version
|
|
26
29
|
version: 3.2.12
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '5.0'
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
34
|
name: rest-client
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,6 +72,20 @@ dependencies:
|
|
|
66
72
|
- - "~>"
|
|
67
73
|
- !ruby/object:Gem::Version
|
|
68
74
|
version: '2.8'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: codeclimate-test-reporter
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
69
89
|
description: " Library to abstract the interaction with the Supplejack API "
|
|
70
90
|
email:
|
|
71
91
|
- info@digitalnz.org
|
|
@@ -75,6 +95,9 @@ extra_rdoc_files: []
|
|
|
75
95
|
files:
|
|
76
96
|
- ".gitignore"
|
|
77
97
|
- ".rspec"
|
|
98
|
+
- ".rubocop.yml"
|
|
99
|
+
- ".rubocop_todo.yml"
|
|
100
|
+
- ".travis.yml"
|
|
78
101
|
- Gemfile
|
|
79
102
|
- Guardfile
|
|
80
103
|
- LICENSE.txt
|
|
@@ -84,6 +107,7 @@ files:
|
|
|
84
107
|
- lib/generators/supplejack/install_generator.rb
|
|
85
108
|
- lib/generators/templates/README
|
|
86
109
|
- lib/generators/templates/supplejack_client.rb
|
|
110
|
+
- lib/supplejack/concept.rb
|
|
87
111
|
- lib/supplejack/config.rb
|
|
88
112
|
- lib/supplejack/controllers/helpers.rb
|
|
89
113
|
- lib/supplejack/engine.rb
|
|
@@ -104,6 +128,7 @@ files:
|
|
|
104
128
|
- lib/supplejack/version.rb
|
|
105
129
|
- lib/supplejack_client.rb
|
|
106
130
|
- spec/spec_helper.rb
|
|
131
|
+
- spec/supplejack/concept_spec.rb
|
|
107
132
|
- spec/supplejack/controllers/helpers_spec.rb
|
|
108
133
|
- spec/supplejack/facet_spec.rb
|
|
109
134
|
- spec/supplejack/item_relation_spec.rb
|
|
@@ -137,13 +162,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
137
162
|
version: '0'
|
|
138
163
|
requirements: []
|
|
139
164
|
rubyforge_project:
|
|
140
|
-
rubygems_version: 2.
|
|
165
|
+
rubygems_version: 2.5.1
|
|
141
166
|
signing_key:
|
|
142
167
|
specification_version: 4
|
|
143
168
|
summary: Connects to the API, and allows you to treat models as if they were in a
|
|
144
169
|
local database
|
|
145
170
|
test_files:
|
|
146
171
|
- spec/spec_helper.rb
|
|
172
|
+
- spec/supplejack/concept_spec.rb
|
|
147
173
|
- spec/supplejack/controllers/helpers_spec.rb
|
|
148
174
|
- spec/supplejack/facet_spec.rb
|
|
149
175
|
- spec/supplejack/item_relation_spec.rb
|