Skip to content

Commit

Permalink
Automatically convert before and after arguments of Strava::Api::Clie…
Browse files Browse the repository at this point in the history
…nt#athlete_activities from Time to Integer.
  • Loading branch information
dblock committed Dec 5, 2018
1 parent 4551d79 commit d15530e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
### 0.3.2 (Next)

* Automatically convert `before` and `after` arguments of `Strava::Api::Client#athlete_activities` from `Time` to `Integer` - [@dblock](https://github.com/dblock).
* Your contribution here.

### 0.3.1 (2018/12/05)
Expand Down
3 changes: 3 additions & 0 deletions lib/strava/api/endpoints/activities.rb
Expand Up @@ -91,6 +91,9 @@ def activity_laps(id_or_options, options = {})
# Number of items per page. Defaults to 30.
#
def athlete_activities(options = {}, &block)
options = options.dup if options.key?(:after) || options.key?(:before)
options[:after] = options[:after].to_i if options[:after]
options[:before] = options[:before].to_i if options[:before]
paginate 'athlete/activities', options, Strava::Models::Activity, &block
end

Expand Down
76 changes: 76 additions & 0 deletions spec/fixtures/strava/client/athlete_activities_december_2018.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -2,9 +2,9 @@

RSpec.describe 'Strava::Api::Client#athlete_activities' do
include_context 'API client'
describe '#athlete_activities', vcr: { cassette_name: 'client/athlete_activities' } do
let(:athlete_activities) { client.athlete_activities }
it 'returns athlete activities' do
describe '#athlete_activities' do
it 'returns athlete activities', vcr: { cassette_name: 'client/athlete_activities' } do
athlete_activities = client.athlete_activities
expect(athlete_activities).to be_a Enumerable
expect(athlete_activities.count).to eq 30
activity = athlete_activities.first
Expand All @@ -13,6 +13,11 @@
expect(activity.map).to be_a Strava::Models::Map
expect(activity.start_date).to be_a Time
end
it 'returns athlete activities for December 2018 only', vcr: { cassette_name: 'client/athlete_activities_december_2018' } do
athlete_activities = client.athlete_activities(before: Time.parse('2019/1/1'), after: Time.parse('2018/11/1'))
expect(athlete_activities).to be_a Enumerable
expect(athlete_activities.count).to eq 8
end
end
describe 'paginated #athlete_activities', vcr: { cassette_name: 'client/all_athlete_activities' } do
let(:athlete_activities) do
Expand Down

0 comments on commit d15530e

Please sign in to comment.