Enable asset pipeline

This commit is contained in:
Erik Michaels-Ober 2011-05-31 04:12:02 -07:00
parent c7f7d712eb
commit 45c48b75d3
25 changed files with 175 additions and 152 deletions

View File

@ -1,9 +1,12 @@
source 'http://rubygems.org'
gem 'rails', '3.1.0.rc1'
gem 'coffee-script'
gem 'devise'
gem 'geokit'
gem 'haml'
gem 'sass'
gem 'uglifier'
platforms :jruby do
gem 'jruby-openssl', '~> 0.7'

View File

@ -39,12 +39,18 @@ GEM
bcrypt-ruby (2.1.4-java)
bouncy-castle-java (1.5.0146.1)
builder (3.0.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.1.1)
crack (0.1.8)
devise (1.3.4)
bcrypt-ruby (~> 2.1.2)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
erubis (2.7.0)
execjs (1.0.0)
multi_json (~> 1.0)
geokit (1.6.0)
haml (3.1.1)
hike (1.0.0)
@ -84,6 +90,7 @@ GEM
rake (>= 0.8.7)
thor (~> 0.14.6)
rake (0.9.0)
sass (3.1.1)
simplecov (0.4.2)
simplecov-html (~> 0.4.4)
simplecov-html (0.4.5)
@ -101,6 +108,9 @@ GEM
turn (0.8.2)
ansi (>= 1.2.2)
tzinfo (0.3.27)
uglifier (0.5.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
warden (1.0.4)
rack (>= 1.0)
webmock (1.6.4)
@ -113,15 +123,18 @@ PLATFORMS
DEPENDENCIES
ZenTest
coffee-script
devise
geokit
haml
jruby-openssl (~> 0.7)
pg
rails (= 3.1.0.rc1)
sass
simplecov
sqlite3
therubyracer-heroku (= 0.8.1.pre3)
therubyrhino (~> 1.72)
turn
uglifier
webmock

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -20,7 +20,7 @@ $(function() {
new google.maps.Point(0, 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.Point(0, 0),
new google.maps.Point(13.0, 18.0)
@ -47,7 +47,7 @@ $(function() {
activeMarker = marker;
$.ajax({
type: 'GET',
url: '/hydrant',
url: '/info_window',
data: {
'hydrant_id': hydrantId
},
@ -93,7 +93,7 @@ $(function() {
}
setTimeout(function() {
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);
}, i * 100);
});
@ -266,7 +266,7 @@ $(function() {
success: function(data) {
$.ajax({
type: 'GET',
url: '/hydrant',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
},
@ -318,7 +318,7 @@ $(function() {
success: function(data) {
$.ajax({
type: 'GET',
url: '/hydrant',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
},
@ -371,7 +371,7 @@ $(function() {
$(submitButton).attr("disabled", true);
$.ajax({
type: 'POST',
url: '/hydrant',
url: '/hydrants.json',
data: {
'id': $('#hydrant_id').val(),
'commit': submitButton.val(),
@ -396,14 +396,14 @@ $(function() {
success: function(data) {
$.ajax({
type: 'GET',
url: '/hydrant',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
},
success: function(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.Point(0, 0),
new google.maps.Point(13.0, 18.0)
@ -423,7 +423,7 @@ $(function() {
$(submitButton).attr("disabled", true);
$.ajax({
type: 'POST',
url: '/hydrant',
url: '/hydrants.json',
data: {
'id': $('#hydrant_id').val(),
'commit': submitButton.val(),
@ -440,7 +440,6 @@ $(function() {
$('#loader').show();
},
error: function(data) {
console.log(data);
$('#loader').hide();
$('#info_window').show();
$(submitButton).attr("disabled", false);
@ -448,13 +447,13 @@ $(function() {
success: function(data) {
$.ajax({
type: 'GET',
url: '/hydrant',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
},
success: function(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.Point(0, 0),
new google.maps.Point(13.0, 18.0)
@ -475,7 +474,7 @@ $(function() {
$(submitButton).attr("disabled", true);
$.ajax({
type: 'POST',
url: '/hydrant',
url: '/hydrants.json',
data: {
'id': $('#hydrant_id').val(),
'commit': submitButton.val(),
@ -500,13 +499,13 @@ $(function() {
success: function(data) {
$.ajax({
type: 'GET',
url: '/hydrant',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
},
success: function(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.Point(0, 0),
new google.maps.Point(13.0, 18.0)
@ -684,7 +683,7 @@ $(function() {
success: function(data) {
$.ajax({
type: 'GET',
url: '/hydrant',
url: '/info_window',
data: {
'hydrant_id': activeHydrantId
},
@ -701,7 +700,7 @@ $(function() {
$(submitButton).attr("disabled", true);
$.ajax({
type: 'GET',
url: '/users/sign_in',
url: '/info_window',
data: {
'commit': submitButton.val(),
'utf8': '✓',
@ -728,7 +727,7 @@ $(function() {
$(submitButton).attr("disabled", true);
$.ajax({
type: 'GET',
url: '/hydrant',
url: '/info_window',
data: {
'commit': submitButton.val(),
'utf8': '✓',

View File

@ -1,24 +1,7 @@
class HydrantsController < ApplicationController
respond_to :json, :only => [:list, :update]
respond_to :json
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)
unless @hydrants.blank?
respond_with @hydrants

View File

@ -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

View File

@ -6,7 +6,7 @@ class UsersController < Devise::RegistrationsController
def update
if resource.update_with_password(params[resource_name])
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
clean_up_passwords(resource)
render(:json => {"errors" => resource.errors}, :status => 500)

View File

@ -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 "user_id", :value => ""
= f.hidden_field "name", :value => ""

View File

@ -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.submit "Back"

View File

@ -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 "user_id", :value => ""
= f.hidden_field "name", :value => ""

View File

@ -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
Adopt this Hydrant
= f.hidden_field "id"

View File

@ -51,6 +51,6 @@ module AdoptAHydrant
config.active_record.identity_map = true
# Enable the asset pipeline
config.assets.enabled = false
config.assets.enabled = true
end
end

View File

@ -4,9 +4,9 @@ AdoptAHydrant::Application.routes.draw do
:registrations => 'users',
:sessions => 'sessions',
}
get 'hydrants' => 'hydrants#list'
resource :hydrant
get 'address' => 'addresses#show'
get 'address' => 'addresses#show', :as => 'address'
get 'info_window' => 'info_window#index', :as => 'info_window'
get 'sitemap' => 'sitemaps#index', :as => 'sitemap'
resource :hydrants
root :to => 'main#index'
end

View File

@ -1,117 +1,13 @@
require 'test_helper'
class HydrantsControllerTest < 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 :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
# test 'should list hydrants' do
# 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_response :success
# end

View File

@ -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

View File

@ -24,7 +24,7 @@ class UsersControllerTest < ActionController::TestCase
assert_select '[value=?]', 'Update'
end
assert_select 'form#back_form' do
assert_select '[action=?]', '/hydrant'
assert_select '[action=?]', '/info_window'
assert_select '[method=?]', 'get'
end
assert_select 'input[name="commit"]' do
@ -40,7 +40,7 @@ class UsersControllerTest < ActionController::TestCase
@user.reload
assert_equal @user.name, 'New Name'
assert_response :redirect
assert_redirected_to :controller => 'hydrants', :action => 'show'
assert_redirected_to :controller => 'info_window', :action => 'index'
end
test 'should return error if password is incorrect' do