tinybucket 1.3.0 → 1.4.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 +4 -4
- data/.rubocop.yml +10 -1
- data/Gemfile +8 -7
- data/README.md +28 -5
- data/Rakefile +1 -0
- data/lib/faraday_middleware/follow_oauth_redirects.rb +5 -2
- data/lib/tinybucket.rb +2 -0
- data/lib/tinybucket/api.rb +3 -0
- data/lib/tinybucket/api/base_api.rb +2 -0
- data/lib/tinybucket/api/branch_restrictions_api.rb +6 -5
- data/lib/tinybucket/api/branches_api.rb +48 -0
- data/lib/tinybucket/api/build_status_api.rb +15 -1
- data/lib/tinybucket/api/comments_api.rb +7 -6
- data/lib/tinybucket/api/commits_api.rb +25 -4
- data/lib/tinybucket/api/diff_api.rb +4 -3
- data/lib/tinybucket/api/helper.rb +3 -0
- data/lib/tinybucket/api/helper/api_helper.rb +2 -0
- data/lib/tinybucket/api/helper/branch_restrictions_helper.rb +2 -0
- data/lib/tinybucket/api/helper/branches_helper.rb +29 -0
- data/lib/tinybucket/api/helper/build_status_helper.rb +11 -0
- data/lib/tinybucket/api/helper/comments_helper.rb +2 -0
- data/lib/tinybucket/api/helper/commits_helper.rb +8 -0
- data/lib/tinybucket/api/helper/diff_helper.rb +2 -0
- data/lib/tinybucket/api/helper/pull_requests_helper.rb +2 -0
- data/lib/tinybucket/api/helper/repo_helper.rb +2 -0
- data/lib/tinybucket/api/helper/repos_helper.rb +2 -0
- data/lib/tinybucket/api/helper/team_helper.rb +2 -0
- data/lib/tinybucket/api/helper/user_helper.rb +2 -0
- data/lib/tinybucket/api/pull_requests_api.rb +4 -3
- data/lib/tinybucket/api/repo_api.rb +4 -3
- data/lib/tinybucket/api/repos_api.rb +3 -1
- data/lib/tinybucket/api/team_api.rb +4 -2
- data/lib/tinybucket/api/user_api.rb +3 -1
- data/lib/tinybucket/api_factory.rb +2 -0
- data/lib/tinybucket/client.rb +3 -2
- data/lib/tinybucket/config.rb +5 -1
- data/lib/tinybucket/connection.rb +21 -8
- data/lib/tinybucket/constants.rb +2 -0
- data/lib/tinybucket/enumerator.rb +2 -0
- data/lib/tinybucket/error.rb +2 -0
- data/lib/tinybucket/error/base_error.rb +2 -0
- data/lib/tinybucket/error/conflict.rb +2 -0
- data/lib/tinybucket/error/not_found.rb +2 -0
- data/lib/tinybucket/error/service_error.rb +2 -0
- data/lib/tinybucket/iterator.rb +4 -2
- data/lib/tinybucket/model.rb +3 -0
- data/lib/tinybucket/model/base.rb +2 -2
- data/lib/tinybucket/model/branch.rb +48 -0
- data/lib/tinybucket/model/branch_restriction.rb +4 -2
- data/lib/tinybucket/model/build_status.rb +3 -1
- data/lib/tinybucket/model/comment.rb +4 -2
- data/lib/tinybucket/model/commit.rb +6 -2
- data/lib/tinybucket/model/concerns.rb +2 -0
- data/lib/tinybucket/model/concerns/acceptable_attributes.rb +2 -0
- data/lib/tinybucket/model/concerns/api_callable.rb +2 -0
- data/lib/tinybucket/model/concerns/enumerable.rb +2 -0
- data/lib/tinybucket/model/concerns/reloadable.rb +2 -0
- data/lib/tinybucket/model/concerns/repository_keys.rb +2 -0
- data/lib/tinybucket/model/error_response.rb +4 -2
- data/lib/tinybucket/model/page.rb +4 -2
- data/lib/tinybucket/model/profile.rb +4 -2
- data/lib/tinybucket/model/pull_request.rb +4 -2
- data/lib/tinybucket/model/repository.rb +31 -5
- data/lib/tinybucket/model/team.rb +4 -2
- data/lib/tinybucket/null_logger.rb +2 -0
- data/lib/tinybucket/parser.rb +5 -0
- data/lib/tinybucket/parser/base_parser.rb +3 -2
- data/lib/tinybucket/parser/branch_parser.rb +13 -0
- data/lib/tinybucket/parser/branch_restriction_parser.rb +2 -0
- data/lib/tinybucket/parser/branch_restrictions_parser.rb +2 -0
- data/lib/tinybucket/parser/branches_parser.rb +11 -0
- data/lib/tinybucket/parser/build_status_parser.rb +2 -0
- data/lib/tinybucket/parser/builds_parser.rb +11 -0
- data/lib/tinybucket/parser/comment_parser.rb +2 -0
- data/lib/tinybucket/parser/comments_parser.rb +2 -0
- data/lib/tinybucket/parser/commit_parser.rb +2 -0
- data/lib/tinybucket/parser/commits_parser.rb +2 -0
- data/lib/tinybucket/parser/profile_parser.rb +2 -0
- data/lib/tinybucket/parser/profiles_parser.rb +2 -0
- data/lib/tinybucket/parser/pull_request_parser.rb +2 -0
- data/lib/tinybucket/parser/pull_requests_parser.rb +2 -0
- data/lib/tinybucket/parser/repo_parser.rb +2 -0
- data/lib/tinybucket/parser/repos_parser.rb +2 -0
- data/lib/tinybucket/parser/team_parser.rb +2 -0
- data/lib/tinybucket/parser/teams_parser.rb +2 -0
- data/lib/tinybucket/request.rb +2 -0
- data/lib/tinybucket/resource.rb +3 -0
- data/lib/tinybucket/resource/base.rb +6 -0
- data/lib/tinybucket/resource/branch_restrictions.rb +2 -0
- data/lib/tinybucket/resource/branches.rb +35 -0
- data/lib/tinybucket/resource/commit/base.rb +2 -0
- data/lib/tinybucket/resource/commit/build_statuses.rb +6 -3
- data/lib/tinybucket/resource/commit/comments.rb +2 -0
- data/lib/tinybucket/resource/commits.rb +13 -0
- data/lib/tinybucket/resource/forks.rb +2 -0
- data/lib/tinybucket/resource/pull_request/base.rb +2 -0
- data/lib/tinybucket/resource/pull_request/comments.rb +2 -0
- data/lib/tinybucket/resource/pull_request/commits.rb +2 -0
- data/lib/tinybucket/resource/pull_requests.rb +2 -0
- data/lib/tinybucket/resource/repos.rb +2 -0
- data/lib/tinybucket/resource/team/base.rb +2 -0
- data/lib/tinybucket/resource/team/followers.rb +2 -0
- data/lib/tinybucket/resource/team/following.rb +2 -0
- data/lib/tinybucket/resource/team/members.rb +2 -0
- data/lib/tinybucket/resource/team/repos.rb +2 -0
- data/lib/tinybucket/resource/user/base.rb +2 -0
- data/lib/tinybucket/resource/user/followers.rb +2 -0
- data/lib/tinybucket/resource/user/following.rb +2 -0
- data/lib/tinybucket/resource/user/repos.rb +2 -0
- data/lib/tinybucket/resource/watchers.rb +2 -0
- data/lib/tinybucket/response.rb +2 -0
- data/lib/tinybucket/response/handler.rb +2 -0
- data/lib/tinybucket/version.rb +3 -1
- data/tinybucket.gemspec +1 -1
- metadata +11 -193
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -33
- data/.rspec +0 -1
- data/.travis.yml +0 -13
- data/Guardfile +0 -13
- data/spec/fixtures/branch_restriction.json +0 -17
- data/spec/fixtures/build_status.json +0 -16
- data/spec/fixtures/comment.json +0 -30
- data/spec/fixtures/commit.json +0 -83
- data/spec/fixtures/profile.json +0 -29
- data/spec/fixtures/pull_request.json +0 -106
- data/spec/fixtures/repositories/get.json +0 -78
- data/spec/fixtures/repositories/test_owner/get.json +0 -78
- data/spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/1/get.json +0 -17
- data/spec/fixtures/repositories/test_owner/test_repo/branch-restrictions/get.json +0 -101
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/approve/post.json +0 -16
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/1/get.json +0 -38
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/comments/get.json +0 -40
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/get.json +0 -83
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/post.json +0 -16
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/get.json +0 -16
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/put.json +0 -16
- data/spec/fixtures/repositories/test_owner/test_repo/commits/get.json +0 -73
- data/spec/fixtures/repositories/test_owner/test_repo/diff/1/get.json +0 -21
- data/spec/fixtures/repositories/test_owner/test_repo/forks/get.json +0 -78
- data/spec/fixtures/repositories/test_owner/test_repo/get.json +0 -71
- data/spec/fixtures/repositories/test_owner/test_repo/patch/1/get.json +0 -29
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/approve/delete.json +0 -3
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/approve/post.json +0 -3
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/1/get.json +0 -30
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/get.json +0 -44
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/commits/get.json +0 -66
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/decline/post.json +0 -116
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/diff/get.txt +0 -13
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/get.json +0 -164
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/merge/post.json +0 -123
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get.json +0 -112
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_declined.json +0 -112
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_merged.json +0 -112
- data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get_state_open.json +0 -112
- data/spec/fixtures/repositories/test_owner/test_repo/watchers/get.json +0 -32
- data/spec/fixtures/repository.json +0 -72
- data/spec/fixtures/team.json +0 -32
- data/spec/fixtures/teams/test_team/followers/get.json +0 -36
- data/spec/fixtures/teams/test_team/following/get.json +0 -39
- data/spec/fixtures/teams/test_team/get.json +0 -32
- data/spec/fixtures/teams/test_team/members/get.json +0 -36
- data/spec/fixtures/teams/test_team/repositories/get.json +0 -125
- data/spec/fixtures/users/test_owner/followers/get.json +0 -65
- data/spec/fixtures/users/test_owner/following/get.json +0 -100
- data/spec/fixtures/users/test_owner/get.json +0 -29
- data/spec/lib/tinybucket/api/branch_restrictions_api_spec.rb +0 -77
- data/spec/lib/tinybucket/api/build_status_api_spec.rb +0 -65
- data/spec/lib/tinybucket/api/comments_api_spec.rb +0 -132
- data/spec/lib/tinybucket/api/commits_api_spec.rb +0 -152
- data/spec/lib/tinybucket/api/diff_api_spec.rb +0 -5
- data/spec/lib/tinybucket/api/pull_requests_api_spec.rb +0 -259
- data/spec/lib/tinybucket/api/repo_api_spec.rb +0 -99
- data/spec/lib/tinybucket/api/repos_api_spec.rb +0 -27
- data/spec/lib/tinybucket/api/team_api_spec.rb +0 -82
- data/spec/lib/tinybucket/api/user_api_spec.rb +0 -73
- data/spec/lib/tinybucket/api_factory_spec.rb +0 -18
- data/spec/lib/tinybucket/client_spec.rb +0 -100
- data/spec/lib/tinybucket/connection_spec.rb +0 -30
- data/spec/lib/tinybucket/error/service_error_spec.rb +0 -23
- data/spec/lib/tinybucket/model/branch_restriction_spec.rb +0 -35
- data/spec/lib/tinybucket/model/build_status_spec.rb +0 -66
- data/spec/lib/tinybucket/model/comment_spec.rb +0 -37
- data/spec/lib/tinybucket/model/commit_spec.rb +0 -108
- data/spec/lib/tinybucket/model/page_spec.rb +0 -28
- data/spec/lib/tinybucket/model/profile_spec.rb +0 -52
- data/spec/lib/tinybucket/model/pull_request_spec.rb +0 -141
- data/spec/lib/tinybucket/model/repository_spec.rb +0 -131
- data/spec/lib/tinybucket/model/team_spec.rb +0 -70
- data/spec/lib/tinybucket/null_logger_spec.rb +0 -53
- data/spec/lib/tinybucket/resource/branch_restrictions_spec.rb +0 -60
- data/spec/lib/tinybucket/resource/commit/build_statuses_spec.rb +0 -50
- data/spec/lib/tinybucket/resource/commit/comments_spec.rb +0 -49
- data/spec/lib/tinybucket/resource/commits_spec.rb +0 -43
- data/spec/lib/tinybucket/resource/forks_spec.rb +0 -36
- data/spec/lib/tinybucket/resource/pull_request/comments_spec.rb +0 -41
- data/spec/lib/tinybucket/resource/pull_request/commits_spec.rb +0 -41
- data/spec/lib/tinybucket/resource/pull_requests_spec.rb +0 -59
- data/spec/lib/tinybucket/resource/repos_spec.rb +0 -76
- data/spec/lib/tinybucket/resource/team/followers_spec.rb +0 -27
- data/spec/lib/tinybucket/resource/team/following_spec.rb +0 -27
- data/spec/lib/tinybucket/resource/team/members_spec.rb +0 -27
- data/spec/lib/tinybucket/resource/team/repos_spec.rb +0 -27
- data/spec/lib/tinybucket/resource/user/followers_spec.rb +0 -27
- data/spec/lib/tinybucket/resource/user/following_spec.rb +0 -27
- data/spec/lib/tinybucket/resource/user/repos_spec.rb +0 -27
- data/spec/lib/tinybucket/resource/watchers_spec.rb +0 -38
- data/spec/lib/tinybucket_spec.rb +0 -42
- data/spec/spec_helper.rb +0 -45
- data/spec/support/api_response_macros.rb +0 -74
- data/spec/support/fixture_macros.rb +0 -5
- data/spec/support/model_macros.rb +0 -103
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Tinybucket::Resource::Watchers do
|
4
|
-
include ApiResponseMacros
|
5
|
-
|
6
|
-
let(:owner) { 'test_owner' }
|
7
|
-
let(:slug) { 'test_repo' }
|
8
|
-
let(:repo) do
|
9
|
-
Tinybucket::Model::Repository.new({}).tap do |m|
|
10
|
-
m.repo_owner = owner
|
11
|
-
m.repo_slug = slug
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
let(:options) { {} }
|
16
|
-
let(:resource) { Tinybucket::Resource::Watchers.new(repo, options) }
|
17
|
-
|
18
|
-
describe 'Enumerable Methods' do
|
19
|
-
let(:params) { {} }
|
20
|
-
let(:request_path) do
|
21
|
-
"/repositories/#{owner}/#{slug}/watchers"
|
22
|
-
end
|
23
|
-
before { stub_enum_response(:get, request_path) }
|
24
|
-
|
25
|
-
describe '#take(1)' do
|
26
|
-
subject { resource.take(1) }
|
27
|
-
it { expect(subject).to be_an_instance_of(Array) }
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#each' do
|
31
|
-
it 'iterate models' do
|
32
|
-
resource.each do |m|
|
33
|
-
expect(m).to be_an_instance_of(Tinybucket::Model::Profile)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/spec/lib/tinybucket_spec.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Tinybucket do
|
4
|
-
|
5
|
-
describe 'new' do
|
6
|
-
subject { Tinybucket.new }
|
7
|
-
it { expect(subject).to be_instance_of(Tinybucket::Client) }
|
8
|
-
end
|
9
|
-
|
10
|
-
describe 'config' do
|
11
|
-
subject { Tinybucket.config }
|
12
|
-
it { expect(subject).to be_an_instance_of(Tinybucket::Config) }
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'configure' do
|
16
|
-
subject(:config) { Tinybucket.config }
|
17
|
-
let(:logger) { Logger.new($stdout) }
|
18
|
-
let(:oauth_token) { 'test_oauth_token' }
|
19
|
-
let(:oauth_secret) { 'test_oauth_secret' }
|
20
|
-
let(:cache_store_options) { { logger: Tinybucket.logger } }
|
21
|
-
|
22
|
-
it 'is configurable' do
|
23
|
-
expect(config.logger).to be_nil
|
24
|
-
|
25
|
-
expect do
|
26
|
-
Tinybucket.configure do |config|
|
27
|
-
config.logger = logger
|
28
|
-
config.cache_store_options = cache_store_options
|
29
|
-
config.oauth_token = oauth_token
|
30
|
-
config.oauth_secret = oauth_secret
|
31
|
-
end
|
32
|
-
end.not_to raise_error
|
33
|
-
|
34
|
-
expect(config.logger).to eq(logger)
|
35
|
-
expect(config.cache_store_options).to eq(cache_store_options)
|
36
|
-
expect(config.oauth_token).to eq(oauth_token)
|
37
|
-
expect(config.oauth_secret).to eq(oauth_secret)
|
38
|
-
end
|
39
|
-
|
40
|
-
after { Tinybucket.instance_variable_set(:@config, nil) }
|
41
|
-
end
|
42
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
|
4
|
-
require 'rspec'
|
5
|
-
require 'webmock/rspec'
|
6
|
-
|
7
|
-
require 'pry'
|
8
|
-
|
9
|
-
require 'coveralls'
|
10
|
-
require 'simplecov'
|
11
|
-
Coveralls.wear!
|
12
|
-
|
13
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
14
|
-
SimpleCov::Formatter::HTMLFormatter,
|
15
|
-
Coveralls::SimpleCov::Formatter
|
16
|
-
])
|
17
|
-
SimpleCov.start do
|
18
|
-
add_filter '.bundle/'
|
19
|
-
add_filter 'spec'
|
20
|
-
add_filter 'features'
|
21
|
-
end
|
22
|
-
|
23
|
-
if ENV['CODECLIMATE_REPORT']
|
24
|
-
WebMock.disable_net_connect!(allow: 'codeclimate.com')
|
25
|
-
require 'codeclimate-test-reporter'
|
26
|
-
CodeClimate::TestReporter.start
|
27
|
-
end
|
28
|
-
|
29
|
-
require 'tinybucket'
|
30
|
-
|
31
|
-
path = Pathname.new(Dir.pwd)
|
32
|
-
Dir[path.join('spec/support/**/*.rb')].each { |f| require f }
|
33
|
-
|
34
|
-
# configure tinybucket logger.
|
35
|
-
Dir.mkdir('log') unless Dir.exist?('log')
|
36
|
-
|
37
|
-
logger = Logger.new('log/test.log')
|
38
|
-
logger.level = Logger::DEBUG
|
39
|
-
Tinybucket.logger = logger
|
40
|
-
|
41
|
-
RSpec.configure do |config|
|
42
|
-
config.extend FixtureMacros
|
43
|
-
config.include FixtureMacros
|
44
|
-
config.order = 'random'
|
45
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
module ApiResponseMacros
|
2
|
-
def stub_apiresponse(method, path, options = {})
|
3
|
-
response_headers = { content_type: 'application/json' }.merge(options)
|
4
|
-
|
5
|
-
ext =
|
6
|
-
case response_headers[:content_type]
|
7
|
-
when 'plain/text' then; 'txt'
|
8
|
-
else 'json'
|
9
|
-
end
|
10
|
-
|
11
|
-
stub_request(method, api_path(path))
|
12
|
-
.to_return(
|
13
|
-
status: (options[:status_code] || 200),
|
14
|
-
body: (options[:message] || fixture_json(method, path, ext)),
|
15
|
-
headers: response_headers)
|
16
|
-
end
|
17
|
-
|
18
|
-
def stub_enum_response(method, path)
|
19
|
-
response_headers = { content_type: 'application/json' }
|
20
|
-
|
21
|
-
first_page_json = fixture_json(method, path, 'json')
|
22
|
-
|
23
|
-
# stub for first page
|
24
|
-
stub_request(method, api_path(path))
|
25
|
-
.to_return(
|
26
|
-
status: 200,
|
27
|
-
body: first_page_json,
|
28
|
-
headers: response_headers)
|
29
|
-
|
30
|
-
# stub for second(last) page
|
31
|
-
next_url = JSON.parse(first_page_json)['next'] || api_path(path, page: 2)
|
32
|
-
stub_request(method, next_url)
|
33
|
-
.to_return(
|
34
|
-
status: 200,
|
35
|
-
body: last_page_json(api_path(path, page: 1)),
|
36
|
-
headers: response_headers)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def api_path(path, params = {})
|
42
|
-
'https://api.bitbucket.org/2.0' + path + query_string(params)
|
43
|
-
end
|
44
|
-
|
45
|
-
def query_string(params)
|
46
|
-
return '' if params.empty?
|
47
|
-
|
48
|
-
'?' + params.each_pair.map do |k, v|
|
49
|
-
URI.escape(k.to_s) + '=' + URI.escape(v.to_s)
|
50
|
-
end.join('&')
|
51
|
-
end
|
52
|
-
|
53
|
-
def fixture_json(method, path, ext)
|
54
|
-
parts = path.split('?')
|
55
|
-
|
56
|
-
path = 'spec/fixtures' + parts[0]
|
57
|
-
fname = method.to_s
|
58
|
-
fname += '_' + parts[1].gsub(/[\/??&=]/, '_') if parts[1].present?
|
59
|
-
fname += '.' + ext
|
60
|
-
|
61
|
-
File.read(path + '/' + fname)
|
62
|
-
end
|
63
|
-
|
64
|
-
def last_page_json(prev)
|
65
|
-
JSON.generate(
|
66
|
-
size: 1,
|
67
|
-
page: 2,
|
68
|
-
pagelen: 0,
|
69
|
-
next: nil,
|
70
|
-
previous: prev,
|
71
|
-
values: []
|
72
|
-
)
|
73
|
-
end
|
74
|
-
end
|
@@ -1,103 +0,0 @@
|
|
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
|
-
|
28
|
-
RSpec.shared_examples 'the model is reloadable' do
|
29
|
-
describe '#load' do
|
30
|
-
before do
|
31
|
-
allow(@model).to \
|
32
|
-
receive_message_chain(:load_model, :attributes).and_return({})
|
33
|
-
end
|
34
|
-
subject { @model.load }
|
35
|
-
|
36
|
-
context 'when not loaded' do
|
37
|
-
it { expect(subject).to be_truthy }
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when load failed' do
|
41
|
-
let(:env) do
|
42
|
-
{
|
43
|
-
htt_method: :get,
|
44
|
-
request_url: 'https://localhost/path/to/resource',
|
45
|
-
status_code: 404,
|
46
|
-
response_body: 'not found'
|
47
|
-
}
|
48
|
-
end
|
49
|
-
before do
|
50
|
-
@model.stub(:load_model) { raise Tinybucket::Error::NotFound.new(env) }
|
51
|
-
end
|
52
|
-
|
53
|
-
it { expect { subject }.to raise_error(Tinybucket::Error::NotFound) }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#loaded?' do
|
58
|
-
subject { @model.loaded? }
|
59
|
-
|
60
|
-
context 'when model is not loaded' do
|
61
|
-
it { expect(@model.loaded?).to be_falsey }
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'when model is already loaded' do
|
65
|
-
before do
|
66
|
-
allow(@model).to \
|
67
|
-
receive_message_chain(:load_model, :attributes).and_return({})
|
68
|
-
@model.load
|
69
|
-
end
|
70
|
-
it { expect(subject).to be_truthy }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe '#reload' do
|
75
|
-
subject { @model.reload }
|
76
|
-
|
77
|
-
context 'when load successfully' do
|
78
|
-
before do
|
79
|
-
allow(@model).to \
|
80
|
-
receive_message_chain(:load_model, :attributes).and_return({})
|
81
|
-
@model.load
|
82
|
-
end
|
83
|
-
it { expect(subject).to be_truthy }
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when load failed' do
|
87
|
-
let(:env) do
|
88
|
-
{
|
89
|
-
htt_method: :get,
|
90
|
-
request_url: 'https://localhost/path/to/resource',
|
91
|
-
status_code: 404,
|
92
|
-
response_body: 'not found'
|
93
|
-
}
|
94
|
-
end
|
95
|
-
before do
|
96
|
-
@model.stub(:load_model) { raise Tinybucket::Error::NotFound.new(env) }
|
97
|
-
end
|
98
|
-
|
99
|
-
it { expect { subject }.to raise_error(Tinybucket::Error::NotFound) }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|