motorurl 0.0.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.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +3 -0
  4. data/Rakefile +18 -0
  5. data/app/assets/stylesheets/motorurl/application.css +13 -0
  6. data/app/controllers/motorurl/application_controller.rb +12 -0
  7. data/app/controllers/motorurl/sensors_controller.rb +18 -0
  8. data/app/helpers/motorurl/application_helper.rb +4 -0
  9. data/app/views/layouts/motorurl/application.html.erb +14 -0
  10. data/config/routes.rb +3 -0
  11. data/lib/motorurl.rb +46 -0
  12. data/lib/motorurl/capistrano/recipes.rb +33 -0
  13. data/lib/motorurl/engine.rb +12 -0
  14. data/lib/motorurl/railtie.rb +7 -0
  15. data/lib/motorurl/registrar.rb +29 -0
  16. data/lib/motorurl/report.rb +22 -0
  17. data/lib/motorurl/transmitter.rb +41 -0
  18. data/lib/motorurl/version.rb +3 -0
  19. data/lib/tasks/motorurl_tasks.rake +11 -0
  20. data/spec/controllers/sensors_controller_spec.rb +39 -0
  21. data/spec/dummy/Capfile +28 -0
  22. data/spec/dummy/Procfile +2 -0
  23. data/spec/dummy/README.rdoc +28 -0
  24. data/spec/dummy/Rakefile +6 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  26. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  27. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  28. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  29. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  30. data/spec/dummy/bin/bundle +3 -0
  31. data/spec/dummy/bin/rails +4 -0
  32. data/spec/dummy/bin/rake +4 -0
  33. data/spec/dummy/config.ru +4 -0
  34. data/spec/dummy/config/application.rb +24 -0
  35. data/spec/dummy/config/boot.rb +5 -0
  36. data/spec/dummy/config/database.yml +25 -0
  37. data/spec/dummy/config/deploy.rb +40 -0
  38. data/spec/dummy/config/deploy/production.rb +43 -0
  39. data/spec/dummy/config/deploy/staging.rb +43 -0
  40. data/spec/dummy/config/environment.rb +5 -0
  41. data/spec/dummy/config/environments/development.rb +29 -0
  42. data/spec/dummy/config/environments/production.rb +80 -0
  43. data/spec/dummy/config/environments/test.rb +36 -0
  44. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  45. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  46. data/spec/dummy/config/initializers/inflections.rb +16 -0
  47. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  48. data/spec/dummy/config/initializers/motorurl.rb +10 -0
  49. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  50. data/spec/dummy/config/initializers/session_store.rb +3 -0
  51. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  52. data/spec/dummy/config/locales/en.yml +23 -0
  53. data/spec/dummy/config/routes.rb +6 -0
  54. data/spec/dummy/db/development.sqlite3 +0 -0
  55. data/spec/dummy/db/schema.rb +16 -0
  56. data/spec/dummy/db/test.sqlite3 +0 -0
  57. data/spec/dummy/lib/job.rb +19 -0
  58. data/spec/dummy/log/development.log +4698 -0
  59. data/spec/dummy/log/sidekiq.log +16656 -0
  60. data/spec/dummy/public/404.html +58 -0
  61. data/spec/dummy/public/422.html +58 -0
  62. data/spec/dummy/public/500.html +57 -0
  63. data/spec/dummy/public/favicon.ico +0 -0
  64. data/spec/dummy/tmp/pids/server.pid +1 -0
  65. data/spec/lib/registrar_spec.rb +63 -0
  66. data/spec/lib/report_spec.rb +21 -0
  67. data/spec/lib/transmitter_spec.rb +48 -0
  68. data/spec/modules/motorurl_spec.rb +74 -0
  69. data/spec/routing/engine_routes_spec.rb +21 -0
  70. data/spec/spec_helper.rb +52 -0
  71. data/spec/support/passwords.rb +5 -0
  72. metadata +333 -0
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1 @@
1
+ 38721
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ module Motorurl
4
+ describe Registrar do
5
+ let!(:params) { {
6
+ callback_url: :callback_url,
7
+ canonical_name: :canon,
8
+ friendly_name: :officer_friendly,
9
+ price: 99 } }
10
+
11
+ describe 'Class Methods' do
12
+ describe '.register' do
13
+ it 'calls xmit with options' do
14
+ Registrar.any_instance.stub(:xmit) { :xmit }
15
+ expect(Registrar.register(params)).to eq(:xmit)
16
+ end
17
+ end
18
+ end
19
+
20
+ describe 'Instance Methods' do
21
+ describe '#new' do
22
+ describe 'initializes values to the config if no options provided' do
23
+ configuration = Motorurl.configuration
24
+ it { expect(subject.friendly_name).to eq(configuration.friendly_name) }
25
+ it { expect(subject.price).to eq(configuration.price) }
26
+ it { expect(subject.callback_url).to eq(configuration.callback_url) }
27
+ it { expect(subject.canonical_name).to eq(configuration.canonical_name) }
28
+ end
29
+
30
+ describe 'initializes values to options if provided' do
31
+ subject { described_class.new params }
32
+
33
+ it { expect(subject.callback_url).to eq(:callback_url) }
34
+ it { expect(subject.canonical_name).to eq(:canon) }
35
+ it { expect(subject.friendly_name).to eq(:officer_friendly) }
36
+ it { expect(subject.price).to eq(99) }
37
+ end
38
+ end
39
+
40
+ describe '#xmit' do
41
+ let(:body) { {
42
+ callback_url: 'http://www.dummy.com',
43
+ canonical_name: 'test_job',
44
+ friendly_name: 'Test Sensor',
45
+ password: 'password',
46
+ price: 10,
47
+ version: '0.0.1' } }
48
+
49
+ let(:params) { {
50
+ body: body,
51
+ headers: {'Content-Type' => 'application/json'} } }
52
+
53
+ it 'sends a registration request' do
54
+ stub_request(:post, 'localhost:8080/sensor')
55
+ .with(params)
56
+ .to_return(status: 200)
57
+
58
+ described_class.new(password: :password).xmit
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Motorurl
4
+ describe Report do
5
+ let(:data) { {
6
+ key1: 'value1',
7
+ key2: 1 } }
8
+
9
+ describe 'Class Methods' do
10
+ describe '.report' do
11
+ it 'sends the data' do
12
+ stub_request(:post, 'localhost:8080/sensor')
13
+ .with(body: hash_including(data: data)),
14
+ .to_return(status: 200)
15
+
16
+ described_class.report(data)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ module Motorurl
4
+ describe Transmitter do
5
+ describe 'Instance Methods' do
6
+ describe '#new' do
7
+ describe 'initializes values to the config if no options provided' do
8
+ configuration = Motorurl.configuration
9
+ it { expect(subject.base_uri).to eq(configuration.spiderman) }
10
+ it { expect(subject.password.to_s).to match(/\d{5,6}/) }
11
+ it { expect(subject.version).to eq('0.0.1') }
12
+ end
13
+
14
+ describe 'initializes values to options if provided' do
15
+ let!(:params) { {
16
+ base_uri: :base_uri,
17
+ password: :password,
18
+ version: :version } }
19
+
20
+ subject { described_class.new params }
21
+
22
+ it { expect(subject.base_uri).to eq(:base_uri) }
23
+ it { expect(subject.password).to eq(:password) }
24
+ it { expect(subject.version).to eq(:version) }
25
+ end
26
+ end
27
+
28
+ describe '#xmit' do
29
+ let(:body) { {
30
+ canonical_name: 'test_job',
31
+ password: 'password',
32
+ version: '0.0.1' } }
33
+
34
+ let(:params) { {
35
+ body: body,
36
+ headers: {'Content-Type' => 'application/json'} } }
37
+
38
+ it 'sends a basic request' do
39
+ stub_request(:post, 'localhost:8080/sensor')
40
+ .with(params)
41
+ .to_return(status: 200)
42
+
43
+ described_class.new(password: :password).xmit
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ module Motorurl
4
+ mattr_accessor :klass
5
+ end
6
+
7
+ describe Motorurl do
8
+ class X
9
+ end
10
+
11
+ describe 'Module Methods' do
12
+ before(:each) do
13
+ described_class.klass = nil
14
+ end
15
+
16
+ describe '.configure' do
17
+ let(:setting) { :random }
18
+
19
+ it 'can assign and retrieve any key' do
20
+ described_class.configure { |c| c.random_setting = setting }
21
+ expect(described_class.configuration.random_setting).to eq(setting)
22
+ end
23
+ end
24
+
25
+ describe '.process' do
26
+ let(:job_class) { fake perform: :job }
27
+
28
+ it 'spawns a sensor job' do
29
+ described_class.configure { |c| c.sensor_job_class = job_class }
30
+ expect(described_class.process({})).to eq(:job)
31
+ end
32
+ end
33
+
34
+ describe '.sensor_job_klass' do
35
+ it 'returns a class if a class is assigned' do
36
+ described_class.configuration.sensor_job_class = X
37
+ expect(described_class.sensor_job_class).to eq(X)
38
+ end
39
+
40
+ it 'returns a class if a string is assigned' do
41
+ described_class.configuration.sensor_job_class = 'X'
42
+ expect(described_class.sensor_job_class).to eq(X)
43
+ end
44
+
45
+ it 'raises an exception if class is nil' do
46
+ described_class.configuration.sensor_job_class = nil
47
+ expect { described_class.sensor_job_class }.to raise_exception
48
+ end
49
+
50
+ it 'raises an exception if class is non-existent' do
51
+ described_class.configuration.sensor_job_class = 'Y'
52
+ expect { described_class.sensor_job_class }.to raise_exception
53
+ end
54
+ end
55
+
56
+ describe '.validate_password' do
57
+ let!(:password) { generate_one_time_password Motorurl.configuration.shared_secret }
58
+
59
+ it 'returns false when passed nil' do
60
+ expect(described_class.validate_password nil).to be_false
61
+ end
62
+
63
+ it 'returns true when password is valid' do
64
+ expect(described_class.validate_password password).to be_true
65
+ end
66
+
67
+ it 'returns false when password has expired' do
68
+ Timecop.freeze(Time.at(Time.now + 60.seconds)) do
69
+ expect(described_class.validate_password password).to be_false
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ #
4
+ # See https://github.com/rspec/rspec-rails/issues/146
5
+ # Proper technique is specify entire URL, as in...
6
+ # { :get => "http://test.example.com" }
7
+ # .should route_to(:controller => :users, :action => :profile, :subdomain => 'test')
8
+
9
+ describe 'Engine Routes' do
10
+ routes { Motorurl::Engine.routes }
11
+
12
+ it 'routes to engine create' do
13
+ expect({ post: '/sensor' })
14
+ .to route_to(controller: 'motorurl/sensors', action: 'create')
15
+ end
16
+
17
+ it 'routes to engine show' do
18
+ expect({ get: '/sensor' })
19
+ .to route_to(controller: 'motorurl/sensors', action: 'show')
20
+ end
21
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
2
+
3
+ require 'bogus/rspec'
4
+ require 'debugger'
5
+ require 'factory_girl_rails'
6
+ require 'letters'
7
+ require 'rotp'
8
+ require 'rspec/autorun'
9
+ require 'rspec/rails'
10
+ require 'timecop'
11
+ require 'webmock/rspec'
12
+
13
+ Rails.backtrace_cleaner.remove_silencers!
14
+
15
+ # Load support files
16
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
17
+
18
+ Bogus.configure do |config|
19
+ config.search_modules << Motorurl
20
+ end
21
+
22
+ RSpec.configure do |config|
23
+ config.after(:all) do
24
+ Motorurl.configure do |c|
25
+ @saved_configuration.each { |k, v| c.send("#{k}=", v) }
26
+ end
27
+ end
28
+
29
+ config.before(:all) do
30
+ @saved_configuration = Motorurl.configuration.dup
31
+
32
+ Motorurl.configure do |c|
33
+ c.callback_url = 'http://www.dummy.com'
34
+ c.canonical_name = 'test_job'
35
+ c.friendly_name = 'Test Sensor'
36
+ c.price = 10
37
+ c.sensor_job_class = 'SpecJob'
38
+ c.shared_secret = 'secretkey'
39
+ c.spiderman = 'http://localhost:8080' # The URL of Spiderman
40
+ c.version = '0.0.1' # The version of the sensor
41
+ end
42
+ end
43
+
44
+ config.formatter = 'documentation'
45
+ config.include FactoryGirl::Syntax::Methods
46
+ config.infer_base_class_for_anonymous_controllers = false
47
+ config.mock_with :rspec
48
+ config.order = 'random'
49
+ config.use_transactional_fixtures = true
50
+ end
51
+
52
+ Timecop.safe_mode = true