Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/rack/passbook_rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(app)
def call(env)
@parameters['authToken'] = env['HTTP_AUTHORIZATION'].gsub(/ApplePass /,'') if env['HTTP_AUTHORIZATION']
@parameters.merge!(Rack::Utils.parse_nested_query(env['QUERY_STRING']))
@parameters['ifModifiedSince'] = env['HTTP_IF_MODIFIED_SINCE'] if env['HTTP_IF_MODIFIED_SINCE']
method_and_params = find_method env['PATH_INFO']
if method_and_params
case method_and_params[:method]
Expand All @@ -25,12 +26,12 @@ def call(env)
[response ? 200 : 204, {}, [response.to_json]]
when 'latest_pass'
response = Passbook::PassbookNotification.latest_pass(method_and_params[:params])
if response
[200, {'Content-Type' => 'application/vnd.apple.pkpass',
'Content-Disposition' => 'attachment',
'filename' => "#{method_and_params[:params]['serialNumber']}.pkpass"}, [response]]
if response[:status] == 200
[200, {'Content-Type' => 'application/vnd.apple.pkpass',
'Content-Disposition' => 'attachment',
'filename' => "#{method_and_params[:params]['serialNumber']}.pkpass","last-modified" => response[:last_modified]}, [response[:latest_pass]]]
else
[204, {}, {}]
[response[:status], {}, {}]
end
when 'log'
Passbook::PassbookNotification.passbook_log JSON.parse(env['rack.input'].read 10000)
Expand Down
22 changes: 16 additions & 6 deletions spec/lib/rack/passbook_rack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@
end

context 'get latest pass' do
context 'valid pass' do
let(:raw_pass) {'some url encoded text'}
context 'valid pass updated after if modified since' do
let(:raw_pass) {{:status => 200, :latest_pass => 'some url encoded text', :last_modified => '13713445412'}}

before do
Passbook::PassbookNotification.should_receive(:latest_pass).with(latest_pass_params).
Expand All @@ -154,15 +154,25 @@

subject {last_response}
its(:status) {should eq 200}
its(:header) {should eq({'Content-Type' => 'application/vnd.apple.pkpass',
'Content-Disposition' => 'attachment', 'filename' => '27-1.pkpass', 'Content-Length' => '21'})}
its(:body) {should eq raw_pass}
its(:header) {should eq({'Content-Type' => 'application/vnd.apple.pkpass',
'Content-Disposition' => 'attachment', 'filename' => '27-1.pkpass', 'last-modified' => '13713445412', 'Content-Length' => '21'})}
its(:body) {should eq raw_pass[:latest_pass]}
end

context 'pass not updated after if modified since' do
before do
Passbook::PassbookNotification.should_receive(:latest_pass).with(latest_pass_params.merge!('ifModifiedSince' => '1371189712')).
and_return({:status => 304})
get latest_pass_path, {}, rack_env = {'HTTP_IF_MODIFIED_SINCE' => '1371189712'}
end
subject {last_response}
its(:status) {should eq 304}
end

context 'no pass' do
before do
Passbook::PassbookNotification.should_receive(:latest_pass).with(latest_pass_params).
and_return(nil)
and_return({:status => 204, :latest_pass => nil})
get latest_pass_path
end

Expand Down