passbook 0.2.1 → 0.3.1

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.
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+ require 'terminal-table'
3
+ require 'commander/import'
4
+ require 'utils/command_utils'
5
+
6
+ def load_commands
7
+ Dir['lib/commands/**/*.rb'].each {|f|
8
+ load File.join(File.dirname(__FILE__), '../../..', f)
9
+ require File.join(File.dirname(__FILE__), '../../..', f.gsub(/.rb/, ''))
10
+ }
11
+ end
12
+
13
+ def mock_terminal
14
+ @input = StringIO.new
15
+ @output = StringIO.new
16
+ $terminal = HighLine.new @input, @output
17
+ end
18
+
19
+ def new_command_runner *args, &block
20
+ Commander::Runner.instance_variable_set :"@singleton", Commander::Runner.new(args)
21
+ program :version, '1.2.3'
22
+ program :description, "Honey Badger Don't Care"
23
+ yield if block
24
+ Commander::Runner.instance
25
+ end
26
+
27
+ def run *args
28
+ runner = new_command_runner(*args) do
29
+ load_commands
30
+ end
31
+ runner.run!
32
+ @output.string
33
+ end
34
+
35
+ RSpec::Matchers.define :exit_with_code do |exp_code|
36
+ actual = nil
37
+ match do |block|
38
+ begin
39
+ block.call
40
+ rescue SystemExit => e
41
+ actual = e.status
42
+ end
43
+ actual and actual == exp_code
44
+ end
45
+ failure_message_for_should do |block|
46
+ "expected block to call exit(#{exp_code}) but exit" +
47
+ (actual.nil? ? " not called" : "(#{actual}) was called")
48
+ end
49
+ failure_message_for_should_not do |block|
50
+ "expected block not to call exit(#{exp_code})"
51
+ end
52
+ description do
53
+ "expect block to call exit(#{exp_code})"
54
+ end
55
+ end
56
+
57
+ def run_raw_command(*args)
58
+ lambda{
59
+ run(*args)
60
+ }.should raise_error(SystemExit, ' ')
61
+ end
62
+
63
+ def run_command(*args, &block)
64
+ begin
65
+ run_raw_command *args
66
+ rescue
67
+ yield
68
+ end
69
+ end
@@ -0,0 +1,72 @@
1
+ require 'lib/commands/commands_spec_helper'
2
+ require 'passbook'
3
+
4
+ describe 'Generate' do
5
+
6
+ before :each do
7
+ $stderr = StringIO.new
8
+ mock_terminal
9
+ end
10
+
11
+ context 'command' do
12
+ specify 'no options' do
13
+ run_command 'generate' do
14
+ @output.string.should eq 'Enter a passbook name: '
15
+ end
16
+
17
+ end
18
+
19
+ specify 'passbook entered directory already exists' do
20
+ @input << "my_awesome_passbook\n"
21
+ @input.rewind
22
+ File.should_receive(:directory?).with('my_awesome_passbook').and_return true
23
+ run_command 'generate' do
24
+ @output.string.should eq "Enter a passbook name: \e[31mDirectory my_awesome_passbook already exists\e[0m\n"
25
+ end
26
+ end
27
+
28
+ specify 'passbook entered file already exists' do
29
+ @input << "my_awesome_passbook\n"
30
+ @input.rewind
31
+ File.should_receive(:directory?).with('my_awesome_passbook').and_return false
32
+ File.should_receive(:exist?).with('my_awesome_passbook').and_return true
33
+ run_command 'generate' do
34
+ @output.string.should eq "Enter a passbook name: \e[31mFile exists at my_awesome_passbook\e[0m\n"
35
+ end
36
+ end
37
+
38
+ context 'valid pass directory' do
39
+
40
+ before :each do
41
+ File.should_receive(:directory?).with('my_awesome_passbook').and_return false
42
+ File.should_receive(:exist?).with('my_awesome_passbook').and_return false
43
+ end
44
+
45
+ specify 'invalid type' do
46
+ @input << "my_awesome_passbook\n"
47
+ @input.rewind
48
+ run_command 'generate', '-T', 'honey_badger' do
49
+ @output.string.should eq "Enter a passbook name: \e[31mInvalid type: \"honey_badger\", expected one of: [boarding-pass, coupon, event-ticket, store-card, generic]\e[0m\n"
50
+ end
51
+ end
52
+
53
+ specify 'valid type' do
54
+ CommandUtils.should_receive(:get_current_directory).and_return('')
55
+ FileUtils.should_receive(:mkdir_p).with('my_awesome_passbook')
56
+ FileUtils.should_receive(:cp).with("/../commands/templates/boarding-pass.json", "my_awesome_passbook/pass.json")
57
+ FileUtils.should_receive(:touch).with("my_awesome_passbook/icon.png")
58
+ FileUtils.should_receive(:touch).with("my_awesome_passbook/icon@2x.png")
59
+ @input << "1\n"
60
+ @input.rewind
61
+ run_command 'generate', 'my_awesome_passbook' do
62
+ @output.string.should eq "Select a pass type\n1. boarding-pass\n2. coupon\n3. event-ticket\n4. store-card\n5. generic\n? \e[32mPass generated in my_awesome_passbook\e[0m\n"
63
+ end
64
+ end
65
+ end
66
+
67
+
68
+ end
69
+
70
+
71
+ end
72
+
@@ -57,7 +57,7 @@ describe Passbook do
57
57
  File.should_receive(:read).with('my_p12_key').and_return 'my_p12_key_file'
58
58
  File.should_receive(:read).with('my_p12_certificate').and_return 'my_p12_certificate_file'
59
59
  OpenSSL::PKey::RSA.should_receive(:new).with('my_p12_key_file', 'password').and_return 'my_rsa_key'
60
- OpenSSL::X509::Certificate.should_receive(:new).with('my_p12_certificate_file').and_return 'my_ssl_p12_cert'
60
+ OpenSSL::X509::Certificate.should_receive(:new).with('my_p12_certificate_file').and_return 'my_ssl_p12_cert'
61
61
  end
62
62
 
63
63
  subject {pass.get_p12_cert_and_key}
@@ -92,7 +92,7 @@ describe Passbook do
92
92
  pass.addFiles ["#{base_path}/icon.png","#{base_path}/icon@2x.png","#{base_path}/logo.png","#{base_path}/logo@2x.png"]
93
93
  pass.should_receive(:createSignature).and_return('Signed by the Honey Badger')
94
94
  @file_entries = []
95
- Zip::ZipInputStream::open(zip_path) {|io|
95
+ Zip::InputStream::open(zip_path) {|io|
96
96
  while (entry = io.get_next_entry)
97
97
  @file_entries << entry.name
98
98
  end
@@ -122,7 +122,26 @@ describe Passbook do
122
122
 
123
123
  after do
124
124
  temp_file.delete
125
- end
125
+ end
126
+ end
127
+ end
128
+
129
+ # TODO: find a proper way to do this
130
+ context 'Error catcher' do
131
+ context 'formatVersion' do
132
+ let (:base_path) {'spec/data'}
133
+
134
+ before :each do
135
+ pass.addFiles ["#{base_path}/icon.png","#{base_path}/icon@2x.png","#{base_path}/logo.png","#{base_path}/logo@2x.png"]
136
+ tpass = JSON.parse(pass.pass)
137
+ tpass['formatVersion'] = 'It should be a numeric'
138
+ pass.pass = tpass.to_json
139
+ end
140
+
141
+ it "raise an error" do
142
+ expect { pass.build }.to raise_error('Format Version should be a numeric')
143
+ end
144
+
126
145
  end
127
146
  end
128
147
  end
@@ -14,6 +14,7 @@ describe Rack::PassbookRack do
14
14
  'serialNumber' => '27-1'}}
15
15
  let(:log_path) {'/v1/log'}
16
16
  let(:push_token) {"8c56f2e787d9c089963960ace834bc2875e3f0cf7745da5b98d58bc6be05b4dc"}
17
+ let(:auth_token) {"3c0adc9ccbcf3e733edeb897043a4835"}
17
18
 
18
19
  context 'find method' do
19
20
  let(:passbook_rack) {Rack::PassbookRack.new nil}
@@ -71,7 +72,7 @@ describe Rack::PassbookRack do
71
72
 
72
73
  context 'rack middleware' do
73
74
 
74
- context 'register pass' do
75
+ context 'register pass without authToken' do
75
76
  before do
76
77
  Passbook::PassbookNotification.should_receive(:register_pass).
77
78
  with(register_delete_params.merge!('pushToken' => push_token)).and_return({:status => 201})
@@ -82,6 +83,17 @@ describe Rack::PassbookRack do
82
83
  its(:status) {should eq 201}
83
84
  end
84
85
 
86
+ context 'register pass with authToken' do
87
+ before do
88
+ Passbook::PassbookNotification.should_receive(:register_pass).
89
+ with(register_delete_params.merge!('pushToken' => push_token,'authToken' => auth_token)).and_return({:status => 201})
90
+ post register_delete_path, {"pushToken" => push_token}.to_json, rack_env = {'HTTP_AUTHORIZATION' => auth_token}
91
+ end
92
+
93
+ subject {last_response}
94
+ its(:status) {should eq 201}
95
+ end
96
+
85
97
  context 'passes for device' do
86
98
  context 'with passes' do
87
99
  let(:passes_for_device_response) {{'last_updated' => 1, 'serial_numbers' => [343, 234]}}
@@ -102,6 +114,20 @@ describe Rack::PassbookRack do
102
114
  end
103
115
  end
104
116
 
117
+ context 'with passes modified since' do
118
+ before do
119
+ Passbook::PassbookNotification.should_receive(:passes_for_device).
120
+ with(passes_for_device_params.merge!('passesUpdatedSince' => '1371189712')).and_return(nil)
121
+ path_with_update_since = passes_for_device_path + "?passesUpdatedSince=1371189712"
122
+ get path_with_update_since
123
+ end
124
+
125
+ context 'status' do
126
+ subject {last_response.status}
127
+ it {should eq 204}
128
+ end
129
+ end
130
+
105
131
  context 'without passes' do
106
132
  before do
107
133
  Passbook::PassbookNotification.should_receive(:passes_for_device).
@@ -145,7 +171,7 @@ describe Rack::PassbookRack do
145
171
  end
146
172
  end
147
173
 
148
- context 'unregister pass' do
174
+ context 'unregister pass without authToken' do
149
175
  before do
150
176
  Passbook::PassbookNotification.should_receive(:unregister_pass).
151
177
  with(register_delete_params).and_return({:status => 200})
@@ -154,12 +180,23 @@ describe Rack::PassbookRack do
154
180
 
155
181
  subject {last_response}
156
182
  its(:status) {should eq 200}
157
- end
183
+ end
184
+
185
+ context 'unregister pass with authToken' do
186
+ before do
187
+ Passbook::PassbookNotification.should_receive(:unregister_pass).
188
+ with(register_delete_params.merge!('authToken' => auth_token)).and_return({:status => 200})
189
+ delete register_delete_path, {}, rack_env = {'HTTP_AUTHORIZATION' => auth_token}
190
+ end
191
+
192
+ subject {last_response}
193
+ its(:status) {should eq 200}
194
+ end
158
195
 
159
196
  context 'log' do
160
197
  let(:log_params) {{'logs' => ['some error']}}
161
198
  before do
162
- Passbook::PassbookNotification.should_receive(:log).
199
+ Passbook::PassbookNotification.should_receive(:passbook_log).
163
200
  with(log_params)
164
201
  post log_path, log_params.to_json
165
202
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.3.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Thomas Lauro
@@ -10,12 +9,25 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-03-08 00:00:00.000000000 Z
12
+ date: 2013-10-29 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rubyzip
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 1.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: grocer
30
+ requirement: !ruby/object:Gem::Requirement
19
31
  requirements:
20
32
  - - ! '>='
21
33
  - !ruby/object:Gem::Version
@@ -23,15 +35,27 @@ dependencies:
23
35
  type: :runtime
24
36
  prerelease: false
25
37
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
38
  requirements:
28
39
  - - ! '>='
29
40
  - !ruby/object:Gem::Version
30
41
  version: '0'
31
42
  - !ruby/object:Gem::Dependency
32
- name: grocer
43
+ name: commander
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: terminal-table
33
58
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
59
  requirements:
36
60
  - - ! '>='
37
61
  - !ruby/object:Gem::Version
@@ -39,7 +63,6 @@ dependencies:
39
63
  type: :runtime
40
64
  prerelease: false
41
65
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
66
  requirements:
44
67
  - - ! '>='
45
68
  - !ruby/object:Gem::Version
@@ -47,7 +70,6 @@ dependencies:
47
70
  - !ruby/object:Gem::Dependency
48
71
  name: rack-test
49
72
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
73
  requirements:
52
74
  - - ! '>='
53
75
  - !ruby/object:Gem::Version
@@ -55,7 +77,6 @@ dependencies:
55
77
  type: :development
56
78
  prerelease: false
57
79
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
80
  requirements:
60
81
  - - ! '>='
61
82
  - !ruby/object:Gem::Version
@@ -63,7 +84,6 @@ dependencies:
63
84
  - !ruby/object:Gem::Dependency
64
85
  name: activesupport
65
86
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
87
  requirements:
68
88
  - - ! '>='
69
89
  - !ruby/object:Gem::Version
@@ -71,7 +91,6 @@ dependencies:
71
91
  type: :development
72
92
  prerelease: false
73
93
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
94
  requirements:
76
95
  - - ! '>='
77
96
  - !ruby/object:Gem::Version
@@ -79,7 +98,6 @@ dependencies:
79
98
  - !ruby/object:Gem::Dependency
80
99
  name: jeweler
81
100
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
101
  requirements:
84
102
  - - ! '>='
85
103
  - !ruby/object:Gem::Version
@@ -87,7 +105,6 @@ dependencies:
87
105
  type: :development
88
106
  prerelease: false
89
107
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
108
  requirements:
92
109
  - - ! '>='
93
110
  - !ruby/object:Gem::Version
@@ -95,7 +112,6 @@ dependencies:
95
112
  - !ruby/object:Gem::Dependency
96
113
  name: simplecov
97
114
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
115
  requirements:
100
116
  - - ! '>='
101
117
  - !ruby/object:Gem::Version
@@ -103,7 +119,6 @@ dependencies:
103
119
  type: :development
104
120
  prerelease: false
105
121
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
122
  requirements:
108
123
  - - ! '>='
109
124
  - !ruby/object:Gem::Version
@@ -111,7 +126,6 @@ dependencies:
111
126
  - !ruby/object:Gem::Dependency
112
127
  name: rspec
113
128
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
129
  requirements:
116
130
  - - ! '>='
117
131
  - !ruby/object:Gem::Version
@@ -119,7 +133,6 @@ dependencies:
119
133
  type: :development
120
134
  prerelease: false
121
135
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
136
  requirements:
124
137
  - - ! '>='
125
138
  - !ruby/object:Gem::Version
@@ -127,7 +140,6 @@ dependencies:
127
140
  - !ruby/object:Gem::Dependency
128
141
  name: rake
129
142
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
143
  requirements:
132
144
  - - ! '>='
133
145
  - !ruby/object:Gem::Version
@@ -135,7 +147,6 @@ dependencies:
135
147
  type: :development
136
148
  prerelease: false
137
149
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
150
  requirements:
140
151
  - - ! '>='
141
152
  - !ruby/object:Gem::Version
@@ -143,7 +154,6 @@ dependencies:
143
154
  - !ruby/object:Gem::Dependency
144
155
  name: yard
145
156
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
157
  requirements:
148
158
  - - ! '>='
149
159
  - !ruby/object:Gem::Version
@@ -151,7 +161,6 @@ dependencies:
151
161
  type: :development
152
162
  prerelease: false
153
163
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
164
  requirements:
156
165
  - - ! '>='
157
166
  - !ruby/object:Gem::Version
@@ -161,7 +170,8 @@ description: This gem allows you to create IOS Passbooks. Unlike some, this wo
161
170
  email:
162
171
  - thomas@lauro.fr
163
172
  - lgleason@polyglotprogramminginc.com
164
- executables: []
173
+ executables:
174
+ - pk
165
175
  extensions: []
166
176
  extra_rdoc_files:
167
177
  - LICENSE
@@ -174,6 +184,15 @@ files:
174
184
  - README.md
175
185
  - Rakefile
176
186
  - VERSION
187
+ - bin/pk
188
+ - lib/commands/build.rb
189
+ - lib/commands/commands.rb
190
+ - lib/commands/generate.rb
191
+ - lib/commands/templates/boarding-pass.json
192
+ - lib/commands/templates/coupon.json
193
+ - lib/commands/templates/event-ticket.json
194
+ - lib/commands/templates/generic.json
195
+ - lib/commands/templates/store-card.json
177
196
  - lib/passbook.rb
178
197
  - lib/passbook/pkpass.rb
179
198
  - lib/passbook/push_notification.rb
@@ -181,11 +200,16 @@ files:
181
200
  - lib/rack/passbook_rack.rb
182
201
  - lib/rails/generators/passbook/config/config_generator.rb
183
202
  - lib/rails/generators/passbook/config/templates/initializer.rb
203
+ - lib/utils/command_utils.rb
184
204
  - passbook.gemspec
185
205
  - spec/data/icon.png
186
206
  - spec/data/icon@2x.png
187
207
  - spec/data/logo.png
188
208
  - spec/data/logo@2x.png
209
+ - spec/lib/commands/build_spec.rb
210
+ - spec/lib/commands/commands_spec.rb
211
+ - spec/lib/commands/commands_spec_helper.rb
212
+ - spec/lib/commands/generate_spec.rb
189
213
  - spec/lib/passbook/pkpass_spec.rb
190
214
  - spec/lib/passbook/push_notification_spec.rb
191
215
  - spec/lib/rack/passbook_rack_spec.rb
@@ -193,27 +217,26 @@ files:
193
217
  homepage: http://github.com/frozon/passbook
194
218
  licenses:
195
219
  - MIT
220
+ metadata: {}
196
221
  post_install_message:
197
222
  rdoc_options: []
198
223
  require_paths:
199
224
  - lib
200
225
  required_ruby_version: !ruby/object:Gem::Requirement
201
- none: false
202
226
  requirements:
203
227
  - - ! '>='
204
228
  - !ruby/object:Gem::Version
205
229
  version: '0'
206
230
  required_rubygems_version: !ruby/object:Gem::Requirement
207
- none: false
208
231
  requirements:
209
232
  - - ! '>='
210
233
  - !ruby/object:Gem::Version
211
234
  version: '0'
212
235
  requirements: []
213
236
  rubyforge_project:
214
- rubygems_version: 1.8.24
237
+ rubygems_version: 2.1.10
215
238
  signing_key:
216
- specification_version: 3
239
+ specification_version: 4
217
240
  summary: A IOS Passbook generator.
218
241
  test_files: []
219
242
  has_rdoc: