neverland 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+ *.swp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in neverland.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Matthew Horan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ module Neverland
2
+ class Engine < Rails::Engine
3
+ initializer 'neverland.static_assets' do |app|
4
+ app.middleware.insert_before('ActionDispatch::Static', 'ActionDispatch::Static', "#{root}/public")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ require 'nokogiri'
2
+
3
+ module Neverland
4
+ class Middleware
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ cookies = Rack::Request.new(env).cookies
11
+ latitude = cookies['mock_latitude']
12
+ longitude = cookies['mock_longitude']
13
+
14
+ status, headers, response = @app.call(env)
15
+
16
+ case response
17
+ when ActionDispatch::Response
18
+ document = Nokogiri::HTML(response.body)
19
+ head = document.at('head')
20
+
21
+ script = Nokogiri::XML::Node.new('script', document)
22
+ script['type'] = 'text/javascript'
23
+ script['src'] = '/javascripts/neverland.js'
24
+ head << script
25
+
26
+ if latitude.present? && longitude.present?
27
+ script = Nokogiri::XML::Node.new('script', document)
28
+ script['type'] = 'text/javascript'
29
+ script.inner_html = <<-SCRIPT
30
+ Neverland.setLatitude(#{latitude})
31
+ Neverland.setLongitude(#{longitude})
32
+ SCRIPT
33
+ head << script
34
+ end
35
+
36
+ response.body = document.to_s
37
+ end
38
+
39
+ [status, headers, response]
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Neverland
2
+ VERSION = "0.0.2"
3
+ end
data/lib/neverland.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "neverland/version"
2
+ require 'neverland/middleware'
3
+ require 'neverland/engine'
4
+
5
+ module Neverland
6
+ end
data/neverland.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "neverland/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "neverland"
7
+ s.version = Neverland::VERSION
8
+ s.authors = ["Matthew Horan"]
9
+ s.email = ["matthew.horan@livestream.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Mock location provider for navigator.geolocation}
12
+ s.description = %q{Ever need to test geolocation in your Rails app? This gem makes it easy.}
13
+
14
+ s.rubyforge_project = "neverland"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'nokogiri'
22
+
23
+ # specify any dependencies here; for example:
24
+ s.add_development_dependency "rspec-rails"
25
+ s.add_development_dependency "tzinfo"
26
+ s.add_development_dependency "capybara"
27
+ s.add_development_dependency "jquery-rails"
28
+ end
@@ -0,0 +1,32 @@
1
+ // http://dev.w3.org/geo/api/spec-source.html
2
+
3
+ navigator.geolocation.getCurrentPosition = function(success, error) {
4
+ success({coords: Neverland.getCoords(), timestamp: Date.now()});
5
+ }
6
+
7
+ var Neverland = new function() {
8
+ var _latitude = 42.31283;
9
+ var _longitude = -71.114287;
10
+
11
+ return {
12
+ getCoords: function () {
13
+ return {
14
+ latitude: _latitude,
15
+ longitude: _longitude,
16
+ altitude: null,
17
+ accuracy: 33,
18
+ altitudeAccuracy: null,
19
+ heading: null,
20
+ speed: null
21
+ };
22
+ },
23
+
24
+ setLatitude: function(latitude) {
25
+ _latitude = latitude;
26
+ },
27
+
28
+ setLongitude: function(longitude) {
29
+ _longitude = longitude;
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,2 @@
1
+ log/*
2
+ tmp/*
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ class TestController < ApplicationController
2
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,9 @@
1
+ <div>Latitude: <span id="latitude"></span></div>
2
+ <div>Longitude: <span id="longitude"><span></div>
3
+
4
+ <%= javascript_tag do %>
5
+ navigator.geolocation.getCurrentPosition(function(success) {
6
+ $('#latitude').text(success.coords.latitude);
7
+ $('#longitude').text(success.coords.longitude);
8
+ });
9
+ <% end %>
@@ -0,0 +1,43 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require 'sprockets/railtie'
5
+ require 'jquery/rails'
6
+
7
+ Bundler.require
8
+ require "neverland"
9
+
10
+ module Dummy
11
+ class Application < Rails::Application
12
+ # Configure the default encoding used in templates for Ruby 1.9.
13
+ config.encoding = "utf-8"
14
+
15
+ # Configure sensitive parameters which will be filtered from the log file.
16
+ config.filter_parameters += [:password]
17
+
18
+ # Enable the asset pipeline
19
+ config.assets.enabled = true
20
+
21
+ # Version of your assets, change this if you want to expire all your assets
22
+ config.assets.version = '1.0'
23
+
24
+ # Log error messages when you accidentally call methods on nil
25
+ config.whiny_nils = true
26
+
27
+ # Show full error reports and disable caching
28
+ config.consider_all_requests_local = true
29
+ config.action_controller.perform_caching = false
30
+
31
+ # Raise exceptions instead of rendering exception templates
32
+ config.action_dispatch.show_exceptions = false
33
+
34
+ # Disable request forgery protection in test environment
35
+ config.action_controller.allow_forgery_protection = false
36
+
37
+ # Print deprecation notices to the stderr
38
+ config.active_support.deprecation = :stderr
39
+
40
+ config.middleware.use Neverland::Middleware
41
+ end
42
+ end
43
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '67f44b464e77d52c9a2e7a295dcf39903e5c73897e08fda94321a3a4fe7a1aff41c4228ba537866373005ff99971eb4a283c67a5dede5916228b5432060b870a'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,3 @@
1
+ Dummy::Application.routes.draw do
2
+ root :to => 'test#index'
3
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'neverland' do
4
+ it 'should insert the mock JavaScript on a successful response' do
5
+ visit '/'
6
+
7
+ page.should have_selector('head script[src="/javascripts/neverland.js"]')
8
+ find('head script[src="/javascripts/neverland.js"]')['type'].should == 'text/javascript'
9
+ end
10
+
11
+ it 'should mock the default coordinates on a successful response', :js => true do
12
+ visit '/'
13
+
14
+ find('#latitude').should have_content('42.31283')
15
+ find('#longitude').should have_content('-71.114287')
16
+ end
17
+
18
+ it 'should mock the provided coordinates on a successful response', :js => true do
19
+ visit '/'
20
+ cookie 'mock_latitude', '37.2630556'
21
+ cookie 'mock_longitude', '-115.7930198'
22
+
23
+ visit '/'
24
+
25
+ find('#latitude').should have_content('37.2630556')
26
+ find('#longitude').should have_content('-115.7930198')
27
+ end
28
+
29
+ it "should not mock on an error response" do
30
+ lambda { visit '/nonexistent' }.should raise_error(ActionController::RoutingError)
31
+
32
+ page.should_not have_selector('head script[src="/javascripts/neverland.js"]')
33
+ end
34
+ end
35
+
36
+ def cookie(name, value)
37
+ Capybara.current_session.driver.browser.manage.add_cookie(:name => name, :value => value)
38
+ end
@@ -0,0 +1,25 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+ require 'capybara/rspec'
7
+
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ # ## Mock Framework
14
+ #
15
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
16
+ #
17
+ # config.mock_with :mocha
18
+ # config.mock_with :flexmock
19
+ # config.mock_with :rr
20
+
21
+ # If true, the base class of anonymous controllers will be inferred
22
+ # automatically. This will be the default behavior in future versions of
23
+ # rspec-rails.
24
+ config.infer_base_class_for_anonymous_controllers = false
25
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neverland
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthew Horan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &16437000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *16437000
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec-rails
27
+ requirement: &16436500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *16436500
36
+ - !ruby/object:Gem::Dependency
37
+ name: tzinfo
38
+ requirement: &16435920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *16435920
47
+ - !ruby/object:Gem::Dependency
48
+ name: capybara
49
+ requirement: &16435360 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *16435360
58
+ - !ruby/object:Gem::Dependency
59
+ name: jquery-rails
60
+ requirement: &16434720 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *16434720
69
+ description: Ever need to test geolocation in your Rails app? This gem makes it easy.
70
+ email:
71
+ - matthew.horan@livestream.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - MIT-LICENSE
80
+ - Rakefile
81
+ - lib/neverland.rb
82
+ - lib/neverland/engine.rb
83
+ - lib/neverland/middleware.rb
84
+ - lib/neverland/version.rb
85
+ - neverland.gemspec
86
+ - public/javascripts/neverland.js
87
+ - spec/dummy/.gitignore
88
+ - spec/dummy/Rakefile
89
+ - spec/dummy/app/assets/javascripts/application.js
90
+ - spec/dummy/app/assets/stylesheets/application.css
91
+ - spec/dummy/app/controllers/application_controller.rb
92
+ - spec/dummy/app/controllers/test_controller.rb
93
+ - spec/dummy/app/helpers/application_helper.rb
94
+ - spec/dummy/app/views/layouts/application.html.erb
95
+ - spec/dummy/app/views/test/index.html.erb
96
+ - spec/dummy/config.ru
97
+ - spec/dummy/config/application.rb
98
+ - spec/dummy/config/boot.rb
99
+ - spec/dummy/config/environment.rb
100
+ - spec/dummy/config/initializers/secret_token.rb
101
+ - spec/dummy/config/initializers/session_store.rb
102
+ - spec/dummy/config/initializers/wrap_parameters.rb
103
+ - spec/dummy/config/routes.rb
104
+ - spec/dummy/public/404.html
105
+ - spec/dummy/public/422.html
106
+ - spec/dummy/public/500.html
107
+ - spec/dummy/public/favicon.ico
108
+ - spec/dummy/script/rails
109
+ - spec/requests/neverland_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: ''
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project: neverland
131
+ rubygems_version: 1.8.15
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: Mock location provider for navigator.geolocation
135
+ test_files: []