Skip to content

Commit

Permalink
add size method.
Browse files Browse the repository at this point in the history
update Guardfile.

fixes issue #7
  • Loading branch information
hirakiuc committed Aug 22, 2014
1 parent ef24dd5 commit bcb82a8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
guard 'rspec' , cmd: 'rspec --drb' do
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^spec/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
guard 'rspec', cmd: 'rspec --drb' do
watch(/^spec\/.+_spec\.rb$/)
watch(/^lib\/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" }
watch(/^spec\/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }

watch(/^lib\/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" }
end

guard :rubocop, all_on_start: true, cmd: ['--format', 'clang', '-c', '.rubocop.yml'] do
watch(%r{^lib/(.+)\.rb$})
watch(%r{\.rubocop.yml$})
watch(/^lib\/(.+)\.rb$/)
watch(/\.rubocop.yml$/)
end
4 changes: 4 additions & 0 deletions lib/tinybucket/model/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def initialize(json, item_klass)
end
end

def size
@attrs[:size]
end

def each(options = {})
loop do
start = (@attrs[:page] - 1) * @attrs[:pagelen]
Expand Down
58 changes: 58 additions & 0 deletions spec/lib/tinybucket/model/page_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'spec_helper'

RSpec.describe Tinybucket::Model::Page do

let(:json) do
text = File.read('spec/fixtures/repositories/get.json')
JSON.parse(text)
end

let(:klass) { Tinybucket::Model::Repository }
let(:model) { Tinybucket::Model::Page.new(json, klass) }

describe 'initialize' do
subject { model }

it 'create instance' do
expect(subject).to be_an_instance_of(Tinybucket::Model::Page)

expect(subject.attrs[:size]).to eq(json['size'])
expect(subject.attrs[:page]).to eq(json['page'])
expect(subject.attrs[:pagelen]).to eq(json['pagelen'])
expect(subject.attrs[:next]).to eq(json['next'])
expect(subject.attrs[:previous]).to eq(json['previous'])

expect(subject.items.size).to eq(json['values'].size)
end
end

describe 'size' do
subject { model.size }

let(:base_json) do
text = File.read('spec/fixtures/repositories/get.json')
JSON.parse(text)
end

context 'when json contains size = nil' do
let(:json) do
base_json['size'] = nil
base_json
end
it { expect(subject).to be_nil }
end

context 'when json contains size' do
let(:size) { 1000 }
let(:json) do
base_json['size'] = size
base_json
end
it { expect(subject).to eq(size) }
end
end

describe 'each' do
pending 'TODO add specs'
end
end

0 comments on commit bcb82a8

Please sign in to comment.