Created
June 13, 2013 23:31
-
-
Save GrooveStomp/5778312 to your computer and use it in GitHub Desktop.
Spec exercising date/time usage with the API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Requirements for this shared example: | |
| # - api_key: ApiKey class instance used for authentication. | |
| # - factory: Name of FactoryGirl factory as a symbol. | |
| # - deps: Hash of dependencies to pass into FactoryGirl.create. | |
| # - params: Parameters to fulfill #index request. | |
| # | |
| # collection: Name to inspect in the resultset. | |
| # See: https://api.unbounce.com/doc/pages#collection_overview | |
| # In the sample responses there, `collection` should be 'pages'. | |
| # | |
| shared_examples_for 'resource_date_filter' do |collection| | |
| let(:prior) { create(factory, deps) } | |
| let(:gmt_resource) { create(factory, deps) } | |
| let(:middle) { create(factory, deps) } | |
| let(:pst_resource) { create(factory, deps) } | |
| let(:after) { create(factory, deps) } | |
| let(:gmt_datetime) { DateTime.now.change(offset: "+0000") } | |
| let(:pst_datetime) { gmt_datetime.change(offset: "-0800") } | |
| describe '#index' do | |
| before do | |
| FormSubmission.destroy_all | |
| gmt_resource.update_column(:created_at, gmt_datetime) | |
| gmt_resource.update_column(:form_data, '{"name":["gmt datetime"]}') | |
| pst_resource.update_column(:created_at, pst_datetime) | |
| pst_resource.update_column(:form_data, '{"name":["pst datetime"]}') | |
| prior.update_column(:created_at, gmt_datetime - 4.hours) | |
| middle.update_column(:created_at, gmt_datetime + 4.hours) | |
| after.update_column(:created_at, pst_datetime + 4.hours) | |
| basic_auth(api_key.key, '') | |
| request.env['HTTP_ACCEPT'] = 'application/json' | |
| end | |
| subject { ActiveSupport::JSON.decode(response.body)[collection] } | |
| context 'requesting all resources up to gmt' do | |
| before { get :index, params.merge(to: gmt_datetime.rfc3339) } | |
| specify { subject.each { |res| DateTime.rfc3339(res['createdAt']).should < gmt_datetime } } | |
| its(:count) { should == 1 } | |
| end | |
| context 'requesting all resources since gmt' do | |
| before { get :index, params.merge(from: gmt_datetime.rfc3339) } | |
| specify { subject.each { |res| DateTime.rfc3339(res['createdAt']).should > gmt_datetime } } | |
| its(:count) { should == 3 } | |
| end | |
| context 'requesting all resources up to pst' do | |
| before { get :index, params.merge(to: pst_datetime.rfc3339) } | |
| specify { subject.each { |res| DateTime.rfc3339(res['createdAt']).should < pst_datetime } } | |
| its(:count) { should == 3 } | |
| end | |
| context 'requesting all resources since pst' do | |
| before { get :index, params.merge(from: pst_datetime.rfc3339) } | |
| specify { subject.each { |res| DateTime.rfc3339(res['createdAt']).should > pst_datetime } } | |
| its(:count) { should == 1 } | |
| end | |
| # When I use GMT, I should get leads only newer than GMT. | |
| # -> Currently don't, by a few hours. | |
| # When I use PST, I should get leads only new than PST. | |
| # -> This already *does* work. | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment