tinybucket 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1269b0935055e587255a2efa9485d568d075c581
4
- data.tar.gz: 142e74c98d8bcee9cdd98cb3561b68cdc7002901
3
+ metadata.gz: 24e3536cf6f81ae670df0d854aca916d60ab010d
4
+ data.tar.gz: 2d59c8468bb0a79a5a6ce76d1a7858817fbcc7f7
5
5
  SHA512:
6
- metadata.gz: d6ad29db68508a71f16670550762f6461588f55397f140d3375c801da2e27569c96ac402d272aa0492f1b6fc4bbc10e046a259a3a83e8bbb06eaa93b4fd72f98
7
- data.tar.gz: b77657f858c70b6a869bbfc76f4a89f97e74489d7014106741fec697aa1380f4d913e97b0cd8c6d1529000d89a56b45f559d57fd5955cfd0c0a255164918ab54
6
+ metadata.gz: 1217df53d313c34644437182696fcb2741813c40af241057bbab8c925491b6a3a44a7c1d9eeea534d64306ab0834b80c01de2ab649c465dd8ec85cc577c72a55
7
+ data.tar.gz: 6badf2bcc2aabb16604f3cea9274723c704dddee46af91050534032fdae72f31f12e127f5fde5d8225f5d43dfc1c1187cb856313ba7a66aee0ca0071a826e77e
@@ -2,6 +2,7 @@ module Tinybucket
2
2
  module Model
3
3
  class Base
4
4
  include ::ActiveModel::Serializers::JSON
5
+ include Concerns::AcceptableAttributes
5
6
  attr_accessor :api_config
6
7
 
7
8
  def self.concern_included?(concern_name)
@@ -16,21 +17,19 @@ module Tinybucket
16
17
  end
17
18
 
18
19
  def attributes=(hash)
19
- hash.each { |key, value| send("#{key}=", value) }
20
- end
21
-
22
- def attributes
23
- instance_values.select do |key, _value|
24
- case key
25
- when /\A_.+\z/
26
- when 'api_config', 'repo_owner', 'repo_slug'
27
- false
20
+ hash.each do |key, value|
21
+ if acceptable_attribute?(key)
22
+ send("#{key}=", value)
28
23
  else
29
- true
24
+ # rubocop:disable Metrics/LineLength
25
+ logger.warn("Ignored '#{key}' attribute (value: #{value}). [#{self.class}]")
26
+ # rubocop:enable Metrics/LineLength
30
27
  end
31
28
  end
32
29
  end
33
30
 
31
+ alias_method :attributes, :acceptable_attributes
32
+
34
33
  protected
35
34
 
36
35
  def create_api(api_key, keys, options)
@@ -49,6 +48,10 @@ module Tinybucket
49
48
  def create_instance(klass_name, options)
50
49
  ApiFactory.create_instance(klass_name, api_config, options)
51
50
  end
51
+
52
+ def logger
53
+ Tinybucket.logger
54
+ end
52
55
  end
53
56
  end
54
57
  end
@@ -3,7 +3,7 @@ module Tinybucket
3
3
  class BranchRestriction < Base
4
4
  include Tinybucket::Model::Concerns::RepositoryKeys
5
5
 
6
- attr_accessor :groups, :id, :kind, :links, :pattern, :users, :uuid
6
+ acceptable_attributes :groups, :id, :kind, :links, :pattern, :users, :uuid
7
7
 
8
8
  def update(_params)
9
9
  fail NotImplementedError
@@ -4,7 +4,7 @@ module Tinybucket
4
4
  include Tinybucket::Model::Concerns::RepositoryKeys
5
5
  include Tinybucket::Model::Concerns::Reloadable
6
6
 
7
- attr_accessor \
7
+ acceptable_attributes \
8
8
  :links, :id, :parent, :filename, :content, :user, :inline, \
9
9
  :created_on, :updated_on, :uuid
10
10
 
@@ -4,7 +4,7 @@ module Tinybucket
4
4
  include Tinybucket::Model::Concerns::RepositoryKeys
5
5
  include Tinybucket::Model::Concerns::Reloadable
6
6
 
7
- attr_accessor \
7
+ acceptable_attributes \
8
8
  :hash, :links, :repository, :author, :parents, :date,
9
9
  :message, :participants, :uuid
10
10
 
@@ -4,6 +4,7 @@ module Tinybucket
4
4
  extend ActiveSupport::Autoload
5
5
 
6
6
  [
7
+ :AcceptableAttributes,
7
8
  :RepositoryKeys,
8
9
  :Reloadable
9
10
  ].each do |mod_name|
@@ -0,0 +1,32 @@
1
+ module Tinybucket
2
+ module Model
3
+ module Concerns
4
+ module AcceptableAttributes
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ def self.acceptable_attributes(*attrs)
9
+ @_acceptable_attributes = attrs.map(&:intern)
10
+
11
+ attr_accessor(*attrs)
12
+ end
13
+
14
+ def self.acceptable_attribute?(key)
15
+ return false if @_acceptable_attributes.nil?
16
+ @_acceptable_attributes.include?(key.intern)
17
+ end
18
+
19
+ protected
20
+
21
+ def acceptable_attribute?(key)
22
+ self.class.acceptable_attribute?(key)
23
+ end
24
+
25
+ def acceptable_attributes
26
+ self.class.instance_variable_get(:@_acceptable_attributes) || []
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,7 +1,7 @@
1
1
  module Tinybucket
2
2
  module Model
3
3
  class ErrorResponse < Base
4
- attr_accessor :message, :fields, :detail, :id, :uuid
4
+ acceptable_attributes :message, :fields, :detail, :id, :uuid
5
5
  end
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@ module Tinybucket
3
3
  class Profile < Base
4
4
  include Tinybucket::Model::Concerns::Reloadable
5
5
 
6
- attr_accessor \
6
+ acceptable_attributes \
7
7
  :username, :kind, :website, :display_name,
8
8
  :links, :created_on, :location, :type, :uuid
9
9
 
@@ -4,7 +4,7 @@ module Tinybucket
4
4
  include Tinybucket::Model::Concerns::RepositoryKeys
5
5
  include Tinybucket::Model::Concerns::Reloadable
6
6
 
7
- attr_accessor \
7
+ acceptable_attributes \
8
8
  :state, :description, :links, :title, :close_source_branch,
9
9
  :destination, :reason, :id, :source, :created_on, :author, :updated_on,
10
10
  :merge_commit, :closed_by, :reviewers, :participants, :uuid
@@ -4,9 +4,10 @@ module Tinybucket
4
4
  include Tinybucket::Model::Concerns::RepositoryKeys
5
5
  include Tinybucket::Model::Concerns::Reloadable
6
6
 
7
- attr_accessor :scm, :has_wiki, :description, :links, :updated_on,
8
- :fork_policy, :created_on, :owner, :size, :parent, :uuid,
9
- :has_issues, :is_private, :full_name, :name, :language
7
+ acceptable_attributes \
8
+ :scm, :has_wiki, :description, :links, :updated_on,
9
+ :fork_policy, :created_on, :owner, :size, :parent, :uuid,
10
+ :has_issues, :is_private, :full_name, :name, :language
10
11
 
11
12
  def create(_params)
12
13
  fail NotImplementedError
@@ -3,7 +3,7 @@ module Tinybucket
3
3
  class Team < Base
4
4
  include Tinybucket::Model::Concerns::Reloadable
5
5
 
6
- attr_accessor \
6
+ acceptable_attributes \
7
7
  :username, :kind, :website, :display_name, :uuid,
8
8
  :links, :created_on, :location, :type
9
9
 
@@ -1,3 +1,3 @@
1
1
  module Tinybucket
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -0,0 +1,17 @@
1
+ {
2
+ "groups": [],
3
+ "id": 52,
4
+ "kind": "delete",
5
+ "links": [
6
+ {
7
+ "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions/52",
8
+ "rel": "self"
9
+ },
10
+ {
11
+ "href": "https://api.bitbucket.org/2.0/repositories/manthony/restrictiontest/branch-restrictions",
12
+ "rel": "parent"
13
+ }
14
+ ],
15
+ "pattern": "foobar/*",
16
+ "users": []
17
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "links": {
3
+ "self": {
4
+ "href": "https://bitbucket.org/api/2.0/repositories/tutorials/tutorials.bitbucket.org/pullrequests/2821/comments/839163"
5
+ },
6
+ "html": {
7
+ "href": "https://bitbucket.org/tutorials/tutorials.bitbucket.org/pull-request/2821/_/diff#comment-839163"
8
+ }
9
+ },
10
+ "content": {
11
+ "raw": "this is my first comment",
12
+ "markup": "markdown",
13
+ "html": "<p>this is my first comment</p>"
14
+ },
15
+ "created_on": "2013-11-19T21:19:24.138375+00:00",
16
+ "user": {
17
+ "username": "tutorials",
18
+ "display_name": "first name last",
19
+ "links": {
20
+ "self": {
21
+ "href": "https://bitbucket.org/api/2.0/users/tutorials"
22
+ },
23
+ "avatar": {
24
+ "href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Jul/17/tutorials-avatar-1826704565-4_avatar.png"
25
+ }
26
+ }
27
+ },
28
+ "updated_on": "2013-11-19T21:19:24.141013+00:00",
29
+ "id": 839163
30
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "username": "teamsinspace",
3
+ "website": null,
4
+ "display_name": "Teams In Space",
5
+ "uuid": "{61fc5cf6-d054-47d2-b4a9-061ccf858379}",
6
+ "links": {
7
+ "self": {
8
+ "href": "https://bitbucket.org/api/2.0/teams/teamsinspace"
9
+ },
10
+ "repositories": {
11
+ "href": "https://bitbucket.org/api/2.0/repositories/teamsinspace"
12
+ },
13
+ "html": {
14
+ "href": "https://bitbucket.org/teamsinspace"
15
+ },
16
+ "followers": {
17
+ "href": "https://bitbucket.org/api/2.0/teams/teamsinspace/followers"
18
+ },
19
+ "avatar": {
20
+ "href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2014/Sep/24/teamsinspace-avatar-3731530358-7_avatar.png"
21
+ },
22
+ "members": {
23
+ "href": "https://bitbucket.org/api/2.0/teams/teamsinspace/members"
24
+ },
25
+ "following": {
26
+ "href": "https://bitbucket.org/api/2.0/teams/teamsinspace/following"
27
+ }
28
+ },
29
+ "created_on": "2014-04-08T00:00:14.070969+00:00",
30
+ "location": null,
31
+ "type": "team"
32
+ }
@@ -3,12 +3,14 @@ require 'spec_helper'
3
3
  RSpec.describe Tinybucket::Model::BranchRestriction do
4
4
  include ApiResponseMacros
5
5
 
6
+ let(:model_json) { load_json_fixture('branch_restriction') }
7
+
8
+ let(:request_method) { :get }
9
+ let(:request_path) { nil }
10
+
6
11
  let(:owner) { 'test_owner' }
7
12
  let(:slug) { 'test_repo' }
8
13
 
9
- # TODO: fix model_json
10
- let(:model_json) { nil }
11
-
12
14
  let(:model) do
13
15
  m = Tinybucket::Model::BranchRestriction.new(model_json)
14
16
  m.repo_owner = owner
@@ -19,6 +21,10 @@ RSpec.describe Tinybucket::Model::BranchRestriction do
19
21
 
20
22
  before { stub_apiresponse(:get, request_path, stub_options) if request_path }
21
23
 
24
+ it_behaves_like 'model has acceptable_attributes',
25
+ Tinybucket::Model::BranchRestriction,
26
+ load_json_fixture('branch_restriction')
27
+
22
28
  describe '#update' do
23
29
  pending 'TODO implement method'
24
30
  end
@@ -4,6 +4,8 @@ RSpec.describe Tinybucket::Model::Comment do
4
4
  include ApiResponseMacros
5
5
  include ModelMacros
6
6
 
7
+ let(:model_json) { load_json_fixture('comment') }
8
+
7
9
  let(:owner) { 'test_owner' }
8
10
  let(:slug) { 'test_repo' }
9
11
 
@@ -15,6 +17,10 @@ RSpec.describe Tinybucket::Model::Comment do
15
17
  m
16
18
  end
17
19
 
20
+ it_behaves_like 'model has acceptable_attributes',
21
+ Tinybucket::Model::Comment,
22
+ load_json_fixture('comment')
23
+
18
24
  describe 'model can reloadable' do
19
25
  let(:comment) do
20
26
  m = Tinybucket::Model::Comment.new({})
@@ -4,12 +4,15 @@ RSpec.describe Tinybucket::Model::Commit do
4
4
  include ApiResponseMacros
5
5
  include ModelMacros
6
6
 
7
+ let(:model_json) { load_json_fixture('commit') }
8
+
9
+ let(:request_path) { nil }
10
+
7
11
  let(:owner) { 'test_owner' }
8
12
  let(:slug) { 'test_repo' }
9
13
 
10
14
  let(:model) do
11
- json = JSON.load(File.read('spec/fixtures/commit.json'))
12
- m = Tinybucket::Model::Commit.new(json)
15
+ m = Tinybucket::Model::Commit.new(model_json)
13
16
  m.repo_owner = owner
14
17
  m.repo_slug = slug
15
18
  m.hash = '1'
@@ -17,10 +20,12 @@ RSpec.describe Tinybucket::Model::Commit do
17
20
  m
18
21
  end
19
22
 
20
- let(:request_path) { nil }
21
-
22
23
  before { stub_apiresponse(:get, request_path) if request_path }
23
24
 
25
+ it_behaves_like 'model has acceptable_attributes',
26
+ Tinybucket::Model::Commit,
27
+ load_json_fixture('commit')
28
+
24
29
  describe 'model can reloadable' do
25
30
  let(:commit) do
26
31
  m = Tinybucket::Model::Commit.new({})
@@ -4,19 +4,24 @@ RSpec.describe Tinybucket::Model::Profile do
4
4
  include ApiResponseMacros
5
5
  include ModelMacros
6
6
 
7
+ let(:model_json) { load_json_fixture('profile') }
8
+
9
+ let(:request_path) { nil }
10
+
7
11
  let(:username) { 'test_owner' }
8
12
 
9
- let(:model_json) { JSON.load(File.read('spec/fixtures/profile.json')) }
10
13
  let(:model) do
11
14
  m = Tinybucket::Model::Profile.new(model_json)
12
15
  m.username = username
13
16
  m
14
17
  end
15
18
 
16
- let(:request_path) { nil }
17
-
18
19
  before { stub_apiresponse(:get, request_path) if request_path }
19
20
 
21
+ it_behaves_like 'model has acceptable_attributes',
22
+ Tinybucket::Model::Profile,
23
+ load_json_fixture('profile')
24
+
20
25
  describe 'model can reloadable' do
21
26
  let(:profile) do
22
27
  m = Tinybucket::Model::Profile.new({})
@@ -4,7 +4,7 @@ RSpec.describe Tinybucket::Model::PullRequest do
4
4
  include ApiResponseMacros
5
5
  include ModelMacros
6
6
 
7
- let(:model_json) { JSON.load(File.read('spec/fixtures/pull_request.json')) }
7
+ let(:model_json) { load_json_fixture('pull_request') }
8
8
 
9
9
  let(:request_method) { :get }
10
10
  let(:request_path) { nil }
@@ -30,6 +30,10 @@ RSpec.describe Tinybucket::Model::PullRequest do
30
30
  end
31
31
  end
32
32
 
33
+ it_behaves_like 'model has acceptable_attributes',
34
+ Tinybucket::Model::PullRequest,
35
+ load_json_fixture('pull_request')
36
+
33
37
  describe 'model can reloadable' do
34
38
  let(:pr) do
35
39
  m = Tinybucket::Model::PullRequest.new({})
@@ -4,10 +4,14 @@ RSpec.describe Tinybucket::Model::Repository do
4
4
  include ApiResponseMacros
5
5
  include ModelMacros
6
6
 
7
+ let(:model_json) { load_json_fixture('repository') }
8
+
9
+ let(:request_path) { nil }
10
+ let(:stub_options) { {} }
11
+
7
12
  let(:owner) { 'test_owner' }
8
13
  let(:slug) { 'test_repo' }
9
14
 
10
- let(:model_json) { JSON.load(File.read('spec/fixtures/repository.json')) }
11
15
  let(:model) do
12
16
  m = Tinybucket::Model::Repository.new(model_json)
13
17
  m.repo_owner = owner
@@ -15,11 +19,13 @@ RSpec.describe Tinybucket::Model::Repository do
15
19
 
16
20
  m
17
21
  end
18
- let(:request_path) { nil }
19
- let(:stub_options) { {} }
20
22
 
21
23
  before { stub_apiresponse(:get, request_path, stub_options) if request_path }
22
24
 
25
+ it_behaves_like 'model has acceptable_attributes',
26
+ Tinybucket::Model::Repository,
27
+ load_json_fixture('repository')
28
+
23
29
  describe 'model can reloadable' do
24
30
  let(:repo) do
25
31
  m = Tinybucket::Model::Repository.new({})
@@ -4,19 +4,24 @@ RSpec.describe Tinybucket::Model::Team do
4
4
  include ApiResponseMacros
5
5
  include ModelMacros
6
6
 
7
+ let(:model_json) { load_json_fixture('team') }
8
+
9
+ let(:request_path) { nil }
10
+
7
11
  let(:teamname) { 'test_team' }
8
12
 
9
- let(:model_json) { JSON.load(File.read('spec/fixtures/profile.json')) }
10
13
  let(:model) do
11
14
  m = Tinybucket::Model::Team.new(model_json)
12
15
  m.username = teamname
13
16
  m
14
17
  end
15
18
 
16
- let(:request_path) { nil }
17
-
18
19
  before { stub_apiresponse(:get, request_path) if request_path }
19
20
 
21
+ it_behaves_like 'model has acceptable_attributes',
22
+ Tinybucket::Model::Team,
23
+ load_json_fixture('team')
24
+
20
25
  describe 'model can reloadable' do
21
26
  let(:team) do
22
27
  m = Tinybucket::Model::Team.new({})
data/spec/spec_helper.rb CHANGED
@@ -38,5 +38,7 @@ logger.level = Logger::DEBUG
38
38
  Tinybucket.logger = logger
39
39
 
40
40
  RSpec.configure do |config|
41
+ config.extend FixtureMacros
42
+ config.include FixtureMacros
41
43
  config.order = 'random'
42
44
  end
@@ -0,0 +1,5 @@
1
+ module FixtureMacros
2
+ def load_json_fixture(suffix)
3
+ JSON.load(File.read('spec/fixtures/' + suffix + '.json'))
4
+ end
5
+ end
@@ -1,4 +1,30 @@
1
1
  module ModelMacros
2
+ RSpec.shared_examples 'model has acceptable_attributes' do |cls, model_json|
3
+ describe '#attribute=' do
4
+ subject { cls.new(json) }
5
+
6
+ context 'json contains only expected attrs' do
7
+ let(:json) { model_json }
8
+ it { expect { subject }.not_to raise_error }
9
+ it 'receive each attributes' do
10
+ json.each_pair do |key, value|
11
+ expect(subject.send(key.intern)).to eq(value)
12
+ end
13
+ end
14
+ end
15
+
16
+ context 'json contains un-acceptable attrs' do
17
+ let(:json) { model_json.merge('_un_acceptable_key' => 'some_value') }
18
+ it { expect { subject }.not_to raise_error }
19
+ it 'receive each acceptable attributes' do
20
+ model_json.each_pair do |key, value|
21
+ expect(subject.send(key.intern)).to eq(value)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
2
28
  RSpec.shared_examples 'the model is reloadable' do
3
29
  describe '#load' do
4
30
  before do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinybucket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - hirakiuc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2015-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -266,6 +266,7 @@ files:
266
266
  - lib/tinybucket/model/comment.rb
267
267
  - lib/tinybucket/model/commit.rb
268
268
  - lib/tinybucket/model/concerns.rb
269
+ - lib/tinybucket/model/concerns/acceptable_attributes.rb
269
270
  - lib/tinybucket/model/concerns/reloadable.rb
270
271
  - lib/tinybucket/model/concerns/repository_keys.rb
271
272
  - lib/tinybucket/model/error_response.rb
@@ -294,6 +295,8 @@ files:
294
295
  - lib/tinybucket/response.rb
295
296
  - lib/tinybucket/response/error_handler.rb
296
297
  - lib/tinybucket/version.rb
298
+ - spec/fixtures/branch_restriction.json
299
+ - spec/fixtures/comment.json
297
300
  - spec/fixtures/commit.json
298
301
  - spec/fixtures/profile.json
299
302
  - spec/fixtures/pull_request.json
@@ -323,6 +326,7 @@ files:
323
326
  - spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_open.json
324
327
  - spec/fixtures/repositories/test_owner/test_repo/watchers/get.json
325
328
  - spec/fixtures/repository.json
329
+ - spec/fixtures/team.json
326
330
  - spec/fixtures/teams/test_team/followers/get.json
327
331
  - spec/fixtures/teams/test_team/following/get.json
328
332
  - spec/fixtures/teams/test_team/get.json
@@ -354,6 +358,7 @@ files:
354
358
  - spec/lib/tinybucket_spec.rb
355
359
  - spec/spec_helper.rb
356
360
  - spec/support/api_response_macros.rb
361
+ - spec/support/fixture_macros.rb
357
362
  - spec/support/model_macros.rb
358
363
  - tinybucket.gemspec
359
364
  homepage: http://hirakiuc.github.io/tinybucket/
@@ -381,6 +386,8 @@ signing_key:
381
386
  specification_version: 4
382
387
  summary: ruby wrapper for the Bitbucket REST API (v2) with oauth
383
388
  test_files:
389
+ - spec/fixtures/branch_restriction.json
390
+ - spec/fixtures/comment.json
384
391
  - spec/fixtures/commit.json
385
392
  - spec/fixtures/profile.json
386
393
  - spec/fixtures/pull_request.json
@@ -410,6 +417,7 @@ test_files:
410
417
  - spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_open.json
411
418
  - spec/fixtures/repositories/test_owner/test_repo/watchers/get.json
412
419
  - spec/fixtures/repository.json
420
+ - spec/fixtures/team.json
413
421
  - spec/fixtures/teams/test_team/followers/get.json
414
422
  - spec/fixtures/teams/test_team/following/get.json
415
423
  - spec/fixtures/teams/test_team/get.json
@@ -441,5 +449,6 @@ test_files:
441
449
  - spec/lib/tinybucket_spec.rb
442
450
  - spec/spec_helper.rb
443
451
  - spec/support/api_response_macros.rb
452
+ - spec/support/fixture_macros.rb
444
453
  - spec/support/model_macros.rb
445
454
  has_rdoc: