Enable asset pipeline
3
Gemfile
|
@ -1,9 +1,12 @@
|
||||||
source 'http://rubygems.org'
|
source 'http://rubygems.org'
|
||||||
|
|
||||||
gem 'rails', '3.1.0.rc1'
|
gem 'rails', '3.1.0.rc1'
|
||||||
|
gem 'coffee-script'
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'geokit'
|
gem 'geokit'
|
||||||
gem 'haml'
|
gem 'haml'
|
||||||
|
gem 'sass'
|
||||||
|
gem 'uglifier'
|
||||||
|
|
||||||
platforms :jruby do
|
platforms :jruby do
|
||||||
gem 'jruby-openssl', '~> 0.7'
|
gem 'jruby-openssl', '~> 0.7'
|
||||||
|
|
13
Gemfile.lock
|
@ -39,12 +39,18 @@ GEM
|
||||||
bcrypt-ruby (2.1.4-java)
|
bcrypt-ruby (2.1.4-java)
|
||||||
bouncy-castle-java (1.5.0146.1)
|
bouncy-castle-java (1.5.0146.1)
|
||||||
builder (3.0.0)
|
builder (3.0.0)
|
||||||
|
coffee-script (2.2.0)
|
||||||
|
coffee-script-source
|
||||||
|
execjs
|
||||||
|
coffee-script-source (1.1.1)
|
||||||
crack (0.1.8)
|
crack (0.1.8)
|
||||||
devise (1.3.4)
|
devise (1.3.4)
|
||||||
bcrypt-ruby (~> 2.1.2)
|
bcrypt-ruby (~> 2.1.2)
|
||||||
orm_adapter (~> 0.0.3)
|
orm_adapter (~> 0.0.3)
|
||||||
warden (~> 1.0.3)
|
warden (~> 1.0.3)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
|
execjs (1.0.0)
|
||||||
|
multi_json (~> 1.0)
|
||||||
geokit (1.6.0)
|
geokit (1.6.0)
|
||||||
haml (3.1.1)
|
haml (3.1.1)
|
||||||
hike (1.0.0)
|
hike (1.0.0)
|
||||||
|
@ -84,6 +90,7 @@ GEM
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
thor (~> 0.14.6)
|
thor (~> 0.14.6)
|
||||||
rake (0.9.0)
|
rake (0.9.0)
|
||||||
|
sass (3.1.1)
|
||||||
simplecov (0.4.2)
|
simplecov (0.4.2)
|
||||||
simplecov-html (~> 0.4.4)
|
simplecov-html (~> 0.4.4)
|
||||||
simplecov-html (0.4.5)
|
simplecov-html (0.4.5)
|
||||||
|
@ -101,6 +108,9 @@ GEM
|
||||||
turn (0.8.2)
|
turn (0.8.2)
|
||||||
ansi (>= 1.2.2)
|
ansi (>= 1.2.2)
|
||||||
tzinfo (0.3.27)
|
tzinfo (0.3.27)
|
||||||
|
uglifier (0.5.4)
|
||||||
|
execjs (>= 0.3.0)
|
||||||
|
multi_json (>= 1.0.2)
|
||||||
warden (1.0.4)
|
warden (1.0.4)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
webmock (1.6.4)
|
webmock (1.6.4)
|
||||||
|
@ -113,15 +123,18 @@ PLATFORMS
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
ZenTest
|
ZenTest
|
||||||
|
coffee-script
|
||||||
devise
|
devise
|
||||||
geokit
|
geokit
|
||||||
haml
|
haml
|
||||||
jruby-openssl (~> 0.7)
|
jruby-openssl (~> 0.7)
|
||||||
pg
|
pg
|
||||||
rails (= 3.1.0.rc1)
|
rails (= 3.1.0.rc1)
|
||||||
|
sass
|
||||||
simplecov
|
simplecov
|
||||||
sqlite3
|
sqlite3
|
||||||
therubyracer-heroku (= 0.8.1.pre3)
|
therubyracer-heroku (= 0.8.1.pre3)
|
||||||
therubyrhino (~> 1.72)
|
therubyrhino (~> 1.72)
|
||||||
turn
|
turn
|
||||||
|
uglifier
|
||||||
webmock
|
webmock
|
||||||
|
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
@ -20,7 +20,7 @@ $(function() {
|
||||||
new google.maps.Point(0, 0),
|
new google.maps.Point(0, 0),
|
||||||
new google.maps.Point(13.0, 18.0)
|
new google.maps.Point(13.0, 18.0)
|
||||||
);
|
);
|
||||||
var shadow = new google.maps.MarkerImage('/images/markers/shadow.png',
|
var shadow = new google.maps.MarkerImage('/assets/markers/shadow.png',
|
||||||
new google.maps.Size(46.0, 37.0),
|
new google.maps.Size(46.0, 37.0),
|
||||||
new google.maps.Point(0, 0),
|
new google.maps.Point(0, 0),
|
||||||
new google.maps.Point(13.0, 18.0)
|
new google.maps.Point(13.0, 18.0)
|
||||||
|
@ -47,7 +47,7 @@ $(function() {
|
||||||
activeMarker = marker;
|
activeMarker = marker;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/hydrant',
|
url: '/info_window',
|
||||||
data: {
|
data: {
|
||||||
'hydrant_id': hydrantId
|
'hydrant_id': hydrantId
|
||||||
},
|
},
|
||||||
|
@ -93,7 +93,7 @@ $(function() {
|
||||||
}
|
}
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
point = new google.maps.LatLng(hydrant.lat, hydrant.lng);
|
point = new google.maps.LatLng(hydrant.lat, hydrant.lng);
|
||||||
color = '/images/markers/' + (hydrant.user_id ? 'green' : 'red') + '.png';
|
color = '/assets/markers/' + (hydrant.user_id ? 'green' : 'red') + '.png';
|
||||||
addMarker(hydrant.id, point, color);
|
addMarker(hydrant.id, point, color);
|
||||||
}, i * 100);
|
}, i * 100);
|
||||||
});
|
});
|
||||||
|
@ -266,7 +266,7 @@ $(function() {
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/hydrant',
|
url: '/info_window',
|
||||||
data: {
|
data: {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
},
|
},
|
||||||
|
@ -318,7 +318,7 @@ $(function() {
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/hydrant',
|
url: '/info_window',
|
||||||
data: {
|
data: {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
},
|
},
|
||||||
|
@ -371,7 +371,7 @@ $(function() {
|
||||||
$(submitButton).attr("disabled", true);
|
$(submitButton).attr("disabled", true);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/hydrant',
|
url: '/hydrants.json',
|
||||||
data: {
|
data: {
|
||||||
'id': $('#hydrant_id').val(),
|
'id': $('#hydrant_id').val(),
|
||||||
'commit': submitButton.val(),
|
'commit': submitButton.val(),
|
||||||
|
@ -396,14 +396,14 @@ $(function() {
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/hydrant',
|
url: '/info_window',
|
||||||
data: {
|
data: {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
||||||
image = new google.maps.MarkerImage('/images/markers/green.png',
|
image = new google.maps.MarkerImage('/assets/markers/green.png',
|
||||||
new google.maps.Size(27.0, 37.0),
|
new google.maps.Size(27.0, 37.0),
|
||||||
new google.maps.Point(0, 0),
|
new google.maps.Point(0, 0),
|
||||||
new google.maps.Point(13.0, 18.0)
|
new google.maps.Point(13.0, 18.0)
|
||||||
|
@ -423,7 +423,7 @@ $(function() {
|
||||||
$(submitButton).attr("disabled", true);
|
$(submitButton).attr("disabled", true);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/hydrant',
|
url: '/hydrants.json',
|
||||||
data: {
|
data: {
|
||||||
'id': $('#hydrant_id').val(),
|
'id': $('#hydrant_id').val(),
|
||||||
'commit': submitButton.val(),
|
'commit': submitButton.val(),
|
||||||
|
@ -440,7 +440,6 @@ $(function() {
|
||||||
$('#loader').show();
|
$('#loader').show();
|
||||||
},
|
},
|
||||||
error: function(data) {
|
error: function(data) {
|
||||||
console.log(data);
|
|
||||||
$('#loader').hide();
|
$('#loader').hide();
|
||||||
$('#info_window').show();
|
$('#info_window').show();
|
||||||
$(submitButton).attr("disabled", false);
|
$(submitButton).attr("disabled", false);
|
||||||
|
@ -448,13 +447,13 @@ $(function() {
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/hydrant',
|
url: '/info_window',
|
||||||
data: {
|
data: {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
||||||
image = new google.maps.MarkerImage('/images/markers/red.png',
|
image = new google.maps.MarkerImage('/assets/markers/red.png',
|
||||||
new google.maps.Size(27.0, 37.0),
|
new google.maps.Size(27.0, 37.0),
|
||||||
new google.maps.Point(0, 0),
|
new google.maps.Point(0, 0),
|
||||||
new google.maps.Point(13.0, 18.0)
|
new google.maps.Point(13.0, 18.0)
|
||||||
|
@ -475,7 +474,7 @@ $(function() {
|
||||||
$(submitButton).attr("disabled", true);
|
$(submitButton).attr("disabled", true);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/hydrant',
|
url: '/hydrants.json',
|
||||||
data: {
|
data: {
|
||||||
'id': $('#hydrant_id').val(),
|
'id': $('#hydrant_id').val(),
|
||||||
'commit': submitButton.val(),
|
'commit': submitButton.val(),
|
||||||
|
@ -500,13 +499,13 @@ $(function() {
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/hydrant',
|
url: '/info_window',
|
||||||
data: {
|
data: {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
||||||
image = new google.maps.MarkerImage('/images/markers/red.png',
|
image = new google.maps.MarkerImage('/assets/markers/red.png',
|
||||||
new google.maps.Size(27.0, 37.0),
|
new google.maps.Size(27.0, 37.0),
|
||||||
new google.maps.Point(0, 0),
|
new google.maps.Point(0, 0),
|
||||||
new google.maps.Point(13.0, 18.0)
|
new google.maps.Point(13.0, 18.0)
|
||||||
|
@ -684,7 +683,7 @@ $(function() {
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/hydrant',
|
url: '/info_window',
|
||||||
data: {
|
data: {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
},
|
},
|
||||||
|
@ -701,7 +700,7 @@ $(function() {
|
||||||
$(submitButton).attr("disabled", true);
|
$(submitButton).attr("disabled", true);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/users/sign_in',
|
url: '/info_window',
|
||||||
data: {
|
data: {
|
||||||
'commit': submitButton.val(),
|
'commit': submitButton.val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
|
@ -728,7 +727,7 @@ $(function() {
|
||||||
$(submitButton).attr("disabled", true);
|
$(submitButton).attr("disabled", true);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/hydrant',
|
url: '/info_window',
|
||||||
data: {
|
data: {
|
||||||
'commit': submitButton.val(),
|
'commit': submitButton.val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
|
@ -1,24 +1,7 @@
|
||||||
class HydrantsController < ApplicationController
|
class HydrantsController < ApplicationController
|
||||||
respond_to :json, :only => [:list, :update]
|
respond_to :json
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@hydrant = Hydrant.find_by_id(params[:hydrant_id])
|
|
||||||
if @hydrant.adopted?
|
|
||||||
if user_signed_in? && current_user.id == @hydrant.user_id
|
|
||||||
render("users/thank_you", :layout => "info_window")
|
|
||||||
else
|
|
||||||
render("users/profile", :layout => "info_window")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if user_signed_in?
|
|
||||||
render("adopt", :layout => "info_window")
|
|
||||||
else
|
|
||||||
render("sessions/new", :layout => "info_window")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def list
|
|
||||||
@hydrants = Hydrant.find_closest(params[:lat], params[:lng], params[:limit] || 50)
|
@hydrants = Hydrant.find_closest(params[:lat], params[:lng], params[:limit] || 50)
|
||||||
unless @hydrants.blank?
|
unless @hydrants.blank?
|
||||||
respond_with @hydrants
|
respond_with @hydrants
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
class InfoWindowController < ApplicationController
|
||||||
|
def index
|
||||||
|
@hydrant = Hydrant.find_by_id(params[:hydrant_id])
|
||||||
|
if @hydrant.adopted?
|
||||||
|
if user_signed_in? && current_user.id == @hydrant.user_id
|
||||||
|
render("users/thank_you")
|
||||||
|
else
|
||||||
|
render("users/profile")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if user_signed_in?
|
||||||
|
render("hydrants/adopt")
|
||||||
|
else
|
||||||
|
render("sessions/new")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,7 +6,7 @@ class UsersController < Devise::RegistrationsController
|
||||||
def update
|
def update
|
||||||
if resource.update_with_password(params[resource_name])
|
if resource.update_with_password(params[resource_name])
|
||||||
sign_in(resource_name, resource, :bypass => true)
|
sign_in(resource_name, resource, :bypass => true)
|
||||||
redirect_to(:controller => "hydrants", :action => "show", :hydrant_id => params[:hydrant_id])
|
redirect_to(:controller => "info_window", :action => "index", :hydrant_id => params[:hydrant_id])
|
||||||
else
|
else
|
||||||
clean_up_passwords(resource)
|
clean_up_passwords(resource)
|
||||||
render(:json => {"errors" => resource.errors}, :status => 500)
|
render(:json => {"errors" => resource.errors}, :status => 500)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= form_for @hydrant, :html => {:id => "abandon_form"} do |f|
|
= form_for :hydrant, :url => hydrants_path, :method => :put, :html => {:id => "abandon_form"} do |f|
|
||||||
= f.hidden_field "id"
|
= f.hidden_field "id"
|
||||||
= f.hidden_field "user_id", :value => ""
|
= f.hidden_field "user_id", :value => ""
|
||||||
= f.hidden_field "name", :value => ""
|
= f.hidden_field "name", :value => ""
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
= form_for :hydrant, :url => '/hydrant', :html => {:id => "back_form", :method => "get"} do |f|
|
= form_for :hydrants, :url => info_window_path, :html => {:id => "back_form", :method => "get"} do |f|
|
||||||
= f.hidden_field "id"
|
= f.hidden_field "id"
|
||||||
= f.submit "Back"
|
= f.submit "Back"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= form_for @hydrant, :html => {:id => "steal_form"} do |f|
|
= form_for :hydrant, :url => hydrants_path, :method => :put, :html => {:id => "steal_form"} do |f|
|
||||||
= f.hidden_field "id"
|
= f.hidden_field "id"
|
||||||
= f.hidden_field "user_id", :value => ""
|
= f.hidden_field "user_id", :value => ""
|
||||||
= f.hidden_field "name", :value => ""
|
= f.hidden_field "name", :value => ""
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= form_for @hydrant, :html => {:id => "adoption_form"} do |f|
|
= form_for :hydrant, :url => hydrants_path, :method => :put, :html => {:id => "adoption_form"} do |f|
|
||||||
%h2
|
%h2
|
||||||
Adopt this Hydrant
|
Adopt this Hydrant
|
||||||
= f.hidden_field "id"
|
= f.hidden_field "id"
|
||||||
|
|
|
@ -51,6 +51,6 @@ module AdoptAHydrant
|
||||||
config.active_record.identity_map = true
|
config.active_record.identity_map = true
|
||||||
|
|
||||||
# Enable the asset pipeline
|
# Enable the asset pipeline
|
||||||
config.assets.enabled = false
|
config.assets.enabled = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,9 +4,9 @@ AdoptAHydrant::Application.routes.draw do
|
||||||
:registrations => 'users',
|
:registrations => 'users',
|
||||||
:sessions => 'sessions',
|
:sessions => 'sessions',
|
||||||
}
|
}
|
||||||
get 'hydrants' => 'hydrants#list'
|
get 'address' => 'addresses#show', :as => 'address'
|
||||||
resource :hydrant
|
get 'info_window' => 'info_window#index', :as => 'info_window'
|
||||||
get 'address' => 'addresses#show'
|
|
||||||
get 'sitemap' => 'sitemaps#index', :as => 'sitemap'
|
get 'sitemap' => 'sitemaps#index', :as => 'sitemap'
|
||||||
|
resource :hydrants
|
||||||
root :to => 'main#index'
|
root :to => 'main#index'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,117 +1,13 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class HydrantsControllerTest < ActionController::TestCase
|
class HydrantsControllerTest < ActionController::TestCase
|
||||||
include Devise::TestHelpers
|
|
||||||
setup do
|
setup do
|
||||||
@hydrant = hydrants(:hydrant_1)
|
@hydrant = hydrants(:hydrant_1)
|
||||||
@user = users(:erik)
|
|
||||||
end
|
|
||||||
|
|
||||||
test 'should thank the user if the user the hydrant is adopted by the user' do
|
|
||||||
sign_in @user
|
|
||||||
@hydrant.user_id = @user.id
|
|
||||||
@hydrant.save!
|
|
||||||
get :show, :hydrant_id => @hydrant.id
|
|
||||||
assert_not_nil assigns :hydrant
|
|
||||||
assert_response :success
|
|
||||||
assert_template 'users/thank_you'
|
|
||||||
assert_select 'h2', 'Thank you for adopting this hydrant!'
|
|
||||||
assert_select 'form#edit_profile_form' do
|
|
||||||
assert_select '[action=?]', '/users/edit'
|
|
||||||
assert_select '[method=?]', 'get'
|
|
||||||
end
|
|
||||||
assert_select 'input[name="commit"]' do
|
|
||||||
assert_select '[type=?]', 'submit'
|
|
||||||
assert_select '[value=?]', 'Edit profile'
|
|
||||||
end
|
|
||||||
assert_select 'form#abandon_form' do
|
|
||||||
assert_select '[action=?]', "/hydrant.#{@hydrant.id}"
|
|
||||||
assert_select '[method=?]', 'post'
|
|
||||||
end
|
|
||||||
assert_select 'input[name="_method"]' do
|
|
||||||
assert_select '[type=?]', 'hidden'
|
|
||||||
assert_select '[value=?]', 'put'
|
|
||||||
end
|
|
||||||
assert_select 'input[name="commit"]' do
|
|
||||||
assert_select '[type=?]', 'submit'
|
|
||||||
assert_select '[value=?]', 'Abandon this hydrant'
|
|
||||||
end
|
|
||||||
assert_select 'form#sign_out_form' do
|
|
||||||
assert_select '[action=?]', '/hydrant'
|
|
||||||
assert_select '[method=?]', 'post'
|
|
||||||
end
|
|
||||||
assert_select 'input[name="commit"]' do
|
|
||||||
assert_select '[type=?]', 'submit'
|
|
||||||
assert_select '[value=?]', 'Sign out'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test 'should show the profile if the hydrant is adopted' do
|
|
||||||
@hydrant.user_id = @user.id
|
|
||||||
@hydrant.save!
|
|
||||||
get :show, :hydrant_id => @hydrant.id
|
|
||||||
assert_not_nil assigns :hydrant
|
|
||||||
assert_response :success
|
|
||||||
assert_template 'users/profile'
|
|
||||||
assert_select 'h2', "This hydrant has been adopted by #{@user.name}"
|
|
||||||
assert_select 'h3', "of #{@user.organization}"
|
|
||||||
end
|
|
||||||
|
|
||||||
test 'should show adoption form if hydrant is not adopted' do
|
|
||||||
sign_in @user
|
|
||||||
get :show, :hydrant_id => @hydrant.id
|
|
||||||
assert_not_nil assigns :hydrant
|
|
||||||
assert_response :success
|
|
||||||
assert_template :adopt
|
|
||||||
assert_select 'h2', 'Adopt this Hydrant'
|
|
||||||
assert_select 'form#adoption_form' do
|
|
||||||
assert_select '[action=?]', "/hydrant.#{@hydrant.id}"
|
|
||||||
assert_select '[method=?]', 'post'
|
|
||||||
end
|
|
||||||
assert_select 'input[name="_method"]' do
|
|
||||||
assert_select '[type=?]', 'hidden'
|
|
||||||
assert_select '[value=?]', 'put'
|
|
||||||
end
|
|
||||||
assert_select 'input[name="commit"]' do
|
|
||||||
assert_select '[type=?]', 'submit'
|
|
||||||
assert_select '[value=?]', 'Adopt!'
|
|
||||||
end
|
|
||||||
assert_select 'form#edit_profile_form' do
|
|
||||||
assert_select '[action=?]', '/users/edit'
|
|
||||||
assert_select '[method=?]', 'get'
|
|
||||||
end
|
|
||||||
assert_select 'input[name="commit"]' do
|
|
||||||
assert_select '[type=?]', 'submit'
|
|
||||||
assert_select '[value=?]', 'Edit profile'
|
|
||||||
end
|
|
||||||
assert_select 'form#sign_out_form' do
|
|
||||||
assert_select '[action=?]', '/hydrant'
|
|
||||||
assert_select '[method=?]', 'post'
|
|
||||||
end
|
|
||||||
assert_select 'input[name="commit"]' do
|
|
||||||
assert_select '[type=?]', 'submit'
|
|
||||||
assert_select '[value=?]', 'Sign out'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test 'should show sign-in form if signed out' do
|
|
||||||
get :show, :hydrant_id => @hydrant.id
|
|
||||||
assert_not_nil assigns :hydrant
|
|
||||||
assert_response :success
|
|
||||||
assert_template 'sessions/new'
|
|
||||||
assert_select 'form#combo_form' do
|
|
||||||
assert_select '[action=?]', '/hydrant'
|
|
||||||
assert_select '[method=?]', 'post'
|
|
||||||
end
|
|
||||||
assert_select 'h2', 'Adopt this Hydrant'
|
|
||||||
assert_select 'input', :count => 15
|
|
||||||
assert_select 'label', :count => 10
|
|
||||||
assert_select 'input[name="commit"]', :count => 3
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# test 'should list hydrants' do
|
# test 'should list hydrants' do
|
||||||
# skip 'Cannot test query on sqlite3 test database'
|
# skip 'Cannot test query on sqlite3 test database'
|
||||||
# get :list, :format => 'json', :lat => 42.358431, :lng => -71.059773
|
# get :show, :format => 'json', :lat => 42.358431, :lng => -71.059773
|
||||||
# assert_not_nil assigns :hydrants
|
# assert_not_nil assigns :hydrants
|
||||||
# assert_response :success
|
# assert_response :success
|
||||||
# end
|
# end
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class InfoWindowControllerTest < ActionController::TestCase
|
||||||
|
include Devise::TestHelpers
|
||||||
|
setup do
|
||||||
|
@hydrant = hydrants(:hydrant_1)
|
||||||
|
@user = users(:erik)
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should thank the user if the user the hydrant is adopted by the user' do
|
||||||
|
sign_in @user
|
||||||
|
@hydrant.user_id = @user.id
|
||||||
|
@hydrant.save!
|
||||||
|
get :index, :hydrant_id => @hydrant.id
|
||||||
|
assert_not_nil assigns :hydrant
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'users/thank_you'
|
||||||
|
assert_select 'h2', 'Thank you for adopting this hydrant!'
|
||||||
|
assert_select 'form#edit_profile_form' do
|
||||||
|
assert_select '[action=?]', '/users/edit'
|
||||||
|
assert_select '[method=?]', 'get'
|
||||||
|
end
|
||||||
|
assert_select 'input[name="commit"]' do
|
||||||
|
assert_select '[type=?]', 'submit'
|
||||||
|
assert_select '[value=?]', 'Edit profile'
|
||||||
|
end
|
||||||
|
assert_select 'form#abandon_form' do
|
||||||
|
assert_select '[action=?]', "/hydrants"
|
||||||
|
assert_select '[method=?]', 'post'
|
||||||
|
end
|
||||||
|
assert_select 'input[name="_method"]' do
|
||||||
|
assert_select '[type=?]', 'hidden'
|
||||||
|
assert_select '[value=?]', 'put'
|
||||||
|
end
|
||||||
|
assert_select 'input[name="commit"]' do
|
||||||
|
assert_select '[type=?]', 'submit'
|
||||||
|
assert_select '[value=?]', 'Abandon this hydrant'
|
||||||
|
end
|
||||||
|
assert_select 'form#sign_out_form' do
|
||||||
|
assert_select '[action=?]', '/info_window'
|
||||||
|
assert_select '[method=?]', 'post'
|
||||||
|
end
|
||||||
|
assert_select 'input[name="commit"]' do
|
||||||
|
assert_select '[type=?]', 'submit'
|
||||||
|
assert_select '[value=?]', 'Sign out'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should show the profile if the hydrant is adopted' do
|
||||||
|
@hydrant.user_id = @user.id
|
||||||
|
@hydrant.save!
|
||||||
|
get :index, :hydrant_id => @hydrant.id
|
||||||
|
assert_not_nil assigns :hydrant
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'users/profile'
|
||||||
|
assert_select 'h2', "This hydrant has been adopted by #{@user.name}"
|
||||||
|
assert_select 'h3', "of #{@user.organization}"
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should show adoption form if hydrant is not adopted' do
|
||||||
|
sign_in @user
|
||||||
|
get :index, :hydrant_id => @hydrant.id
|
||||||
|
assert_not_nil assigns :hydrant
|
||||||
|
assert_response :success
|
||||||
|
assert_template :adopt
|
||||||
|
assert_select 'h2', 'Adopt this Hydrant'
|
||||||
|
assert_select 'form#adoption_form' do
|
||||||
|
assert_select '[action=?]', "/hydrants"
|
||||||
|
assert_select '[method=?]', 'post'
|
||||||
|
end
|
||||||
|
assert_select 'input[name="_method"]' do
|
||||||
|
assert_select '[type=?]', 'hidden'
|
||||||
|
assert_select '[value=?]', 'put'
|
||||||
|
end
|
||||||
|
assert_select 'input[name="commit"]' do
|
||||||
|
assert_select '[type=?]', 'submit'
|
||||||
|
assert_select '[value=?]', 'Adopt!'
|
||||||
|
end
|
||||||
|
assert_select 'form#edit_profile_form' do
|
||||||
|
assert_select '[action=?]', '/users/edit'
|
||||||
|
assert_select '[method=?]', 'get'
|
||||||
|
end
|
||||||
|
assert_select 'input[name="commit"]' do
|
||||||
|
assert_select '[type=?]', 'submit'
|
||||||
|
assert_select '[value=?]', 'Edit profile'
|
||||||
|
end
|
||||||
|
assert_select 'form#sign_out_form' do
|
||||||
|
assert_select '[action=?]', '/info_window'
|
||||||
|
assert_select '[method=?]', 'post'
|
||||||
|
end
|
||||||
|
assert_select 'input[name="commit"]' do
|
||||||
|
assert_select '[type=?]', 'submit'
|
||||||
|
assert_select '[value=?]', 'Sign out'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'should show sign-in form if signed out' do
|
||||||
|
get :index, :hydrant_id => @hydrant.id
|
||||||
|
assert_not_nil assigns :hydrant
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'sessions/new'
|
||||||
|
assert_select 'form#combo_form' do
|
||||||
|
assert_select '[action=?]', '/info_window'
|
||||||
|
assert_select '[method=?]', 'post'
|
||||||
|
end
|
||||||
|
assert_select 'h2', 'Adopt this Hydrant'
|
||||||
|
assert_select 'input', :count => 15
|
||||||
|
assert_select 'label', :count => 10
|
||||||
|
assert_select 'input[name="commit"]', :count => 3
|
||||||
|
end
|
||||||
|
end
|
|
@ -24,7 +24,7 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
assert_select '[value=?]', 'Update'
|
assert_select '[value=?]', 'Update'
|
||||||
end
|
end
|
||||||
assert_select 'form#back_form' do
|
assert_select 'form#back_form' do
|
||||||
assert_select '[action=?]', '/hydrant'
|
assert_select '[action=?]', '/info_window'
|
||||||
assert_select '[method=?]', 'get'
|
assert_select '[method=?]', 'get'
|
||||||
end
|
end
|
||||||
assert_select 'input[name="commit"]' do
|
assert_select 'input[name="commit"]' do
|
||||||
|
@ -40,7 +40,7 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
@user.reload
|
@user.reload
|
||||||
assert_equal @user.name, 'New Name'
|
assert_equal @user.name, 'New Name'
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_redirected_to :controller => 'hydrants', :action => 'show'
|
assert_redirected_to :controller => 'info_window', :action => 'index'
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'should return error if password is incorrect' do
|
test 'should return error if password is incorrect' do
|
||||||
|
|