gmaps4rails 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/gmaps4rails/gmaps_controller.rb +1 -1
- data/lib/acts_as_gmappable/base.rb +9 -10
- data/lib/application_helper.rb +5 -0
- data/lib/array.rb +1 -1
- data/public/javascripts/gmaps4rails.js +15 -2
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/users_controller.rb +42 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/users_helper.rb +2 -0
- data/test/dummy/app/models/user.rb +8 -0
- data/test/dummy/config/application.rb +42 -0
- data/test/dummy/config/boot.rb +6 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/db/migrate/20110306182914_create_users.rb +21 -0
- data/test/dummy/db/schema.rb +30 -0
- data/test/dummy/db/seeds.rb +7 -0
- data/test/dummy/spec/base/base_spec.rb +15 -0
- data/test/dummy/spec/controllers/users_controller_spec.rb +57 -0
- data/test/dummy/spec/models/user_spec.rb +168 -0
- data/test/dummy/spec/spec_helper.rb +27 -0
- data/test/dummy/test/performance/browsing_test.rb +9 -0
- data/test/dummy/test/test_helper.rb +13 -0
- metadata +58 -10
- data/test/test_helper.rb +0 -56
- data/test/unit/gmaps4rails_widget_test.rb +0 -11
@@ -10,7 +10,7 @@ module Gmaps4rails
|
|
10
10
|
# The split returns the array [scope_name, arg1, arg2, ...]
|
11
11
|
if @scope && !@scope.empty? && @model.gmaps4rails_trusted_scopes.include?(@scope.split(/\(| *, *|\)/)[0])
|
12
12
|
object = eval("#{@model}.#{@scope}") # Cannot use send with lambda scope
|
13
|
-
|
13
|
+
# because the arguments have to be separated
|
14
14
|
@objects = object.to_gmaps4rails
|
15
15
|
else
|
16
16
|
@objects = @model.all.to_gmaps4rails
|
@@ -44,7 +44,7 @@ module Gmaps4rails
|
|
44
44
|
end
|
45
45
|
return array
|
46
46
|
else #status != OK
|
47
|
-
raise Gmaps4rails::GeocodeStatus, "The
|
47
|
+
raise Gmaps4rails::GeocodeStatus, "The address you passed seems invalid, status was: #{parse["status"]}.
|
48
48
|
Request was: #{request}"
|
49
49
|
end #end parse status
|
50
50
|
|
@@ -73,12 +73,12 @@ module Gmaps4rails
|
|
73
73
|
|
74
74
|
define_method "gmaps4rails_options" do
|
75
75
|
{
|
76
|
-
:lat_column
|
77
|
-
:lng_column
|
78
|
-
:check_process
|
79
|
-
:checker
|
80
|
-
:msg
|
81
|
-
:validation
|
76
|
+
:lat_column => args[:lat] || "latitude",
|
77
|
+
:lng_column => args[:lng] || "longitude",
|
78
|
+
:check_process => args[:check_process] || true,
|
79
|
+
:checker => args[:checker] || "gmaps",
|
80
|
+
:msg => args[:msg] || "Address invalid",
|
81
|
+
:validation => args[:validation] || true
|
82
82
|
#TODO: address as a proc?
|
83
83
|
}
|
84
84
|
end
|
@@ -103,7 +103,7 @@ module Gmaps4rails
|
|
103
103
|
else #if no exception
|
104
104
|
self[gmaps4rails_options[:lng_column]] = coordinates.first[:lng]
|
105
105
|
self[gmaps4rails_options[:lat_column]] = coordinates.first[:lat]
|
106
|
-
if gmaps4rails_options[:check_process]
|
106
|
+
if gmaps4rails_options[:check_process] == true
|
107
107
|
self[gmaps4rails_options[:checker]] = true
|
108
108
|
end
|
109
109
|
end
|
@@ -123,8 +123,7 @@ module Gmaps4rails
|
|
123
123
|
|
124
124
|
def to_gmaps4rails
|
125
125
|
json = "["
|
126
|
-
json += Gmaps4rails.create_json(self).to_s
|
127
|
-
json.chop! #removes the extra comma
|
126
|
+
json += Gmaps4rails.create_json(self).to_s.chop #removes the extra comma
|
128
127
|
json += "]"
|
129
128
|
end
|
130
129
|
|
data/lib/application_helper.rb
CHANGED
@@ -4,4 +4,9 @@ module ApplicationHelper
|
|
4
4
|
render :partial => 'gmaps4rails/gmaps4rails', :locals => { :builder => builder, :options => options }
|
5
5
|
end
|
6
6
|
|
7
|
+
def gmaps4rails(builder, options = {})
|
8
|
+
options.merge!({ "processing" => 'json' })
|
9
|
+
render :partial => 'gmaps4rails/gmaps4rails', :locals => { :builder => builder, :options => options }
|
10
|
+
end
|
11
|
+
|
7
12
|
end
|
data/lib/array.rb
CHANGED
@@ -9,6 +9,7 @@ var Gmaps4Rails = {
|
|
9
9
|
map_center_latitude : 0,
|
10
10
|
map_center_longitude : 0,
|
11
11
|
map_zoom : 1,
|
12
|
+
auto_adjust : false,
|
12
13
|
base_url : '/gmaps',
|
13
14
|
rails_model : null,
|
14
15
|
model_scope : null,
|
@@ -20,6 +21,7 @@ var Gmaps4Rails = {
|
|
20
21
|
do_clustering: true,
|
21
22
|
clusterer_gridSize: 50,
|
22
23
|
clusterer_maxZoom: 10,
|
24
|
+
bounds: null,
|
23
25
|
//Triggers the creation of the map.
|
24
26
|
//Two options:
|
25
27
|
// 1- processing == "rails_model" && builder = model_name
|
@@ -40,6 +42,9 @@ var Gmaps4Rails = {
|
|
40
42
|
this.locations = builder;
|
41
43
|
this.setup_Markers();
|
42
44
|
}
|
45
|
+
if (this.auto_adjust) {
|
46
|
+
this.map.fitBounds(this.bounds);
|
47
|
+
}
|
43
48
|
},
|
44
49
|
|
45
50
|
//resets the map, removes all markers
|
@@ -68,7 +73,9 @@ var Gmaps4Rails = {
|
|
68
73
|
setup_Markers: function () {
|
69
74
|
//variable used for Marker Clusterer
|
70
75
|
var markers = [];
|
71
|
-
|
76
|
+
//variable used for Auto-adjust
|
77
|
+
this.bounds = new google.maps.LatLngBounds();
|
78
|
+
|
72
79
|
//resests Clusterer if needed
|
73
80
|
if (this.markerClusterer) {
|
74
81
|
this.markerClusterer.clearMarkers();
|
@@ -94,7 +101,13 @@ var Gmaps4Rails = {
|
|
94
101
|
//save the marker again in a list for the clusterer
|
95
102
|
markers.push(ThisMarker);
|
96
103
|
//add click listener
|
97
|
-
google.maps.event.addListener(Gmaps4Rails.locations[i].marker_object, 'click', function() { if (Gmaps4Rails.info_window!=null) {Gmaps4Rails.info_window.close();}; Gmaps4Rails.getInfoWindow(this);});
|
104
|
+
google.maps.event.addListener(Gmaps4Rails.locations[i].marker_object, 'click', function() { if (Gmaps4Rails.info_window!=null) {Gmaps4Rails.info_window.close();}; Gmaps4Rails.getInfoWindow(this);});
|
105
|
+
|
106
|
+
//extending bounds, ref: http://unicornless.com/code/google-maps-v3-auto-zoom-and-auto-center
|
107
|
+
if (this.auto_adjust) {
|
108
|
+
var ll = new google.maps.LatLng(this.locations[i].latitude, this.locations[i].longitude);
|
109
|
+
this.bounds.extend(ll);
|
110
|
+
}
|
98
111
|
}
|
99
112
|
this.setup_Clusterer(markers);
|
100
113
|
},
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
def index
|
3
|
+
@users = User.all
|
4
|
+
@json = User.all.to_gmaps4rails
|
5
|
+
end
|
6
|
+
|
7
|
+
def show
|
8
|
+
@user = User.find(params[:id])
|
9
|
+
end
|
10
|
+
|
11
|
+
def new
|
12
|
+
@user = User.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
@user = User.new(params[:user])
|
17
|
+
if @user.save
|
18
|
+
redirect_to @user, :notice => "Successfully created user."
|
19
|
+
else
|
20
|
+
render :action => 'new'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
@user = User.find(params[:id])
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
@user = User.find(params[:id])
|
30
|
+
if @user.update_attributes(params[:user])
|
31
|
+
redirect_to @user, :notice => "Successfully updated user."
|
32
|
+
else
|
33
|
+
render :action => 'edit'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
@user = User.find(params[:id])
|
39
|
+
@user.destroy
|
40
|
+
redirect_to users_url, :notice => "Successfully destroyed user."
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# If you have a Gemfile, require the gems listed there, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
8
|
+
|
9
|
+
module Dummy
|
10
|
+
class Application < Rails::Application
|
11
|
+
# Settings in config/environments/* take precedence over those specified here.
|
12
|
+
# Application configuration should go into files in config/initializers
|
13
|
+
# -- all .rb files in that directory are automatically loaded.
|
14
|
+
|
15
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
16
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
17
|
+
|
18
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
19
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
20
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
21
|
+
|
22
|
+
# Activate observers that should always be running.
|
23
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
24
|
+
|
25
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
26
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
27
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
28
|
+
|
29
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
30
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
31
|
+
# config.i18n.default_locale = :de
|
32
|
+
|
33
|
+
# JavaScript files you want as :defaults (application.js is always included).
|
34
|
+
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
35
|
+
|
36
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
37
|
+
config.encoding = "utf-8"
|
38
|
+
|
39
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
40
|
+
config.filter_parameters += [:password]
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -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 = '2a919a7d43f61da3daa4f6ea302b6c57ecc7ba76129e9ab4d8021e5588c927e6f52027e10bbc5a82cc0715002c5455e36461e8c785b47a5c2e1db59dcf53c6e1'
|
@@ -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,21 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :users do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :address
|
6
|
+
t.text :description
|
7
|
+
t.string :picture
|
8
|
+
t.float :lat_test
|
9
|
+
t.float :long_test
|
10
|
+
t.float :latitude
|
11
|
+
t.float :longitude
|
12
|
+
t.boolean :gmaps
|
13
|
+
t.boolean :bool_test
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
drop_table :users
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended to check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(:version => 20110306182914) do
|
14
|
+
|
15
|
+
create_table "users", :force => true do |t|
|
16
|
+
t.string "name"
|
17
|
+
t.string "address"
|
18
|
+
t.text "description"
|
19
|
+
t.string "picture"
|
20
|
+
t.float "lat_test"
|
21
|
+
t.float "long_test"
|
22
|
+
t.float "latitude"
|
23
|
+
t.float "longitude"
|
24
|
+
t.boolean "gmaps"
|
25
|
+
t.boolean "bool_test"
|
26
|
+
t.datetime "created_at"
|
27
|
+
t.datetime "updated_at"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Basic Functions" do
|
4
|
+
#Gmaps4rails.geocode(address)
|
5
|
+
it "should geocode properly an address" do
|
6
|
+
Gmaps4rails.geocode("alaska").should == [{:lat=>63.588753, :lng=>-154.4930619, :matched_address=>"Alaska, USA"}]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should raise an error when error invalid" do
|
10
|
+
lambda { Gmaps4rails.geocode("home")}.should raise_error Gmaps4rails::GeocodeStatus
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should raise an error when net connection failed" #TODO: Damn, I don't know how to test that!
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe UsersController do
|
4
|
+
fixtures :all
|
5
|
+
render_views
|
6
|
+
|
7
|
+
it "index action should render index template" do
|
8
|
+
get :index
|
9
|
+
response.should render_template(:index)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "show action should render show template" do
|
13
|
+
get :show, :id => User.first
|
14
|
+
response.should render_template(:show)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "new action should render new template" do
|
18
|
+
get :new
|
19
|
+
response.should render_template(:new)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "create action should render new template when model is invalid" do
|
23
|
+
User.any_instance.stubs(:valid?).returns(false)
|
24
|
+
post :create
|
25
|
+
response.should render_template(:new)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "create action should redirect when model is valid" do
|
29
|
+
User.any_instance.stubs(:valid?).returns(true)
|
30
|
+
post :create
|
31
|
+
response.should redirect_to(user_url(assigns[:user]))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "edit action should render edit template" do
|
35
|
+
get :edit, :id => User.first
|
36
|
+
response.should render_template(:edit)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "update action should render edit template when model is invalid" do
|
40
|
+
User.any_instance.stubs(:valid?).returns(false)
|
41
|
+
put :update, :id => User.first
|
42
|
+
response.should render_template(:edit)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "update action should redirect when model is valid" do
|
46
|
+
User.any_instance.stubs(:valid?).returns(true)
|
47
|
+
put :update, :id => User.first
|
48
|
+
response.should redirect_to(user_url(assigns[:user]))
|
49
|
+
end
|
50
|
+
|
51
|
+
it "destroy action should destroy model and redirect to index action" do
|
52
|
+
user = User.first
|
53
|
+
delete :destroy, :id => user
|
54
|
+
response.should redirect_to(users_url)
|
55
|
+
User.exists?(user.id).should be_false
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Acts as gmappable" do
|
4
|
+
|
5
|
+
describe "standard configuration, valid user" do
|
6
|
+
before(:each) do
|
7
|
+
@user = User.create!(:name => "me", :address => "Toulon, France" )
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have a geocoded position" do
|
11
|
+
@user.latitude.should == 43.1251606
|
12
|
+
@user.longitude.should == 5.9311119
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should set boolean to true once user is created" do
|
16
|
+
@user.gmaps.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should render a valid json from an array of ojects" do
|
20
|
+
@user2 = User.create!(:name => "me", :address => "Paris, France" )
|
21
|
+
User.all.to_gmaps4rails.should == "[{\"description\": \"\",\n\"longitude\": \"5.9311119\",\n\"latitude\": \"43.1251606\",\n\"picture\": \"\",\n\"width\": \"\",\n\"height\": \"\"\n} ,{\"description\": \"\",\n\"longitude\": \"2.3509871\",\n\"latitude\": \"48.8566667\",\n\"picture\": \"\",\n\"width\": \"\",\n\"height\": \"\"\n} ]"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should render a valid json from a single object" do
|
25
|
+
@user.to_gmaps4rails.should == "[{\"description\": \"\",\n\"longitude\": \"5.9311119\",\n\"latitude\": \"43.1251606\",\n\"picture\": \"\",\n\"width\": \"\",\n\"height\": \"\"\n} ]"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
describe "standard configuration, invalid address" do
|
32
|
+
before(:each) do
|
33
|
+
@user = User.new(:name => "me", :address => "home" )
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should raise an error if validation option is turned on and address incorrect" do
|
37
|
+
@user.should_not be_valid, "Address invalid"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not set boolean to true when address update fails" do
|
41
|
+
@user["gmaps"].should_not == true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
describe "model customization" do
|
47
|
+
it "should render a valid json even if there is no instance in the db" do
|
48
|
+
User.all.to_gmaps4rails.should == "[]"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should display the proper error message when address is invalid" do
|
52
|
+
User.class_eval do
|
53
|
+
def gmaps4rails_options
|
54
|
+
{
|
55
|
+
:lat_column => "latitude",
|
56
|
+
:lng_column => "longitude",
|
57
|
+
:check_process => true,
|
58
|
+
:checker => "gmaps",
|
59
|
+
:msg => "Custom Address invalid",
|
60
|
+
:validation => true
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
@user = User.new(:name => "me", :address => "home" )
|
65
|
+
@user.should_not be_valid, "Custom Address invalid"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not raise an error if validation option is turned off" do
|
69
|
+
User.class_eval do
|
70
|
+
def gmaps4rails_options
|
71
|
+
{
|
72
|
+
:lat_column => "latitude",
|
73
|
+
:lng_column => "longitude",
|
74
|
+
:check_process => true,
|
75
|
+
:checker => "gmaps",
|
76
|
+
:msg => "Address invalid",
|
77
|
+
:validation => false
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
@user = User.new(:name => "me", :address => "home" )
|
82
|
+
@user.should be_valid
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should save longitude and latitude to the customized columns" do
|
86
|
+
User.class_eval do
|
87
|
+
def gmaps4rails_options
|
88
|
+
{
|
89
|
+
:lat_column => "lat_test",
|
90
|
+
:lng_column => "long_test",
|
91
|
+
:check_process => true,
|
92
|
+
:checker => "gmaps",
|
93
|
+
:msg => "Address invalid",
|
94
|
+
:validation => true
|
95
|
+
}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
@user = User.create!(:name => "me", :address => "Toulon, France" )
|
99
|
+
@user.lat_test.should == 43.1251606
|
100
|
+
@user.long_test.should == 5.9311119
|
101
|
+
@user.longitude.should == nil
|
102
|
+
@user.latitude.should == nil
|
103
|
+
@user.to_gmaps4rails.should == "[{\"description\": \"\",\n\"longitude\": \"5.9311119\",\n\"latitude\": \"43.1251606\",\n\"picture\": \"\",\n\"width\": \"\",\n\"height\": \"\"\n} ]"
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should not save the boolean if check_process is false" do
|
107
|
+
User.class_eval do
|
108
|
+
def gmaps4rails_options
|
109
|
+
{
|
110
|
+
:lat_column => "lat_test",
|
111
|
+
:lng_column => "long_test",
|
112
|
+
:check_process => false,
|
113
|
+
:checker => "gmaps",
|
114
|
+
:msg => "Address invalid",
|
115
|
+
:validation => true
|
116
|
+
}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
@user = User.create!(:name => "me", :address => "Toulon, France" )
|
120
|
+
@user.gmaps.should == nil
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should save to the proper boolean checker set in checker" do
|
124
|
+
User.class_eval do
|
125
|
+
def gmaps4rails_options
|
126
|
+
{
|
127
|
+
:lat_column => "lat_test",
|
128
|
+
:lng_column => "long_test",
|
129
|
+
:check_process => true,
|
130
|
+
:checker => "bool_test",
|
131
|
+
:msg => "Address invalid",
|
132
|
+
:validation => true
|
133
|
+
}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
@user = User.create!(:name => "me", :address => "Toulon, France" )
|
137
|
+
@user.gmaps.should == nil
|
138
|
+
@user.bool_test.should == true
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should take into account the description provided in the model" do
|
142
|
+
User.class_eval do
|
143
|
+
def gmaps4rails_infowindow
|
144
|
+
"My Beautiful Picture: #{picture}"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
@user = User.create!(:name => "me", :address => "Toulon, France", :picture => "http://www.blankdots.com/img/github-32x32.png")
|
148
|
+
@user.to_gmaps4rails.should == "[{\"description\": \"My Beautiful Picture: http://www.blankdots.com/img/github-32x32.png\",\n\"longitude\": \"5.9311119\",\n\"latitude\": \"43.1251606\",\n\"picture\": \"\",\n\"width\": \"\",\n\"height\": \"\"\n} ]"
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should take into account the picture provided in the model" do
|
152
|
+
User.class_eval do
|
153
|
+
def gmaps4rails_infowindow
|
154
|
+
#to reset the former declaration
|
155
|
+
end
|
156
|
+
def gmaps4rails_marker_picture
|
157
|
+
{
|
158
|
+
"picture" => "http://www.blankdots.com/img/github-32x32.png",
|
159
|
+
"width" => "32",
|
160
|
+
"height" => "32"
|
161
|
+
}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
@user = User.create!(:name => "me", :address => "Toulon, France")
|
165
|
+
@user.to_gmaps4rails.should == "[{\"description\": \"\",\n\"longitude\": \"5.9311119\",\n\"latitude\": \"43.1251606\",\n\"picture\": \"http://www.blankdots.com/img/github-32x32.png\",\n\"width\": \"32\",\n\"height\": \"32\"\n} ]"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require File.expand_path("../../config/environment", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
|
6
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
7
|
+
# in spec/support/ and its subdirectories.
|
8
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
# == Mock Framework
|
12
|
+
#
|
13
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
14
|
+
#
|
15
|
+
# config.mock_with :mocha
|
16
|
+
# config.mock_with :flexmock
|
17
|
+
# config.mock_with :rr
|
18
|
+
config.mock_with :rspec
|
19
|
+
|
20
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
21
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
22
|
+
|
23
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
24
|
+
# examples within a transaction, remove the following line or assign false
|
25
|
+
# instead of true.
|
26
|
+
config.use_transactional_fixtures = true
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
+
#
|
8
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
+
# -- they do not yet inherit this setting
|
10
|
+
fixtures :all
|
11
|
+
|
12
|
+
# Add more helper methods to be used by all tests here...
|
13
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmaps4rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Benjamin Roth
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-03-07 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -61,8 +61,32 @@ files:
|
|
61
61
|
- public/javascripts/old.js
|
62
62
|
- public/stylesheets/gmaps4rails.css
|
63
63
|
- README.rdoc
|
64
|
-
- test/
|
65
|
-
- test/
|
64
|
+
- test/dummy/app/controllers/application_controller.rb
|
65
|
+
- test/dummy/app/controllers/users_controller.rb
|
66
|
+
- test/dummy/app/helpers/application_helper.rb
|
67
|
+
- test/dummy/app/helpers/users_helper.rb
|
68
|
+
- test/dummy/app/models/user.rb
|
69
|
+
- test/dummy/config/application.rb
|
70
|
+
- test/dummy/config/boot.rb
|
71
|
+
- test/dummy/config/environment.rb
|
72
|
+
- test/dummy/config/environments/development.rb
|
73
|
+
- test/dummy/config/environments/production.rb
|
74
|
+
- test/dummy/config/environments/test.rb
|
75
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
76
|
+
- test/dummy/config/initializers/inflections.rb
|
77
|
+
- test/dummy/config/initializers/mime_types.rb
|
78
|
+
- test/dummy/config/initializers/secret_token.rb
|
79
|
+
- test/dummy/config/initializers/session_store.rb
|
80
|
+
- test/dummy/config/routes.rb
|
81
|
+
- test/dummy/db/migrate/20110306182914_create_users.rb
|
82
|
+
- test/dummy/db/schema.rb
|
83
|
+
- test/dummy/db/seeds.rb
|
84
|
+
- test/dummy/spec/base/base_spec.rb
|
85
|
+
- test/dummy/spec/controllers/users_controller_spec.rb
|
86
|
+
- test/dummy/spec/models/user_spec.rb
|
87
|
+
- test/dummy/spec/spec_helper.rb
|
88
|
+
- test/dummy/test/performance/browsing_test.rb
|
89
|
+
- test/dummy/test/test_helper.rb
|
66
90
|
has_rdoc: true
|
67
91
|
homepage: http://github.com/apneadiving/Google-Maps-for-Rails
|
68
92
|
licenses: []
|
@@ -93,10 +117,34 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
117
|
requirements: []
|
94
118
|
|
95
119
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.
|
120
|
+
rubygems_version: 1.3.7
|
97
121
|
signing_key:
|
98
122
|
specification_version: 3
|
99
123
|
summary: Enables easy display of items (taken from a Rails 3 model) on a Google Map. Uses Javascript API V3.
|
100
124
|
test_files:
|
101
|
-
- test/
|
102
|
-
- test/
|
125
|
+
- test/dummy/app/controllers/application_controller.rb
|
126
|
+
- test/dummy/app/controllers/users_controller.rb
|
127
|
+
- test/dummy/app/helpers/application_helper.rb
|
128
|
+
- test/dummy/app/helpers/users_helper.rb
|
129
|
+
- test/dummy/app/models/user.rb
|
130
|
+
- test/dummy/config/application.rb
|
131
|
+
- test/dummy/config/boot.rb
|
132
|
+
- test/dummy/config/environment.rb
|
133
|
+
- test/dummy/config/environments/development.rb
|
134
|
+
- test/dummy/config/environments/production.rb
|
135
|
+
- test/dummy/config/environments/test.rb
|
136
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
137
|
+
- test/dummy/config/initializers/inflections.rb
|
138
|
+
- test/dummy/config/initializers/mime_types.rb
|
139
|
+
- test/dummy/config/initializers/secret_token.rb
|
140
|
+
- test/dummy/config/initializers/session_store.rb
|
141
|
+
- test/dummy/config/routes.rb
|
142
|
+
- test/dummy/db/migrate/20110306182914_create_users.rb
|
143
|
+
- test/dummy/db/schema.rb
|
144
|
+
- test/dummy/db/seeds.rb
|
145
|
+
- test/dummy/spec/base/base_spec.rb
|
146
|
+
- test/dummy/spec/controllers/users_controller_spec.rb
|
147
|
+
- test/dummy/spec/models/user_spec.rb
|
148
|
+
- test/dummy/spec/spec_helper.rb
|
149
|
+
- test/dummy/test/performance/browsing_test.rb
|
150
|
+
- test/dummy/test/test_helper.rb
|
data/test/test_helper.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'rubygems'
|
5
|
-
require 'yaml'
|
6
|
-
require 'active_record'
|
7
|
-
require 'mysql'
|
8
|
-
|
9
|
-
require 'app/models/gmaps4rails/widget.rb'
|
10
|
-
|
11
|
-
def gmaps4rails_widget( fixture_name )
|
12
|
-
id = @@fixtures['gmaps4rails_widget'][ fixture_name.to_s ][ 'id' ]
|
13
|
-
gmaps4rails::Widget.find( id )
|
14
|
-
end
|
15
|
-
|
16
|
-
def load_schema
|
17
|
-
config = YAML::load( IO.read( File.dirname(__FILE__) + '/database.yml') )
|
18
|
-
|
19
|
-
# Manually initialize the database
|
20
|
-
conn = Mysql.real_connect( config['mysql']['host'], config['mysql']['username'], config['mysql']['password'] )
|
21
|
-
conn.query( "CREATE DATABASE IF NOT EXISTS #{config['mysql']['database']}" )
|
22
|
-
|
23
|
-
ActiveRecord::Base.establish_connection( config['mysql'] )
|
24
|
-
ActiveRecord::Base.connection()
|
25
|
-
|
26
|
-
load(File.dirname(__FILE__) + "/../" +
|
27
|
-
"lib/rails/generators/gmaps4rails/templates/schema.rb")
|
28
|
-
|
29
|
-
@@fixtures = {}
|
30
|
-
|
31
|
-
load_fixture( 'gmaps4rails_widget' )
|
32
|
-
end
|
33
|
-
|
34
|
-
def load_fixture( table )
|
35
|
-
@@fixtures[ table ] = {}
|
36
|
-
fixture = YAML::load( IO.read( File.dirname(__FILE__) + "/fixtures/#{table}.yml") )
|
37
|
-
@@fixtures[ table ] = fixture
|
38
|
-
|
39
|
-
klass = class_eval table.titleize.gsub(/ /, '::')
|
40
|
-
|
41
|
-
fixture.each do |record_name, record|
|
42
|
-
record.each do |column, value|
|
43
|
-
if ( match = column.match(/(.*)_id/) )
|
44
|
-
fixture_reference = "gmaps4rails_" + match[1].pluralize
|
45
|
-
if value.is_a? Symbol
|
46
|
-
r = class_eval "#{fixture_reference}( '#{value}' )"
|
47
|
-
record[ column ] = r.id
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
r = klass.create( record )
|
53
|
-
@@fixtures[ table ][ record_name ][ 'id' ] = r.id
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|