Commit 9b8ae79
Changed files (8)
app
spec
app/controllers/needs_controller.rb
@@ -14,6 +14,7 @@ class NeedsController < ApplicationController
def create
@need = current_user.needs.create(params[:need])
+ location = GeoLocationService.GetGeoLocation(params[:location]) if params[:location]
current_user.tag(@need, :with => params[:need_tags], :on => :tags)
if @need.save
redirect_to needs_path, notice: 'Need was successfully created.'
app/helpers/GeoLocationService/GeoLocationService.rb → app/models/geo_location_service.rb
@@ -31,9 +31,7 @@ class GeoLocationService
end
class GeoLocation
-
attr_accessor :x, :y
-
def initialize (x,y)
@x = x
@y = y
app/views/needs/index.html.erb
@@ -17,6 +17,12 @@ $(function() {
<%= f.text_area :description, cols: 160, rows: 2, :class => "span12" %>
</div>
</div>
+ <div class="control-group">
+ <label class="control-label" for="description">location</label>
+ <div class="controls">
+ <input name="location" type="text" value="" />
+ </div>
+ </div>
<div class="control-group">
<label class="control-label" for="description">tags</label>
<div class="controls">
app/helpers/GeoLocationService/spec/GeoLocationService_spec.rb → spec/models/GeoLocationService_spec.rb
@@ -1,4 +1,4 @@
-require_relative '../GeoLocationService.rb'
+require 'spec_helper'
describe GeoLocationService do
it "can get a location" do
@@ -39,4 +39,4 @@ describe GeoLocationService do
result.x.should be_within(0.0001).of(-87.6221405679)
result.y.should be_within(0.0001).of(41.8845104628)
end
-end
\ No newline at end of file
+end
spec/spec_helper.rb
@@ -0,0 +1,38 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
+
+RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = "random"
+end
.rspec
@@ -0,0 +1,1 @@
+--color
Gemfile
@@ -5,10 +5,12 @@ gem 'jquery-ui-rails'
gem 'devise'
gem 'bootstrap-sass'
gem 'acts-as-taggable-on'
+gem 'rest-client'
group :development, :test do
gem 'sqlite3'
gem 'dotenv-rails'
+ gem 'rspec-rails'
end
group :assets do
Gemfile.lock
@@ -50,6 +50,7 @@ GEM
orm_adapter (~> 0.1)
railties (~> 3.1)
warden (~> 1.2.1)
+ diff-lcs (1.2.4)
dotenv (0.8.0)
dotenv-rails (0.8.0)
dotenv (= 0.8.0)
@@ -117,6 +118,19 @@ GEM
rake (10.1.0)
rdoc (3.12.2)
json (~> 1.4)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ rspec-core (2.13.1)
+ rspec-expectations (2.13.0)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.13.1)
+ rspec-rails (2.13.2)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 2.13.0)
+ rspec-expectations (~> 2.13.0)
+ rspec-mocks (~> 2.13.0)
ruby-hmac (0.4.0)
sass (3.2.9)
sass-rails (3.2.6)
@@ -159,6 +173,8 @@ DEPENDENCIES
jquery-ui-rails
pg
rails (= 3.2.13)
+ rest-client
+ rspec-rails
sass-rails (~> 3.2.3)
sqlite3
uglifier (>= 1.0.3)