supplejack_client 1.0.5 → 1.0.7

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +2 -2
  5. data/Gemfile +4 -2
  6. data/README.md +3 -3
  7. data/lib/generators/locales/en.yml +5 -3
  8. data/lib/generators/supplejack/install_generator.rb +5 -3
  9. data/lib/generators/templates/supplejack_client.rb +5 -3
  10. data/lib/supplejack/concept.rb +5 -3
  11. data/lib/supplejack/config.rb +5 -3
  12. data/lib/supplejack/controllers/helpers.rb +5 -3
  13. data/lib/supplejack/engine.rb +5 -3
  14. data/lib/supplejack/exceptions.rb +8 -3
  15. data/lib/supplejack/facet.rb +5 -3
  16. data/lib/supplejack/item.rb +7 -5
  17. data/lib/supplejack/item_relation.rb +7 -4
  18. data/lib/supplejack/log_subscriber.rb +5 -3
  19. data/lib/supplejack/paginated_collection.rb +5 -3
  20. data/lib/supplejack/record.rb +5 -3
  21. data/lib/supplejack/request.rb +18 -4
  22. data/lib/supplejack/search.rb +5 -3
  23. data/lib/supplejack/story.rb +232 -0
  24. data/lib/supplejack/story_item.rb +149 -0
  25. data/lib/supplejack/story_item_relation.rb +81 -0
  26. data/lib/supplejack/url_formats/item_hash.rb +5 -3
  27. data/lib/supplejack/user.rb +9 -3
  28. data/lib/supplejack/user_set.rb +28 -26
  29. data/lib/supplejack/user_set_relation.rb +5 -3
  30. data/lib/supplejack/user_story_relation.rb +141 -0
  31. data/lib/supplejack/util.rb +5 -3
  32. data/lib/supplejack/version.rb +7 -5
  33. data/lib/supplejack_client.rb +14 -3
  34. data/spec/spec_helper.rb +7 -5
  35. data/spec/supplejack/concept_spec.rb +5 -3
  36. data/spec/supplejack/facet_spec.rb +5 -3
  37. data/spec/supplejack/item_relation_spec.rb +5 -3
  38. data/spec/supplejack/item_spec.rb +7 -5
  39. data/spec/supplejack/log_subscriber_spec.rb +5 -3
  40. data/spec/supplejack/paginated_collection_spec.rb +5 -3
  41. data/spec/supplejack/record_spec.rb +5 -3
  42. data/spec/supplejack/request_spec.rb +5 -3
  43. data/spec/supplejack/search_spec.rb +5 -3
  44. data/spec/supplejack/story_item_relation_spec.rb +149 -0
  45. data/spec/supplejack/story_item_spec.rb +114 -0
  46. data/spec/supplejack/story_spec.rb +401 -0
  47. data/spec/supplejack/user_set_relation_spec.rb +5 -3
  48. data/spec/supplejack/user_set_spec.rb +9 -7
  49. data/spec/supplejack/user_spec.rb +5 -3
  50. data/spec/supplejack/user_story_relation_spec.rb +157 -0
  51. data/stories_integration_test.rb +97 -0
  52. data/supplejack_client.gemspec +9 -3
  53. metadata +32 -10
@@ -1,9 +1,11 @@
1
- # The Supplejack Client code is Crown copyright (C) 2014, New Zealand Government,
1
+ # The Supplejack Common code is
2
+ # Crown copyright (C) 2014, New Zealand Government,
2
3
  # and is licensed under the GNU General Public License, version 3.
3
4
  # See https://github.com/DigitalNZ/supplejack_client for details.
4
5
  #
5
- # Supplejack was created by DigitalNZ at the National Library of NZ
6
- # and the Department of Internal Affairs. http://digitalnz.org/supplejack
6
+ # Supplejack was created by DigitalNZ at the
7
+ # National Library of NZ and the Department of Internal Affairs.
8
+ # http://digitalnz.org/supplejack
7
9
 
8
10
  require 'spec_helper'
9
11
 
@@ -1,9 +1,11 @@
1
- # The Supplejack Client code is Crown copyright (C) 2014, New Zealand Government,
1
+ # The Supplejack Common code is
2
+ # Crown copyright (C) 2014, New Zealand Government,
2
3
  # and is licensed under the GNU General Public License, version 3.
3
4
  # See https://github.com/DigitalNZ/supplejack_client for details.
4
5
  #
5
- # Supplejack was created by DigitalNZ at the National Library of NZ
6
- # and the Department of Internal Affairs. http://digitalnz.org/supplejack
6
+ # Supplejack was created by DigitalNZ at the
7
+ # National Library of NZ and the Department of Internal Affairs.
8
+ # http://digitalnz.org/supplejack
7
9
 
8
10
  require 'spec_helper'
9
11
 
@@ -245,7 +247,7 @@ module Supplejack
245
247
  end
246
248
  end
247
249
  end
248
-
250
+
249
251
  describe '#api_records' do
250
252
  it 'generates a hash of records with position and record_id' do
251
253
  supplejack_set.stub(:records) { [{title: 'Hi', record_id: 1, position: 1} ] }
@@ -293,7 +295,7 @@ module Supplejack
293
295
  it 'returns false when the response is not a 200' do
294
296
  Supplejack::UserSet.stub(:delete).and_raise(RestClient::Forbidden.new)
295
297
  supplejack_set.destroy.should be_false
296
- supplejack_set.errors.should eq 'Forbidden: '
298
+ supplejack_set.errors.should eq 'Forbidden'
297
299
  end
298
300
 
299
301
  it 'returns false when it is a new user set' do
@@ -358,7 +360,7 @@ module Supplejack
358
360
 
359
361
  describe '#owned_by?' do
360
362
  let(:user) { double(:user, api_key: '123456') }
361
-
363
+
362
364
  it 'returns true when the users api_key is the same as the set\'s' do
363
365
  supplejack_set.stub(:api_key) { "123456" }
364
366
  supplejack_set.owned_by?(user).should be_true
@@ -398,7 +400,7 @@ module Supplejack
398
400
  end
399
401
 
400
402
  it 'fetches the set from the api' do
401
- Supplejack::UserSet.should_receive(:get).with('/sets/123abc')
403
+ Supplejack::UserSet.should_receive(:get).with('/sets/123abc', {})
402
404
  Supplejack::UserSet.find('123abc')
403
405
  end
404
406
 
@@ -1,9 +1,11 @@
1
- # The Supplejack Client code is Crown copyright (C) 2014, New Zealand Government,
1
+ # The Supplejack Common code is
2
+ # Crown copyright (C) 2014, New Zealand Government,
2
3
  # and is licensed under the GNU General Public License, version 3.
3
4
  # See https://github.com/DigitalNZ/supplejack_client for details.
4
5
  #
5
- # Supplejack was created by DigitalNZ at the National Library of NZ
6
- # and the Department of Internal Affairs. http://digitalnz.org/supplejack
6
+ # Supplejack was created by DigitalNZ at the
7
+ # National Library of NZ and the Department of Internal Affairs.
8
+ # http://digitalnz.org/supplejack
7
9
 
8
10
  require 'spec_helper'
9
11
 
@@ -0,0 +1,157 @@
1
+ # The Supplejack Common code is
2
+ # Crown copyright (C) 2014, New Zealand Government,
3
+ # and is licensed under the GNU General Public License, version 3.
4
+ # See https://github.com/DigitalNZ/supplejack_client for details.
5
+ #
6
+ # Supplejack was created by DigitalNZ at the
7
+ # National Library of NZ and the Department of Internal Affairs.
8
+ # http://digitalnz.org/supplejack
9
+
10
+ require 'spec_helper'
11
+
12
+ module Supplejack
13
+ describe UserStoryRelation do
14
+ let(:user) { Supplejack::User.new({authentication_token: '123abc'}) }
15
+ let(:relation) { Supplejack::UserStoryRelation.new(user) }
16
+
17
+ before do
18
+ relation.stub(:get) do
19
+ [
20
+ {
21
+ 'id' => '1',
22
+ 'name' => 'dogs',
23
+ 'description' => 'desc',
24
+ 'privacy' => "public",
25
+ 'featured' => false,
26
+ 'approved' => true,
27
+ 'number_of_items' => 1,
28
+ },
29
+ {
30
+ 'id' => '2',
31
+ 'name' => 'cats',
32
+ 'description' => 'desc',
33
+ 'privacy' => "public",
34
+ 'featured' => false,
35
+ 'approved' => true,
36
+ 'number_of_items' => 1,
37
+ },
38
+ ]
39
+ end
40
+ end
41
+
42
+ describe '#initialize' do
43
+ it 'initializes with a UserSet object' do
44
+ expect(Supplejack::UserStoryRelation.new(user).user).to eq(user)
45
+ end
46
+ end
47
+
48
+ describe '#fetch' do
49
+ context 'use_own_api_key? is false' do
50
+ it 'fetches the users stories with the App api_key' do
51
+ expect(relation).to receive(:get).with('/users/123abc/stories', {})
52
+
53
+ relation.fetch
54
+ end
55
+ end
56
+
57
+ context 'use_own_api_key? is true' do
58
+ let(:user) {Supplejack::User.new(api_key: '123abc', use_own_api_key: true)}
59
+
60
+ it 'fetches the users stories with their api_key' do
61
+ expect(relation).to receive(:get).with('/stories', {api_key: '123abc'})
62
+
63
+ relation.fetch
64
+ end
65
+ end
66
+
67
+ it 'returns a array of Story objects' do
68
+ expect(relation.fetch).to be_a Array
69
+
70
+ relation.fetch.each do |story|
71
+ expect(story).to be_a Supplejack::Story
72
+ end
73
+ end
74
+
75
+ it 'memoizes the result' do
76
+ expect(relation).to receive(:fetch_api_stories).once { [] }
77
+
78
+ relation.fetch
79
+ relation.fetch
80
+ end
81
+
82
+ it 'lets you force a refetch' do
83
+ expect(relation).to receive(:fetch_api_stories).twice { [] }
84
+
85
+ relation.fetch
86
+ relation.fetch(force: true)
87
+ end
88
+ end
89
+
90
+ describe '#build' do
91
+ it "initializes a new Story with the user's api_key" do
92
+ story = relation.build
93
+
94
+ expect(story).to be_a Supplejack::Story
95
+ expect(story.api_key).to eq('123abc')
96
+ end
97
+
98
+ it 'initializes the Story with the provided attributes' do
99
+ story = relation.build({name: 'Dogs', description: 'Hi'})
100
+
101
+ expect(story.name).to eq('Dogs')
102
+ expect(story.description).to eq('Hi')
103
+ end
104
+ end
105
+
106
+ describe '#create' do
107
+ it 'initializes the Story and saves it' do
108
+ story = relation.build({name: 'Dogs'})
109
+ allow(relation).to receive(:build).with(name: 'Dogs') { story }
110
+
111
+ expect(story).to receive(:save) { true }
112
+
113
+ expect(relation.create({name: 'Dogs'})).to be_a Supplejack::Story
114
+ end
115
+
116
+ it 'adds the new Story to the relation' do
117
+ expect(relation.count).to eq(2)
118
+ relation.create(name: 'Dogs')
119
+ expect(relation.count).to eq(3)
120
+ end
121
+ end
122
+
123
+ describe '#order' do
124
+ before do
125
+ relation.stub(:get) do
126
+ [
127
+ {'name' => 'dogs'},
128
+ {'name' => 'zavourites'},
129
+ {'name' => 'Favourites'}
130
+ ]
131
+ end
132
+ end
133
+
134
+ it 'orders the stories based on the supplied field' do
135
+ ordered_relations = relation.order(:name)
136
+
137
+ expect(ordered_relations[0].name).to eq('dogs')
138
+ expect(ordered_relations[1].name).to eq('Favourites')
139
+ expect(ordered_relations[2].name).to eq('zavourites')
140
+ end
141
+ end
142
+
143
+ describe '#all' do
144
+ it 'it is an alias to #fetch' do
145
+ expect(relation.all).to eq(relation.fetch)
146
+ end
147
+ end
148
+
149
+ context 'stories array behaviour' do
150
+ it 'executes array methods on the @stories array' do
151
+ relation.stub(:all) { [] }
152
+
153
+ expect(relation.size).to eq(0)
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,97 @@
1
+ def assert(left, right, message)
2
+ ok = left == right
3
+ p message unless ok
4
+ p "#{left} != #{right}" unless ok
5
+ end
6
+
7
+ # Setup
8
+ p 'Setup'
9
+
10
+ Supplejack.api_key = ENV['SJ_CLIENT_TEST_KEY']
11
+ user = Supplejack::User.new(api_key: ENV['SJ_CLIENT_TEST_KEY'])
12
+ user.stories.each(&:destroy)
13
+ user.stories.fetch(force: true)
14
+
15
+ p 'Done Setup'
16
+
17
+ # Create story
18
+ p 'Create Story'
19
+
20
+ user.stories.create(name: 'Test story')
21
+
22
+ assert(user.stories.first.name, 'Test story', 'name of story does not match')
23
+
24
+ p 'Done Create Story'
25
+
26
+ # Update story
27
+ p 'Update Story'
28
+ user.stories.first.update_attributes(name: 'A new name', description: 'fizzle', tags: ['love', 'me', 'some', 'tags'])
29
+
30
+ assert(user.stories.first.name, 'A new name', 'name of story does not match')
31
+ assert(user.stories.first.description, 'fizzle', 'description of story does not match')
32
+ assert(user.stories.first.tags, ['love', 'me', 'some', 'tags'], 'tags of story does not match')
33
+
34
+ p 'Done Update Story'
35
+
36
+ # Create items
37
+ p 'Create Items'
38
+
39
+ assert(user.stories.first.items.create(type: 'embed', sub_type: 'dnz', content: {record_id: 123}, meta: {}), true, 'dnz embed item failed to create')
40
+ assert(user.stories.first.items.create(type: 'text', sub_type: 'heading', content: {value: 'Heading'}, meta: {size: 1}), true, 'heading item failed to create')
41
+
42
+ assert(user.stories.first.items.first.content[:record_id], 123, 'record_id does not match')
43
+ assert(user.stories.first.items.last.content[:value], 'Heading', 'heading value does not match')
44
+ assert(user.stories.first.items.count, 2, 'two items were not created')
45
+
46
+ p 'Done Create Items'
47
+
48
+ # Update item
49
+ p 'Update Item'
50
+
51
+ user.stories.first.items.first.update_attributes(content: {record_id: 456})
52
+
53
+ assert(user.stories.first.items.first.content, {record_id: 456}, 'record_id does not match')
54
+
55
+ p 'Done Update Item'
56
+
57
+ # Move item
58
+ p 'Move Item'
59
+
60
+ id = user.stories.first.items.first.id
61
+ user.stories.first.items.move_item(id, 2)
62
+
63
+ assert(user.stories.first.items.last.id, id, 'block did not get moved')
64
+
65
+ p 'Done Move Item'
66
+
67
+ # Delete item
68
+ p 'Delete Item'
69
+
70
+ user.stories.first.items.first.destroy
71
+
72
+ p 'Done Delete Item'
73
+
74
+ # Force refetch of stories
75
+ p 'Force refetch'
76
+
77
+ start = Time.now
78
+ user.stories.fetch(force: true)
79
+ end_time = Time.now
80
+
81
+ if ((start - end_time) * 1000) > 100
82
+ p 'did not refetch'
83
+ end
84
+ # Have to refetch to check if item is deleted, so I put it here
85
+ assert(user.stories.first.items.count, 1, 'item was not deleted')
86
+
87
+ p 'Done Force refetch'
88
+
89
+ # Delete story
90
+ p 'Delete Story'
91
+
92
+ user.stories.first.destroy
93
+ user.stories.fetch(force: true)
94
+
95
+ assert(user.stories.count, 0, 'story was not deleted')
96
+
97
+ p 'Done Delete Story'
@@ -21,11 +21,17 @@ Gem::Specification.new do |gem|
21
21
  gem.name = 'supplejack_client'
22
22
  gem.require_paths = ['lib']
23
23
  gem.version = Supplejack::VERSION
24
-
25
- gem.add_dependency 'rails', '>= 3.2.12', '< 5.0'
26
- gem.add_dependency 'rest-client', '~> 1.6'
24
+
25
+ if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new("2.2.2")
26
+ gem.add_dependency 'rails', '>= 3.2.12', '< 5.0'
27
+ else
28
+ gem.add_dependency 'rails', '>= 3.2.12'
29
+ end
30
+
31
+ gem.add_dependency 'rest-client', '~> 2.0'
27
32
  gem.add_dependency 'rails_autolink', '~> 1.0'
28
33
 
29
34
  gem.add_development_dependency 'rspec', '~> 2.8'
30
35
  gem.add_development_dependency 'codeclimate-test-reporter'
36
+ gem.add_development_dependency 'pry'
31
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supplejack_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Supplejack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-16 00:00:00.000000000 Z
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.12
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '5.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,23 +24,20 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.2.12
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '5.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rest-client
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '1.6'
33
+ version: '2.0'
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '1.6'
40
+ version: '2.0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rails_autolink
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +80,20 @@ dependencies:
86
80
  - - ">="
87
81
  - !ruby/object:Gem::Version
88
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
89
97
  description: " Library to abstract the interaction with the Supplejack API "
90
98
  email:
91
99
  - info@digitalnz.org
@@ -97,6 +105,7 @@ files:
97
105
  - ".rspec"
98
106
  - ".rubocop.yml"
99
107
  - ".rubocop_todo.yml"
108
+ - ".ruby-version"
100
109
  - ".travis.yml"
101
110
  - Gemfile
102
111
  - Guardfile
@@ -120,10 +129,14 @@ files:
120
129
  - lib/supplejack/record.rb
121
130
  - lib/supplejack/request.rb
122
131
  - lib/supplejack/search.rb
132
+ - lib/supplejack/story.rb
133
+ - lib/supplejack/story_item.rb
134
+ - lib/supplejack/story_item_relation.rb
123
135
  - lib/supplejack/url_formats/item_hash.rb
124
136
  - lib/supplejack/user.rb
125
137
  - lib/supplejack/user_set.rb
126
138
  - lib/supplejack/user_set_relation.rb
139
+ - lib/supplejack/user_story_relation.rb
127
140
  - lib/supplejack/util.rb
128
141
  - lib/supplejack/version.rb
129
142
  - lib/supplejack_client.rb
@@ -138,10 +151,15 @@ files:
138
151
  - spec/supplejack/record_spec.rb
139
152
  - spec/supplejack/request_spec.rb
140
153
  - spec/supplejack/search_spec.rb
154
+ - spec/supplejack/story_item_relation_spec.rb
155
+ - spec/supplejack/story_item_spec.rb
156
+ - spec/supplejack/story_spec.rb
141
157
  - spec/supplejack/url_formats/item_hash_spec.rb
142
158
  - spec/supplejack/user_set_relation_spec.rb
143
159
  - spec/supplejack/user_set_spec.rb
144
160
  - spec/supplejack/user_spec.rb
161
+ - spec/supplejack/user_story_relation_spec.rb
162
+ - stories_integration_test.rb
145
163
  - supplejack_client.gemspec
146
164
  homepage: http://digitalnz.org
147
165
  licenses: []
@@ -179,7 +197,11 @@ test_files:
179
197
  - spec/supplejack/record_spec.rb
180
198
  - spec/supplejack/request_spec.rb
181
199
  - spec/supplejack/search_spec.rb
200
+ - spec/supplejack/story_item_relation_spec.rb
201
+ - spec/supplejack/story_item_spec.rb
202
+ - spec/supplejack/story_spec.rb
182
203
  - spec/supplejack/url_formats/item_hash_spec.rb
183
204
  - spec/supplejack/user_set_relation_spec.rb
184
205
  - spec/supplejack/user_set_spec.rb
185
206
  - spec/supplejack/user_spec.rb
207
+ - spec/supplejack/user_story_relation_spec.rb