From 25130fcb7fbbc91f60700c9bfa4b4ba2f87ca81b Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 4 Apr 2013 18:17:01 +0100 Subject: [PATCH 01/57] Install Omniauth --- Gemfile | 3 +++ Gemfile.lock | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 39f3a06dd..da51ebb84 100644 --- a/Gemfile +++ b/Gemfile @@ -75,6 +75,9 @@ gem 'geocoder' # For easy calendar selection gem 'bootstrap-datepicker-rails' +# For connecting to other services (eg Twitter) +gem 'omniauth' + # for phusion passenger (i.e. mod_rails) on the server gem 'passenger' gem 'rake', '>= 10.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index a7528ea3a..271ce5887 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,6 +95,7 @@ GEM activesupport (>= 3.1, < 4.1) haml (>= 3.1, < 4.1) railties (>= 3.1, < 4.1) + hashie (1.2.0) highline (1.6.16) hike (1.2.1) i18n (0.6.1) @@ -124,8 +125,10 @@ GEM net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) newrelic_rpm (3.5.8.72) - nokogiri (1.5.7) nokogiri (1.5.8) + omniauth (1.1.3) + hashie (~> 1.2) + rack orm_adapter (0.4.0) passenger (3.0.19) daemon_controller (>= 1.0.0) @@ -242,6 +245,7 @@ DEPENDENCIES json (~> 1.7.7) less-rails newrelic_rpm + omniauth passenger pg rack (~> 1.4.5) From e6e8398038b8a784945f30129ae6e0e6b268ac14 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 4 Apr 2013 18:34:29 +0100 Subject: [PATCH 02/57] Install omniauth-twitter You lied to us, RailsCasts! You lied! Specifically, http://asciicasts.com/episodes/235-omniauth-part-1 lied to us about which gem we needed to install. See also https://github.com/intridea/omniauth/issues/641 for the issues this caused. --- Gemfile | 1 + Gemfile.lock | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Gemfile b/Gemfile index da51ebb84..aa053c647 100644 --- a/Gemfile +++ b/Gemfile @@ -77,6 +77,7 @@ gem 'bootstrap-datepicker-rails' # For connecting to other services (eg Twitter) gem 'omniauth' +gem 'omniauth-twitter' # for phusion passenger (i.e. mod_rails) on the server gem 'passenger' diff --git a/Gemfile.lock b/Gemfile.lock index 271ce5887..3bd726505 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -126,9 +126,16 @@ GEM net-ssh (>= 2.6.5) newrelic_rpm (3.5.8.72) nokogiri (1.5.8) + oauth (0.4.7) omniauth (1.1.3) hashie (~> 1.2) rack + omniauth-oauth (1.0.1) + oauth + omniauth (~> 1.0) + omniauth-twitter (0.0.16) + multi_json (~> 1.3) + omniauth-oauth (~> 1.0) orm_adapter (0.4.0) passenger (3.0.19) daemon_controller (>= 1.0.0) @@ -246,6 +253,7 @@ DEPENDENCIES less-rails newrelic_rpm omniauth + omniauth-twitter passenger pg rack (~> 1.4.5) From 2187972b470af219f8b09e7f29e3be5961f7725f Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 4 Apr 2013 18:38:12 +0100 Subject: [PATCH 03/57] Gitignore the local credentials.sh script. This contains API keys and secrets and so should not be kept in Git. Example script (edit as required): export MANDRILL_USERNAME=xxxxxxxxxxxxxxxxxxxxx export MANDRILL_APIKEY=xxxxxxxxxxxxxxxxxxxxx export TWITTER_KEY=xxxxxxxxxxxxxxxxxxxxx export TWITTER_SECRET=xxxxxxxxxxxxxxxxxxxxx --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index dd8c626f3..ead788319 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .*.sw* *~ *.DS_Store +credentials.sh From 5ea91bf56afeeca4ef8860919ee544f9afa9e205 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 4 Apr 2013 18:48:54 +0100 Subject: [PATCH 04/57] Added an Authentications table. Connects users to remote web services, as recommended at http://asciicasts.com/episodes/235-omniauth-part-1 In addition, we store "token" and "secret" fields. --- .../javascripts/authentications.js.coffee | 3 + app/controllers/authentications_controller.rb | 83 +++++++++ app/helpers/authentications_helper.rb | 2 + app/models/authentication.rb | 3 + app/views/authentications/_form.html.haml | 22 +++ app/views/authentications/edit.html.haml | 7 + app/views/authentications/index.html.haml | 25 +++ app/views/authentications/new.html.haml | 5 + app/views/authentications/show.html.haml | 18 ++ config/routes.rb | 1 + .../20130404174459_create_authentications.rb | 13 ++ db/schema.rb | 14 +- .../authentications_controller_spec.rb | 164 ++++++++++++++++++ spec/factories/authentications.rb | 10 ++ spec/helpers/authentications_helper_spec.rb | 15 ++ spec/models/authentication_spec.rb | 5 + spec/requests/authentications_spec.rb | 11 ++ spec/routing/authentications_routing_spec.rb | 35 ++++ .../authentications/edit.html.haml_spec.rb | 24 +++ .../authentications/index.html.haml_spec.rb | 29 ++++ .../authentications/new.html.haml_spec.rb | 24 +++ .../authentications/show.html.haml_spec.rb | 21 +++ 22 files changed, 533 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/authentications.js.coffee create mode 100644 app/controllers/authentications_controller.rb create mode 100644 app/helpers/authentications_helper.rb create mode 100644 app/models/authentication.rb create mode 100644 app/views/authentications/_form.html.haml create mode 100644 app/views/authentications/edit.html.haml create mode 100644 app/views/authentications/index.html.haml create mode 100644 app/views/authentications/new.html.haml create mode 100644 app/views/authentications/show.html.haml create mode 100644 db/migrate/20130404174459_create_authentications.rb create mode 100644 spec/controllers/authentications_controller_spec.rb create mode 100644 spec/factories/authentications.rb create mode 100644 spec/helpers/authentications_helper_spec.rb create mode 100644 spec/models/authentication_spec.rb create mode 100644 spec/requests/authentications_spec.rb create mode 100644 spec/routing/authentications_routing_spec.rb create mode 100644 spec/views/authentications/edit.html.haml_spec.rb create mode 100644 spec/views/authentications/index.html.haml_spec.rb create mode 100644 spec/views/authentications/new.html.haml_spec.rb create mode 100644 spec/views/authentications/show.html.haml_spec.rb diff --git a/app/assets/javascripts/authentications.js.coffee b/app/assets/javascripts/authentications.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/authentications.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb new file mode 100644 index 000000000..8676dfdd8 --- /dev/null +++ b/app/controllers/authentications_controller.rb @@ -0,0 +1,83 @@ +class AuthenticationsController < ApplicationController + # GET /authentications + # GET /authentications.json + def index + @authentications = Authentication.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @authentications } + end + end + + # GET /authentications/1 + # GET /authentications/1.json + def show + @authentication = Authentication.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @authentication } + end + end + + # GET /authentications/new + # GET /authentications/new.json + def new + @authentication = Authentication.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @authentication } + end + end + + # GET /authentications/1/edit + def edit + @authentication = Authentication.find(params[:id]) + end + + # POST /authentications + # POST /authentications.json + def create + @authentication = Authentication.new(params[:authentication]) + + respond_to do |format| + if @authentication.save + format.html { redirect_to @authentication, notice: 'Authentication was successfully created.' } + format.json { render json: @authentication, status: :created, location: @authentication } + else + format.html { render action: "new" } + format.json { render json: @authentication.errors, status: :unprocessable_entity } + end + end + end + + # PUT /authentications/1 + # PUT /authentications/1.json + def update + @authentication = Authentication.find(params[:id]) + + respond_to do |format| + if @authentication.update_attributes(params[:authentication]) + format.html { redirect_to @authentication, notice: 'Authentication was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @authentication.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /authentications/1 + # DELETE /authentications/1.json + def destroy + @authentication = Authentication.find(params[:id]) + @authentication.destroy + + respond_to do |format| + format.html { redirect_to authentications_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/authentications_helper.rb b/app/helpers/authentications_helper.rb new file mode 100644 index 000000000..2c19ef818 --- /dev/null +++ b/app/helpers/authentications_helper.rb @@ -0,0 +1,2 @@ +module AuthenticationsHelper +end diff --git a/app/models/authentication.rb b/app/models/authentication.rb new file mode 100644 index 000000000..cb415bd91 --- /dev/null +++ b/app/models/authentication.rb @@ -0,0 +1,3 @@ +class Authentication < ActiveRecord::Base + attr_accessible :member_id, :provider, :secret, :uid +end diff --git a/app/views/authentications/_form.html.haml b/app/views/authentications/_form.html.haml new file mode 100644 index 000000000..210501534 --- /dev/null +++ b/app/views/authentications/_form.html.haml @@ -0,0 +1,22 @@ += form_for @authentication do |f| + - if @authentication.errors.any? + #error_explanation + %h2= "#{pluralize(@authentication.errors.count, "error")} prohibited this authentication from being saved:" + %ul + - @authentication.errors.full_messages.each do |msg| + %li= msg + + .field + = f.label :member_id + = f.number_field :member_id + .field + = f.label :provider + = f.text_field :provider + .field + = f.label :uid + = f.text_field :uid + .field + = f.label :secret + = f.text_field :secret + .actions + = f.submit 'Save' diff --git a/app/views/authentications/edit.html.haml b/app/views/authentications/edit.html.haml new file mode 100644 index 000000000..4fc381835 --- /dev/null +++ b/app/views/authentications/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing authentication + += render 'form' + += link_to 'Show', @authentication +\| += link_to 'Back', authentications_path diff --git a/app/views/authentications/index.html.haml b/app/views/authentications/index.html.haml new file mode 100644 index 000000000..eeb90243f --- /dev/null +++ b/app/views/authentications/index.html.haml @@ -0,0 +1,25 @@ +%h1 Listing authentications + +%table + %tr + %th Member + %th Provider + %th Uid + %th Secret + %th + %th + %th + + - @authentications.each do |authentication| + %tr + %td= authentication.member_id + %td= authentication.provider + %td= authentication.uid + %td= authentication.secret + %td= link_to 'Show', authentication + %td= link_to 'Edit', edit_authentication_path(authentication) + %td= link_to 'Destroy', authentication, :method => :delete, :data => { :confirm => 'Are you sure?' } + +%br + += link_to 'New Authentication', new_authentication_path diff --git a/app/views/authentications/new.html.haml b/app/views/authentications/new.html.haml new file mode 100644 index 000000000..39d803c13 --- /dev/null +++ b/app/views/authentications/new.html.haml @@ -0,0 +1,5 @@ +%h1 New authentication + += render 'form' + += link_to 'Back', authentications_path diff --git a/app/views/authentications/show.html.haml b/app/views/authentications/show.html.haml new file mode 100644 index 000000000..dacaa2be8 --- /dev/null +++ b/app/views/authentications/show.html.haml @@ -0,0 +1,18 @@ +%p#notice= notice + +%p + %b Member: + = @authentication.member_id +%p + %b Provider: + = @authentication.provider +%p + %b Uid: + = @authentication.uid +%p + %b Secret: + = @authentication.secret + += link_to 'Edit', edit_authentication_path(@authentication) +\| += link_to 'Back', authentications_path diff --git a/config/routes.rb b/config/routes.rb index 871c85670..a4efa4413 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,7 @@ Growstuff::Application.routes.draw do devise_for :members, :controllers => { :registrations => "registrations" } + resources :authentications resources :plantings resources :gardens resources :posts diff --git a/db/migrate/20130404174459_create_authentications.rb b/db/migrate/20130404174459_create_authentications.rb new file mode 100644 index 000000000..3acdf6080 --- /dev/null +++ b/db/migrate/20130404174459_create_authentications.rb @@ -0,0 +1,13 @@ +class CreateAuthentications < ActiveRecord::Migration + def change + create_table :authentications do |t| + t.integer :member_id, :null => false + t.string :provider, :null => false + t.string :uid + t.string :token + t.string :secret + t.timestamps + end + add_index :authentications, :member_id + end +end diff --git a/db/schema.rb b/db/schema.rb index f13ce0fd1..279d0780e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,19 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130329045744) do +ActiveRecord::Schema.define(:version => 20130404174459) do + + create_table "authentications", :force => true do |t| + t.integer "member_id", :null => false + t.string "provider", :null => false + t.string "uid" + t.string "token" + t.string "secret" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "authentications", ["member_id"], :name => "index_authentications_on_member_id" create_table "comments", :force => true do |t| t.integer "post_id", :null => false diff --git a/spec/controllers/authentications_controller_spec.rb b/spec/controllers/authentications_controller_spec.rb new file mode 100644 index 000000000..bb8f53f76 --- /dev/null +++ b/spec/controllers/authentications_controller_spec.rb @@ -0,0 +1,164 @@ +require 'spec_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +describe AuthenticationsController do + + # This should return the minimal set of attributes required to create a valid + # Authentication. As you add validations to Authentication, be sure to + # update the return value of this method accordingly. + def valid_attributes + { "member_id" => "1" } + end + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # AuthenticationsController. Be sure to keep this updated too. + def valid_session + {} + end + + describe "GET index" do + it "assigns all authentications as @authentications" do + authentication = Authentication.create! valid_attributes + get :index, {}, valid_session + assigns(:authentications).should eq([authentication]) + end + end + + describe "GET show" do + it "assigns the requested authentication as @authentication" do + authentication = Authentication.create! valid_attributes + get :show, {:id => authentication.to_param}, valid_session + assigns(:authentication).should eq(authentication) + end + end + + describe "GET new" do + it "assigns a new authentication as @authentication" do + get :new, {}, valid_session + assigns(:authentication).should be_a_new(Authentication) + end + end + + describe "GET edit" do + it "assigns the requested authentication as @authentication" do + authentication = Authentication.create! valid_attributes + get :edit, {:id => authentication.to_param}, valid_session + assigns(:authentication).should eq(authentication) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new Authentication" do + expect { + post :create, {:authentication => valid_attributes}, valid_session + }.to change(Authentication, :count).by(1) + end + + it "assigns a newly created authentication as @authentication" do + post :create, {:authentication => valid_attributes}, valid_session + assigns(:authentication).should be_a(Authentication) + assigns(:authentication).should be_persisted + end + + it "redirects to the created authentication" do + post :create, {:authentication => valid_attributes}, valid_session + response.should redirect_to(Authentication.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved authentication as @authentication" do + # Trigger the behavior that occurs when invalid params are submitted + Authentication.any_instance.stub(:save).and_return(false) + post :create, {:authentication => { "member_id" => "invalid value" }}, valid_session + assigns(:authentication).should be_a_new(Authentication) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + Authentication.any_instance.stub(:save).and_return(false) + post :create, {:authentication => { "member_id" => "invalid value" }}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested authentication" do + authentication = Authentication.create! valid_attributes + # Assuming there are no other authentications in the database, this + # specifies that the Authentication created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + Authentication.any_instance.should_receive(:update_attributes).with({ "member_id" => "1" }) + put :update, {:id => authentication.to_param, :authentication => { "member_id" => "1" }}, valid_session + end + + it "assigns the requested authentication as @authentication" do + authentication = Authentication.create! valid_attributes + put :update, {:id => authentication.to_param, :authentication => valid_attributes}, valid_session + assigns(:authentication).should eq(authentication) + end + + it "redirects to the authentication" do + authentication = Authentication.create! valid_attributes + put :update, {:id => authentication.to_param, :authentication => valid_attributes}, valid_session + response.should redirect_to(authentication) + end + end + + describe "with invalid params" do + it "assigns the authentication as @authentication" do + authentication = Authentication.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Authentication.any_instance.stub(:save).and_return(false) + put :update, {:id => authentication.to_param, :authentication => { "member_id" => "invalid value" }}, valid_session + assigns(:authentication).should eq(authentication) + end + + it "re-renders the 'edit' template" do + authentication = Authentication.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Authentication.any_instance.stub(:save).and_return(false) + put :update, {:id => authentication.to_param, :authentication => { "member_id" => "invalid value" }}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested authentication" do + authentication = Authentication.create! valid_attributes + expect { + delete :destroy, {:id => authentication.to_param}, valid_session + }.to change(Authentication, :count).by(-1) + end + + it "redirects to the authentications list" do + authentication = Authentication.create! valid_attributes + delete :destroy, {:id => authentication.to_param}, valid_session + response.should redirect_to(authentications_url) + end + end + +end diff --git a/spec/factories/authentications.rb b/spec/factories/authentications.rb new file mode 100644 index 000000000..94588b6f9 --- /dev/null +++ b/spec/factories/authentications.rb @@ -0,0 +1,10 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :authentication do + member_id 1 + provider "MyString" + uid "MyString" + secret "MyString" + end +end diff --git a/spec/helpers/authentications_helper_spec.rb b/spec/helpers/authentications_helper_spec.rb new file mode 100644 index 000000000..1294169a4 --- /dev/null +++ b/spec/helpers/authentications_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the AuthenticationsHelper. For example: +# +# describe AuthenticationsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe AuthenticationsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/authentication_spec.rb b/spec/models/authentication_spec.rb new file mode 100644 index 000000000..7a30df466 --- /dev/null +++ b/spec/models/authentication_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Authentication do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/authentications_spec.rb b/spec/requests/authentications_spec.rb new file mode 100644 index 000000000..01843d6bc --- /dev/null +++ b/spec/requests/authentications_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "Authentications" do + describe "GET /authentications" do + it "works! (now write some real specs)" do + # Run the generator again with the --webrat flag if you want to use webrat methods/matchers + get authentications_path + response.status.should be(200) + end + end +end diff --git a/spec/routing/authentications_routing_spec.rb b/spec/routing/authentications_routing_spec.rb new file mode 100644 index 000000000..1a639dead --- /dev/null +++ b/spec/routing/authentications_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe AuthenticationsController do + describe "routing" do + + it "routes to #index" do + get("/authentications").should route_to("authentications#index") + end + + it "routes to #new" do + get("/authentications/new").should route_to("authentications#new") + end + + it "routes to #show" do + get("/authentications/1").should route_to("authentications#show", :id => "1") + end + + it "routes to #edit" do + get("/authentications/1/edit").should route_to("authentications#edit", :id => "1") + end + + it "routes to #create" do + post("/authentications").should route_to("authentications#create") + end + + it "routes to #update" do + put("/authentications/1").should route_to("authentications#update", :id => "1") + end + + it "routes to #destroy" do + delete("/authentications/1").should route_to("authentications#destroy", :id => "1") + end + + end +end diff --git a/spec/views/authentications/edit.html.haml_spec.rb b/spec/views/authentications/edit.html.haml_spec.rb new file mode 100644 index 000000000..725f39986 --- /dev/null +++ b/spec/views/authentications/edit.html.haml_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe "authentications/edit" do + before(:each) do + @authentication = assign(:authentication, stub_model(Authentication, + :member_id => 1, + :provider => "MyString", + :uid => "MyString", + :secret => "MyString" + )) + end + + it "renders the edit authentication form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => authentications_path(@authentication), :method => "post" do + assert_select "input#authentication_member_id", :name => "authentication[member_id]" + assert_select "input#authentication_provider", :name => "authentication[provider]" + assert_select "input#authentication_uid", :name => "authentication[uid]" + assert_select "input#authentication_secret", :name => "authentication[secret]" + end + end +end diff --git a/spec/views/authentications/index.html.haml_spec.rb b/spec/views/authentications/index.html.haml_spec.rb new file mode 100644 index 000000000..5e5748e97 --- /dev/null +++ b/spec/views/authentications/index.html.haml_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe "authentications/index" do + before(:each) do + assign(:authentications, [ + stub_model(Authentication, + :member_id => 1, + :provider => "Provider", + :uid => "Uid", + :secret => "Secret" + ), + stub_model(Authentication, + :member_id => 1, + :provider => "Provider", + :uid => "Uid", + :secret => "Secret" + ) + ]) + end + + it "renders a list of authentications" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => 1.to_s, :count => 2 + assert_select "tr>td", :text => "Provider".to_s, :count => 2 + assert_select "tr>td", :text => "Uid".to_s, :count => 2 + assert_select "tr>td", :text => "Secret".to_s, :count => 2 + end +end diff --git a/spec/views/authentications/new.html.haml_spec.rb b/spec/views/authentications/new.html.haml_spec.rb new file mode 100644 index 000000000..89e54b43d --- /dev/null +++ b/spec/views/authentications/new.html.haml_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe "authentications/new" do + before(:each) do + assign(:authentication, stub_model(Authentication, + :member_id => 1, + :provider => "MyString", + :uid => "MyString", + :secret => "MyString" + ).as_new_record) + end + + it "renders new authentication form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form", :action => authentications_path, :method => "post" do + assert_select "input#authentication_member_id", :name => "authentication[member_id]" + assert_select "input#authentication_provider", :name => "authentication[provider]" + assert_select "input#authentication_uid", :name => "authentication[uid]" + assert_select "input#authentication_secret", :name => "authentication[secret]" + end + end +end diff --git a/spec/views/authentications/show.html.haml_spec.rb b/spec/views/authentications/show.html.haml_spec.rb new file mode 100644 index 000000000..c0f0c1179 --- /dev/null +++ b/spec/views/authentications/show.html.haml_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe "authentications/show" do + before(:each) do + @authentication = assign(:authentication, stub_model(Authentication, + :member_id => 1, + :provider => "Provider", + :uid => "Uid", + :secret => "Secret" + )) + end + + it "renders attributes in

" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/1/) + rendered.should match(/Provider/) + rendered.should match(/Uid/) + rendered.should match(/Secret/) + end +end From a3ad8c7bf9cb01e2d7f8fb437675808a80ba0f87 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 8 Apr 2013 16:27:03 +0100 Subject: [PATCH 05/57] Stub "authentications#create" method. --- app/controllers/authentications_controller.rb | 12 +----------- app/models/authentication.rb | 2 +- app/models/member.rb | 1 + config/routes.rb | 1 + 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index 8676dfdd8..13ac6bd3b 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -40,17 +40,7 @@ class AuthenticationsController < ApplicationController # POST /authentications # POST /authentications.json def create - @authentication = Authentication.new(params[:authentication]) - - respond_to do |format| - if @authentication.save - format.html { redirect_to @authentication, notice: 'Authentication was successfully created.' } - format.json { render json: @authentication, status: :created, location: @authentication } - else - format.html { render action: "new" } - format.json { render json: @authentication.errors, status: :unprocessable_entity } - end - end + render :text => request.env["omniauth.auth."].to_yaml end # PUT /authentications/1 diff --git a/app/models/authentication.rb b/app/models/authentication.rb index cb415bd91..e6171c8b7 100644 --- a/app/models/authentication.rb +++ b/app/models/authentication.rb @@ -1,3 +1,3 @@ class Authentication < ActiveRecord::Base - attr_accessible :member_id, :provider, :secret, :uid + belongs_to :member end diff --git a/app/models/member.rb b/app/models/member.rb index 18396862a..191b1d4e3 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -10,6 +10,7 @@ class Member < ActiveRecord::Base has_and_belongs_to_many :roles has_many :notifications, :foreign_key => 'recipient_id' has_many :sent_notifications, :foreign_key => 'sender_id' + has_many :authentifications default_scope order("lower(login_name) asc") scope :confirmed, where('confirmed_at IS NOT NULL') diff --git a/config/routes.rb b/config/routes.rb index a4efa4413..e0719a28b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,7 @@ Growstuff::Application.routes.draw do get "home/index" match 'search/members/nearby' => 'members#nearby', :as => :nearby_members + match 'auth/:provider/callback' => 'authentications#create' # The priority is based upon order of creation: # first created -> highest priority. From dcbe9446833952a303f6f6ed9ee2fc219555cb80 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 8 Apr 2013 16:27:50 +0100 Subject: [PATCH 06/57] Removed unneeded generated files. --- .../javascripts/authentications.js.coffee | 3 --- app/helpers/authentications_helper.rb | 2 -- app/views/authentications/_form.html.haml | 22 ------------------- 3 files changed, 27 deletions(-) delete mode 100644 app/assets/javascripts/authentications.js.coffee delete mode 100644 app/helpers/authentications_helper.rb delete mode 100644 app/views/authentications/_form.html.haml diff --git a/app/assets/javascripts/authentications.js.coffee b/app/assets/javascripts/authentications.js.coffee deleted file mode 100644 index 761567942..000000000 --- a/app/assets/javascripts/authentications.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/helpers/authentications_helper.rb b/app/helpers/authentications_helper.rb deleted file mode 100644 index 2c19ef818..000000000 --- a/app/helpers/authentications_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module AuthenticationsHelper -end diff --git a/app/views/authentications/_form.html.haml b/app/views/authentications/_form.html.haml deleted file mode 100644 index 210501534..000000000 --- a/app/views/authentications/_form.html.haml +++ /dev/null @@ -1,22 +0,0 @@ -= form_for @authentication do |f| - - if @authentication.errors.any? - #error_explanation - %h2= "#{pluralize(@authentication.errors.count, "error")} prohibited this authentication from being saved:" - %ul - - @authentication.errors.full_messages.each do |msg| - %li= msg - - .field - = f.label :member_id - = f.number_field :member_id - .field - = f.label :provider - = f.text_field :provider - .field - = f.label :uid - = f.text_field :uid - .field - = f.label :secret - = f.text_field :secret - .actions - = f.submit 'Save' From 83ac83a076d213a096df21078d6ceb6712473df8 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 8 Apr 2013 16:46:17 +0100 Subject: [PATCH 07/57] Add omniauth to our middleware. --- config/initializers/omniauth.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 config/initializers/omniauth.rb diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 000000000..05d79edae --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,3 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] +end From 8647cd5315f7623bbd7b91259356bab50fdaf789 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 8 Apr 2013 16:46:51 +0100 Subject: [PATCH 08/57] Fix typo in models/member.rb --- app/models/member.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/member.rb b/app/models/member.rb index 191b1d4e3..3e3790a46 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -10,7 +10,7 @@ class Member < ActiveRecord::Base has_and_belongs_to_many :roles has_many :notifications, :foreign_key => 'recipient_id' has_many :sent_notifications, :foreign_key => 'sender_id' - has_many :authentifications + has_many :authentications default_scope order("lower(login_name) asc") scope :confirmed, where('confirmed_at IS NOT NULL') From b3154b8592ded6d7e044960e34c3d002b61bfa3e Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 8 Apr 2013 17:03:52 +0100 Subject: [PATCH 09/57] Fix stub authentications#create method As per comment at http://railscasts.com/episodes/235-omniauth-part-1?view=comments#comment_153390 --- app/controllers/authentications_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index 13ac6bd3b..f48c4fc95 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -40,7 +40,8 @@ class AuthenticationsController < ApplicationController # POST /authentications # POST /authentications.json def create - render :text => request.env["omniauth.auth."].to_yaml + auth = request.env['omniauth.auth'] + render :text => auth.to_yaml end # PUT /authentications/1 From 82998ddfd4211d8db7e0af28f5512f7316f10130 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 8 Apr 2013 17:37:36 +0100 Subject: [PATCH 10/57] Create an authentication object on successful callback. --- app/controllers/authentications_controller.rb | 7 ++++++- app/models/authentication.rb | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index f48c4fc95..c4f0dfa36 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -41,7 +41,12 @@ class AuthenticationsController < ApplicationController # POST /authentications.json def create auth = request.env['omniauth.auth'] - render :text => auth.to_yaml + current_member.authentications.create( + :provider => auth['provider'], + :uid => auth['uid'], + :secret => auth['credentials']['secret']) + flash[:notice] = "Authentication successful." + redirect_to authentications_url end # PUT /authentications/1 diff --git a/app/models/authentication.rb b/app/models/authentication.rb index e6171c8b7..a7e843ee3 100644 --- a/app/models/authentication.rb +++ b/app/models/authentication.rb @@ -1,3 +1,4 @@ class Authentication < ActiveRecord::Base belongs_to :member + attr_accessible :provider, :uid, :secret end From 087a0cf1761054addeb1133fa59d5d1e9172f62c Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 16:46:31 +0100 Subject: [PATCH 11/57] Store token on creating a new authentication. --- app/controllers/authentications_controller.rb | 1 + app/models/authentication.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index c4f0dfa36..180c06927 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -44,6 +44,7 @@ class AuthenticationsController < ApplicationController current_member.authentications.create( :provider => auth['provider'], :uid => auth['uid'], + :token => auth['credentials']['token'], :secret => auth['credentials']['secret']) flash[:notice] = "Authentication successful." redirect_to authentications_url diff --git a/app/models/authentication.rb b/app/models/authentication.rb index a7e843ee3..79bb43e68 100644 --- a/app/models/authentication.rb +++ b/app/models/authentication.rb @@ -1,4 +1,4 @@ class Authentication < ActiveRecord::Base belongs_to :member - attr_accessible :provider, :uid, :secret + attr_accessible :provider, :uid, :token, :secret end From 89d8390a6fc82e0043d3b1762bf01828303dbe2e Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 16:50:09 +0100 Subject: [PATCH 12/57] Added authbuttons-rails gem Provides pretty icons for Twitter, FB, GitHub, etc. No Flickr :-( --- Gemfile | 1 + Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index aa053c647..ba7e4a619 100644 --- a/Gemfile +++ b/Gemfile @@ -78,6 +78,7 @@ gem 'bootstrap-datepicker-rails' # For connecting to other services (eg Twitter) gem 'omniauth' gem 'omniauth-twitter' +gem 'authbuttons-rails' # for phusion passenger (i.e. mod_rails) on the server gem 'passenger' diff --git a/Gemfile.lock b/Gemfile.lock index 3bd726505..e46fff46f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,7 @@ GEM i18n (= 0.6.1) multi_json (~> 1.0) arel (3.0.2) + authbuttons-rails (0.1.2) bcrypt-ruby (3.0.1) bluecloth (2.2.0) bootstrap-datepicker-rails (1.0.0) @@ -230,6 +231,7 @@ PLATFORMS ruby DEPENDENCIES + authbuttons-rails bluecloth bootstrap-datepicker-rails bundler (>= 1.1.5) From 0697d5a5eaec70a51ded87a3c349fb64ef3b9668 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 17:19:38 +0100 Subject: [PATCH 13/57] Restrict ability to create authentications. --- app/models/ability.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/ability.rb b/app/models/ability.rb index c5e8c4905..c91bef027 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -43,6 +43,11 @@ class Ability can :manage, ScientificName end + # can create/update/destroy their own authentications against other sites. + can :create, Authentication + can :update, Authentication, :member_id => member.id + can :destroy, Authentication, :member_id => member.id + # anyone can create a post, or comment on a post, # but only the author can edit/destroy it. can :create, Post From a3ac6343c7001b8013382b0319c2694c7320739a Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 17:20:40 +0100 Subject: [PATCH 14/57] Only show current member's authentications on index. --- app/controllers/authentications_controller.rb | 2 +- app/views/authentications/index.html.haml | 32 +++++++------------ 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index 180c06927..a56553911 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -2,7 +2,7 @@ class AuthenticationsController < ApplicationController # GET /authentications # GET /authentications.json def index - @authentications = Authentication.all + @authentications = current_member.authentications if member_signed_in? respond_to do |format| format.html # index.html.erb diff --git a/app/views/authentications/index.html.haml b/app/views/authentications/index.html.haml index eeb90243f..790904281 100644 --- a/app/views/authentications/index.html.haml +++ b/app/views/authentications/index.html.haml @@ -1,25 +1,15 @@ -%h1 Listing authentications - -%table - %tr - %th Member - %th Provider - %th Uid - %th Secret - %th - %th - %th +%h1 Linked accounts on other sites +- if @authentications && !@authentications.empty? + .authentications - @authentications.each do |authentication| - %tr - %td= authentication.member_id - %td= authentication.provider - %td= authentication.uid - %td= authentication.secret - %td= link_to 'Show', authentication - %td= link_to 'Edit', edit_authentication_path(authentication) - %td= link_to 'Destroy', authentication, :method => :delete, :data => { :confirm => 'Are you sure?' } - -%br + .authentication + = image_tag "#{authentication.provider}_64.png", :size => "64x64" + .provider + = authentication.provider.titleize + .uid + = authentication.uid + = link_to "X", authentication, :confirm => "Are you sure you want to remove this authentication?", :method => :delete, :class => "remove" + .clear = link_to 'New Authentication', new_authentication_path From ff80b637433899e113fa147a38f6d979b667037b Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 17:23:59 +0100 Subject: [PATCH 15/57] Add a "name" column to authentications. --- db/migrate/20130409162140_add_name_to_authentications.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20130409162140_add_name_to_authentications.rb diff --git a/db/migrate/20130409162140_add_name_to_authentications.rb b/db/migrate/20130409162140_add_name_to_authentications.rb new file mode 100644 index 000000000..c8e981b5f --- /dev/null +++ b/db/migrate/20130409162140_add_name_to_authentications.rb @@ -0,0 +1,5 @@ +class AddNameToAuthentications < ActiveRecord::Migration + def change + add_column :authentications, :name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 279d0780e..1dd917e6b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130404174459) do +ActiveRecord::Schema.define(:version => 20130409162140) do create_table "authentications", :force => true do |t| t.integer "member_id", :null => false @@ -21,6 +21,7 @@ ActiveRecord::Schema.define(:version => 20130404174459) do t.string "secret" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.string "name" end add_index "authentications", ["member_id"], :name => "index_authentications_on_member_id" From 0db582689868c29f0bc65b17374a2fb0a427f964 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 17:26:47 +0100 Subject: [PATCH 16/57] Remove unused methods on authentications. --- app/controllers/authentications_controller.rb | 43 ------------------- app/models/ability.rb | 4 +- app/views/authentications/edit.html.haml | 7 --- app/views/authentications/new.html.haml | 5 --- app/views/authentications/show.html.haml | 18 -------- 5 files changed, 2 insertions(+), 75 deletions(-) delete mode 100644 app/views/authentications/edit.html.haml delete mode 100644 app/views/authentications/new.html.haml delete mode 100644 app/views/authentications/show.html.haml diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index a56553911..e8ee8e64f 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -10,33 +10,6 @@ class AuthenticationsController < ApplicationController end end - # GET /authentications/1 - # GET /authentications/1.json - def show - @authentication = Authentication.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.json { render json: @authentication } - end - end - - # GET /authentications/new - # GET /authentications/new.json - def new - @authentication = Authentication.new - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @authentication } - end - end - - # GET /authentications/1/edit - def edit - @authentication = Authentication.find(params[:id]) - end - # POST /authentications # POST /authentications.json def create @@ -50,22 +23,6 @@ class AuthenticationsController < ApplicationController redirect_to authentications_url end - # PUT /authentications/1 - # PUT /authentications/1.json - def update - @authentication = Authentication.find(params[:id]) - - respond_to do |format| - if @authentication.update_attributes(params[:authentication]) - format.html { redirect_to @authentication, notice: 'Authentication was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: "edit" } - format.json { render json: @authentication.errors, status: :unprocessable_entity } - end - end - end - # DELETE /authentications/1 # DELETE /authentications/1.json def destroy diff --git a/app/models/ability.rb b/app/models/ability.rb index c91bef027..e8ffaf75c 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -8,6 +8,7 @@ class Ability can :read, :all cannot :read, Notification cannot :create, Notification + cannot :read, Authentication # nobody should be able to view this except admins cannot :read, Role @@ -43,9 +44,8 @@ class Ability can :manage, ScientificName end - # can create/update/destroy their own authentications against other sites. + # can create & destroy their own authentications against other sites. can :create, Authentication - can :update, Authentication, :member_id => member.id can :destroy, Authentication, :member_id => member.id # anyone can create a post, or comment on a post, diff --git a/app/views/authentications/edit.html.haml b/app/views/authentications/edit.html.haml deleted file mode 100644 index 4fc381835..000000000 --- a/app/views/authentications/edit.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h1 Editing authentication - -= render 'form' - -= link_to 'Show', @authentication -\| -= link_to 'Back', authentications_path diff --git a/app/views/authentications/new.html.haml b/app/views/authentications/new.html.haml deleted file mode 100644 index 39d803c13..000000000 --- a/app/views/authentications/new.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%h1 New authentication - -= render 'form' - -= link_to 'Back', authentications_path diff --git a/app/views/authentications/show.html.haml b/app/views/authentications/show.html.haml deleted file mode 100644 index dacaa2be8..000000000 --- a/app/views/authentications/show.html.haml +++ /dev/null @@ -1,18 +0,0 @@ -%p#notice= notice - -%p - %b Member: - = @authentication.member_id -%p - %b Provider: - = @authentication.provider -%p - %b Uid: - = @authentication.uid -%p - %b Secret: - = @authentication.secret - -= link_to 'Edit', edit_authentication_path(@authentication) -\| -= link_to 'Back', authentications_path From 36c509cc90740c1e93f3d652f12f144173590689 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 17:32:03 +0100 Subject: [PATCH 17/57] Add "link to another account" link to authentications/index --- app/views/authentications/index.html.haml | 30 ++++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/views/authentications/index.html.haml b/app/views/authentications/index.html.haml index 790904281..05599b2df 100644 --- a/app/views/authentications/index.html.haml +++ b/app/views/authentications/index.html.haml @@ -1,15 +1,21 @@ %h1 Linked accounts on other sites -- if @authentications && !@authentications.empty? - .authentications - - @authentications.each do |authentication| - .authentication - = image_tag "#{authentication.provider}_64.png", :size => "64x64" - .provider - = authentication.provider.titleize - .uid - = authentication.uid - = link_to "X", authentication, :confirm => "Are you sure you want to remove this authentication?", :method => :delete, :class => "remove" - .clear +- if @authentications + - unless @authentications.empty? + .authentications + - @authentications.each do |authentication| + .authentication + = image_tag "#{authentication.provider}_64.png", :size => "64x64" + .provider + = authentication.provider.titleize + .uid + = authentication.uid + = link_to "X", authentication, :confirm => "Are you sure you want to remove this authentication?", :method => :delete, :class => "remove" + .clear + %p + %strong Link another external account: + - else + %p + %strong Link to an external account: -= link_to 'New Authentication', new_authentication_path += link_to image_tag("twitter_64.png", :size => "64x64"), "/auth/twitter", :class => "auth_provider" From 7be173eea9e75902127988c7fe544a248f5746a1 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 17:38:17 +0100 Subject: [PATCH 18/57] Store name with authentications --- app/controllers/authentications_controller.rb | 1 + app/models/authentication.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index e8ee8e64f..ec1f180f1 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -17,6 +17,7 @@ class AuthenticationsController < ApplicationController current_member.authentications.create( :provider => auth['provider'], :uid => auth['uid'], + :name => auth['info']['nickname'] || auth['info']['name'], :token => auth['credentials']['token'], :secret => auth['credentials']['secret']) flash[:notice] = "Authentication successful." diff --git a/app/models/authentication.rb b/app/models/authentication.rb index 79bb43e68..325bffe40 100644 --- a/app/models/authentication.rb +++ b/app/models/authentication.rb @@ -1,4 +1,4 @@ class Authentication < ActiveRecord::Base belongs_to :member - attr_accessible :provider, :uid, :token, :secret + attr_accessible :provider, :uid, :token, :secret, :name end From 707bae2475a5ee7e6322eb355cec47f1e54737cf Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 17:38:30 +0100 Subject: [PATCH 19/57] Make the authentication into a link to your Twitter page. When we support other authentication providers, we'll need to make this into a callback or something. --- app/views/authentications/index.html.haml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/views/authentications/index.html.haml b/app/views/authentications/index.html.haml index 05599b2df..61cd83250 100644 --- a/app/views/authentications/index.html.haml +++ b/app/views/authentications/index.html.haml @@ -4,12 +4,13 @@ - unless @authentications.empty? .authentications - @authentications.each do |authentication| - .authentication - = image_tag "#{authentication.provider}_64.png", :size => "64x64" - .provider - = authentication.provider.titleize - .uid - = authentication.uid + %a{ :href => "http://twitter.com/#{authentication.name}" } + .authentication + = image_tag "#{authentication.provider}_64.png", :size => "64x64" + .provider + = authentication.provider.titleize + .name + = authentication.name = link_to "X", authentication, :confirm => "Are you sure you want to remove this authentication?", :method => :delete, :class => "remove" .clear %p From f2b2f12f67e6e6ee3519cf7ffb7ecf653ff1bd7c Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 17:45:10 +0100 Subject: [PATCH 20/57] Delete specs for unused views and controller methods. --- .../authentications_controller_spec.rb | 69 +------------------ spec/helpers/authentications_helper_spec.rb | 15 ---- .../authentications/edit.html.haml_spec.rb | 24 ------- .../authentications/index.html.haml_spec.rb | 11 ++- .../authentications/new.html.haml_spec.rb | 24 ------- .../authentications/show.html.haml_spec.rb | 21 ------ 6 files changed, 6 insertions(+), 158 deletions(-) delete mode 100644 spec/helpers/authentications_helper_spec.rb delete mode 100644 spec/views/authentications/edit.html.haml_spec.rb delete mode 100644 spec/views/authentications/new.html.haml_spec.rb delete mode 100644 spec/views/authentications/show.html.haml_spec.rb diff --git a/spec/controllers/authentications_controller_spec.rb b/spec/controllers/authentications_controller_spec.rb index bb8f53f76..6b37708aa 100644 --- a/spec/controllers/authentications_controller_spec.rb +++ b/spec/controllers/authentications_controller_spec.rb @@ -24,7 +24,7 @@ describe AuthenticationsController do # Authentication. As you add validations to Authentication, be sure to # update the return value of this method accordingly. def valid_attributes - { "member_id" => "1" } + { } end # This should return the minimal set of values that should be in the session @@ -42,29 +42,6 @@ describe AuthenticationsController do end end - describe "GET show" do - it "assigns the requested authentication as @authentication" do - authentication = Authentication.create! valid_attributes - get :show, {:id => authentication.to_param}, valid_session - assigns(:authentication).should eq(authentication) - end - end - - describe "GET new" do - it "assigns a new authentication as @authentication" do - get :new, {}, valid_session - assigns(:authentication).should be_a_new(Authentication) - end - end - - describe "GET edit" do - it "assigns the requested authentication as @authentication" do - authentication = Authentication.create! valid_attributes - get :edit, {:id => authentication.to_param}, valid_session - assigns(:authentication).should eq(authentication) - end - end - describe "POST create" do describe "with valid params" do it "creates a new Authentication" do @@ -102,50 +79,6 @@ describe AuthenticationsController do end end - describe "PUT update" do - describe "with valid params" do - it "updates the requested authentication" do - authentication = Authentication.create! valid_attributes - # Assuming there are no other authentications in the database, this - # specifies that the Authentication created on the previous line - # receives the :update_attributes message with whatever params are - # submitted in the request. - Authentication.any_instance.should_receive(:update_attributes).with({ "member_id" => "1" }) - put :update, {:id => authentication.to_param, :authentication => { "member_id" => "1" }}, valid_session - end - - it "assigns the requested authentication as @authentication" do - authentication = Authentication.create! valid_attributes - put :update, {:id => authentication.to_param, :authentication => valid_attributes}, valid_session - assigns(:authentication).should eq(authentication) - end - - it "redirects to the authentication" do - authentication = Authentication.create! valid_attributes - put :update, {:id => authentication.to_param, :authentication => valid_attributes}, valid_session - response.should redirect_to(authentication) - end - end - - describe "with invalid params" do - it "assigns the authentication as @authentication" do - authentication = Authentication.create! valid_attributes - # Trigger the behavior that occurs when invalid params are submitted - Authentication.any_instance.stub(:save).and_return(false) - put :update, {:id => authentication.to_param, :authentication => { "member_id" => "invalid value" }}, valid_session - assigns(:authentication).should eq(authentication) - end - - it "re-renders the 'edit' template" do - authentication = Authentication.create! valid_attributes - # Trigger the behavior that occurs when invalid params are submitted - Authentication.any_instance.stub(:save).and_return(false) - put :update, {:id => authentication.to_param, :authentication => { "member_id" => "invalid value" }}, valid_session - response.should render_template("edit") - end - end - end - describe "DELETE destroy" do it "destroys the requested authentication" do authentication = Authentication.create! valid_attributes diff --git a/spec/helpers/authentications_helper_spec.rb b/spec/helpers/authentications_helper_spec.rb deleted file mode 100644 index 1294169a4..000000000 --- a/spec/helpers/authentications_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -# Specs in this file have access to a helper object that includes -# the AuthenticationsHelper. For example: -# -# describe AuthenticationsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# helper.concat_strings("this","that").should == "this that" -# end -# end -# end -describe AuthenticationsHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/views/authentications/edit.html.haml_spec.rb b/spec/views/authentications/edit.html.haml_spec.rb deleted file mode 100644 index 725f39986..000000000 --- a/spec/views/authentications/edit.html.haml_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'spec_helper' - -describe "authentications/edit" do - before(:each) do - @authentication = assign(:authentication, stub_model(Authentication, - :member_id => 1, - :provider => "MyString", - :uid => "MyString", - :secret => "MyString" - )) - end - - it "renders the edit authentication form" do - render - - # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "form", :action => authentications_path(@authentication), :method => "post" do - assert_select "input#authentication_member_id", :name => "authentication[member_id]" - assert_select "input#authentication_provider", :name => "authentication[provider]" - assert_select "input#authentication_uid", :name => "authentication[uid]" - assert_select "input#authentication_secret", :name => "authentication[secret]" - end - end -end diff --git a/spec/views/authentications/index.html.haml_spec.rb b/spec/views/authentications/index.html.haml_spec.rb index 5e5748e97..f780966ae 100644 --- a/spec/views/authentications/index.html.haml_spec.rb +++ b/spec/views/authentications/index.html.haml_spec.rb @@ -7,13 +7,13 @@ describe "authentications/index" do :member_id => 1, :provider => "Provider", :uid => "Uid", - :secret => "Secret" + :name => "Name" ), stub_model(Authentication, :member_id => 1, :provider => "Provider", :uid => "Uid", - :secret => "Secret" + :name => "Name" ) ]) end @@ -21,9 +21,8 @@ describe "authentications/index" do it "renders a list of authentications" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "tr>td", :text => 1.to_s, :count => 2 - assert_select "tr>td", :text => "Provider".to_s, :count => 2 - assert_select "tr>td", :text => "Uid".to_s, :count => 2 - assert_select "tr>td", :text => "Secret".to_s, :count => 2 + assert_select ".authentication", :count => 2 + assert_select ".provider", :text => "Provider".to_s, :count => 2 + assert_select ".name", :text => "Name".to_s, :count => 2 end end diff --git a/spec/views/authentications/new.html.haml_spec.rb b/spec/views/authentications/new.html.haml_spec.rb deleted file mode 100644 index 89e54b43d..000000000 --- a/spec/views/authentications/new.html.haml_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'spec_helper' - -describe "authentications/new" do - before(:each) do - assign(:authentication, stub_model(Authentication, - :member_id => 1, - :provider => "MyString", - :uid => "MyString", - :secret => "MyString" - ).as_new_record) - end - - it "renders new authentication form" do - render - - # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "form", :action => authentications_path, :method => "post" do - assert_select "input#authentication_member_id", :name => "authentication[member_id]" - assert_select "input#authentication_provider", :name => "authentication[provider]" - assert_select "input#authentication_uid", :name => "authentication[uid]" - assert_select "input#authentication_secret", :name => "authentication[secret]" - end - end -end diff --git a/spec/views/authentications/show.html.haml_spec.rb b/spec/views/authentications/show.html.haml_spec.rb deleted file mode 100644 index c0f0c1179..000000000 --- a/spec/views/authentications/show.html.haml_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -describe "authentications/show" do - before(:each) do - @authentication = assign(:authentication, stub_model(Authentication, - :member_id => 1, - :provider => "Provider", - :uid => "Uid", - :secret => "Secret" - )) - end - - it "renders attributes in

" do - render - # Run the generator again with the --webrat flag if you want to use webrat matchers - rendered.should match(/1/) - rendered.should match(/Provider/) - rendered.should match(/Uid/) - rendered.should match(/Secret/) - end -end From 612b966678e2370c0a20aa784dfa28f2b83dbc3e Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 9 Apr 2013 17:56:48 +0100 Subject: [PATCH 21/57] Disallow duplicate authentications. You can authenticate multiple times against a server, but you must supply different uids each time. --- app/controllers/authentications_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index ec1f180f1..8a29adf3f 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -14,7 +14,7 @@ class AuthenticationsController < ApplicationController # POST /authentications.json def create auth = request.env['omniauth.auth'] - current_member.authentications.create( + current_member.authentications.find_or_create_by_provider_and_uid( :provider => auth['provider'], :uid => auth['uid'], :name => auth['info']['nickname'] || auth['info']['name'], From 41135f3869ca322fb2c5c7abc89610e8e7ba8024 Mon Sep 17 00:00:00 2001 From: Samuel Cochran Date: Thu, 11 Apr 2013 10:23:43 +1000 Subject: [PATCH 22/57] Fix some email formatting issues --- .../confirmation_instructions.html.haml | 20 ++++++++--------- .../reset_password_instructions.html.haml | 22 ++++++++++--------- .../mailer/unlock_instructions.html.haml | 15 ++++++++----- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/app/views/devise/mailer/confirmation_instructions.html.haml b/app/views/devise/mailer/confirmation_instructions.html.haml index 42250d7b9..f336d874e 100644 --- a/app/views/devise/mailer/confirmation_instructions.html.haml +++ b/app/views/devise/mailer/confirmation_instructions.html.haml @@ -5,8 +5,7 @@ Your account on #{site_name} has been created. You just need to confirm your email address through the link below: -%p - = link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) +%p= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %p Once you're confirmed, you can sign in with your login name @@ -17,22 +16,23 @@ %p We're excited to have you as a member, and hope you'll enjoy what #{site_name} has to offer. Take a look around the site, - =link_to 'plant some things', url_for(:controller => '/crops', :only_path => false) - , and feel free to drop in on the - =link_to 'forums', url_for(:controller => '/forums', :only_path => false) + = succeed "," do + = link_to('plant some things', url_for(:controller => '/crops', :only_path => false)) + and feel free to drop in on the + = link_to 'forums', url_for(:controller => '/forums', :only_path => false) if you have any questions or feedback. %p We'd also appreciate it if you'd read our - =link_to 'Community Guidelines', url_for(:controller => '/policy', :action => 'community', :only_path => false) - , and make sure you follow them. We want #{site_name} to be a + = succeed "," do + = link_to 'Community Guidelines', url_for(:controller => '/policy', :action => 'community', :only_path => false) + and make sure you follow them. We want #{site_name} to be a friendly, welcoming environment for everyone, and we hope you'll help us keep it that way. -%p - Looking forward to seeing you! +%p Looking forward to seeing you! %p The #{site_name} team. %br/ - =link_to root_url, root_url + = link_to root_url, root_url diff --git a/app/views/devise/mailer/reset_password_instructions.html.haml b/app/views/devise/mailer/reset_password_instructions.html.haml index 13f3a123a..95aa0ee09 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.haml +++ b/app/views/devise/mailer/reset_password_instructions.html.haml @@ -1,19 +1,21 @@ - site_name = Growstuff::Application.config.site_name %p Hello #{@resource.login_name}, -%p Someone has requested a link to reset your password on #{site_name}. -We presume this was you, in which case you can do so through this link: +%p + Someone has requested a link to reset your password on #{site_name}. + We presume this was you, in which case you can do so through this link: + +%p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %p - = link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) - -%p If it wasn't you, then someone's made a typo or has been messing -around. In this case, you can safely ignore this email, and your -password will not be changed. + If it wasn't you, then someone's made a typo or has been messing + around. In this case, you can safely ignore this email, and your + password will not be changed. %p See you soon, -%p The #{site_name} team. -%br/ -=link_to root_url, root_url +%p + The #{site_name} team. + %br/ + =link_to root_url, root_url diff --git a/app/views/devise/mailer/unlock_instructions.html.haml b/app/views/devise/mailer/unlock_instructions.html.haml index 7c25dce77..91177fd55 100644 --- a/app/views/devise/mailer/unlock_instructions.html.haml +++ b/app/views/devise/mailer/unlock_instructions.html.haml @@ -10,11 +10,14 @@ %p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) -%p If you have actually forgotten your password, you can -= link_to 'reset your password', new_password_url(@resource) -after you've unlocked your account. +%p + If you have actually forgotten your password, you can + = link_to 'reset your password', new_password_url(@resource) + after you've unlocked your account. %p See you soon, -%p The #{site_name} team. -%br/ -=link_to root_url, root_url + +%p + The #{site_name} team. + %br/ + =link_to root_url, root_url From 2418be18d3ae1ea1ded485e11a81a144e9c7271c Mon Sep 17 00:00:00 2001 From: Skud Date: Thu, 18 Apr 2013 23:23:29 +1000 Subject: [PATCH 23/57] added connections to settings page, fixed tests --- app/controllers/authentications_controller.rb | 23 +++--- app/controllers/registrations_controller.rb | 15 +++- app/views/devise/registrations/edit.html.haml | 14 ++++ config/routes.rb | 1 + db/schema.rb | 10 ++- .../authentications_controller_spec.rb | 76 +++++++------------ .../registrations_controller_spec.rb | 25 ++++++ spec/factories/authentications.rb | 9 ++- spec/models/authentication_spec.rb | 7 +- spec/views/devise/registrations/edit_spec.rb | 39 +++++++++- 10 files changed, 151 insertions(+), 68 deletions(-) create mode 100644 spec/controllers/registrations_controller_spec.rb diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index 8a29adf3f..aa3498fd9 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -14,14 +14,19 @@ class AuthenticationsController < ApplicationController # POST /authentications.json def create auth = request.env['omniauth.auth'] - current_member.authentications.find_or_create_by_provider_and_uid( - :provider => auth['provider'], - :uid => auth['uid'], - :name => auth['info']['nickname'] || auth['info']['name'], - :token => auth['credentials']['token'], - :secret => auth['credentials']['secret']) - flash[:notice] = "Authentication successful." - redirect_to authentications_url + @authentication = nil + if auth + @authentication = current_member.authentications.find_or_create_by_provider_and_uid( + :provider => auth['provider'], + :uid => auth['uid'], + :name => auth['info']['nickname'] || auth['info']['name'], + :token => auth['credentials']['token'], + :secret => auth['credentials']['secret']) + flash[:notice] = "Authentication successful." + else + flash[:notice] = "Authentication failed." + end + redirect_to edit_member_registration_path end # DELETE /authentications/1 @@ -31,7 +36,7 @@ class AuthenticationsController < ApplicationController @authentication.destroy respond_to do |format| - format.html { redirect_to authentications_url } + format.html { redirect_to edit_member_registration_path } format.json { head :no_content } end end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 566ecb94c..79c809ead 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -1,8 +1,16 @@ -# we need this subclass so that Devise doesn't force people to change their -# password every time they want to edit their settings. Code copied from -# https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password class RegistrationsController < Devise::RegistrationsController + + def edit + @twitter_auth = current_member.authentications.find_by_provider('twitter') + render "edit" + end + +# we need this subclassed method so that Devise doesn't force people to +# change their password every time they want to edit their settings. +# Code copied from +# https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password + def update # required for settings form to submit when password is left blank if params[:member][:password].blank? @@ -12,6 +20,7 @@ class RegistrationsController < Devise::RegistrationsController end @member = Member.find(current_member.id) + if @member.update_attributes(params[:member]) set_flash_message :notice, :updated # Sign in the member bypassing validation in case his password changed diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 235658336..21a3ef3de 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -38,6 +38,20 @@ = f.check_box :show_email Show email publicly on your profile page + %h2 Linked accounts + + .control-group + .controls + %p + = image_tag "twitter_32.png", :size => "32x32", :alt => 'Twitter logo' + - if @twitter_auth + You are connected to Twitter as + = succeed "." do + =link_to @twitter_auth.name, "http://twitter.com/#{@twitter_auth.name}" + = link_to "Disconnect", @twitter_auth, :confirm => "Are you sure you want to remove this connection?", :method => :delete, :class => "remove" + - else + =link_to 'Connect to Twitter', '/auth/twitter' + %h2 Change password %p %span.help-block Leave blank if you don't want to change your password. diff --git a/config/routes.rb b/config/routes.rb index e0719a28b..4373efb3b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,7 @@ Growstuff::Application.routes.draw do get "home/index" match 'search/members/nearby' => 'members#nearby', :as => :nearby_members + match 'auth/:provider/callback' => 'authentications#create' # The priority is based upon order of creation: diff --git a/db/schema.rb b/db/schema.rb index 1dd917e6b..4c82164fe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130409162140) do +ActiveRecord::Schema.define(:version => 20130418102558) do create_table "authentications", :force => true do |t| t.integer "member_id", :null => false @@ -120,6 +120,14 @@ ActiveRecord::Schema.define(:version => 20130409162140) do t.datetime "updated_at", :null => false end + create_table "payments", :force => true do |t| + t.integer "payer_id" + t.string "payment_type" + t.decimal "amount" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "plantings", :force => true do |t| t.integer "garden_id", :null => false t.integer "crop_id", :null => false diff --git a/spec/controllers/authentications_controller_spec.rb b/spec/controllers/authentications_controller_spec.rb index 6b37708aa..393f0509a 100644 --- a/spec/controllers/authentications_controller_spec.rb +++ b/spec/controllers/authentications_controller_spec.rb @@ -1,44 +1,24 @@ require 'spec_helper' -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. - describe AuthenticationsController do - # This should return the minimal set of attributes required to create a valid - # Authentication. As you add validations to Authentication, be sure to - # update the return value of this method accordingly. - def valid_attributes - { } - end - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # AuthenticationsController. Be sure to keep this updated too. - def valid_session - {} + before(:each) do + @member = FactoryGirl.create(:member) + sign_in @member + controller.stub(:current_member) { @member } + @auth = FactoryGirl.create(:authentication, :member => @member) + request.env['omniauth.auth'] = { + 'provider' => 'foo', + 'uid' => 'bar', + 'info' => { 'nickname' => 'blah' }, + 'credentials' => { 'token' => 'blah', 'secret' => 'blah' } + } end describe "GET index" do it "assigns all authentications as @authentications" do - authentication = Authentication.create! valid_attributes - get :index, {}, valid_session - assigns(:authentications).should eq([authentication]) + get :index, {} + assigns(:authentications).should eq([@auth]) end end @@ -46,19 +26,19 @@ describe AuthenticationsController do describe "with valid params" do it "creates a new Authentication" do expect { - post :create, {:authentication => valid_attributes}, valid_session + post :create, {:authentication => @auth} }.to change(Authentication, :count).by(1) end it "assigns a newly created authentication as @authentication" do - post :create, {:authentication => valid_attributes}, valid_session + post :create, {:authentication => @auth} assigns(:authentication).should be_a(Authentication) assigns(:authentication).should be_persisted end - it "redirects to the created authentication" do - post :create, {:authentication => valid_attributes}, valid_session - response.should redirect_to(Authentication.last) + it "redirects to the settings page" do + post :create, {:authentication => @auth } + response.should redirect_to(edit_member_registration_path) end end @@ -66,31 +46,31 @@ describe AuthenticationsController do it "assigns a newly created but unsaved authentication as @authentication" do # Trigger the behavior that occurs when invalid params are submitted Authentication.any_instance.stub(:save).and_return(false) - post :create, {:authentication => { "member_id" => "invalid value" }}, valid_session + post :create, {:authentication => { "member_id" => "invalid value" }} assigns(:authentication).should be_a_new(Authentication) end - it "re-renders the 'new' template" do + it "redirects to settings page" do # Trigger the behavior that occurs when invalid params are submitted Authentication.any_instance.stub(:save).and_return(false) - post :create, {:authentication => { "member_id" => "invalid value" }}, valid_session - response.should render_template("new") + post :create, {:authentication => { "member_id" => "invalid value" }} + response.should redirect_to(edit_member_registration_path) end end end describe "DELETE destroy" do it "destroys the requested authentication" do - authentication = Authentication.create! valid_attributes + authentication = @auth expect { - delete :destroy, {:id => authentication.to_param}, valid_session + delete :destroy, {:id => authentication.to_param} }.to change(Authentication, :count).by(-1) end - it "redirects to the authentications list" do - authentication = Authentication.create! valid_attributes - delete :destroy, {:id => authentication.to_param}, valid_session - response.should redirect_to(authentications_url) + it "redirects to the settings page" do + authentication = @auth + delete :destroy, {:id => authentication.to_param} + response.should redirect_to(edit_member_registration_path) end end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb new file mode 100644 index 000000000..bc0a93433 --- /dev/null +++ b/spec/controllers/registrations_controller_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe RegistrationsController do + + before :each do + @member = FactoryGirl.create(:member) + sign_in @member + controller.stub(:current_user) { @member } + controller.stub(:devise_mapping).and_return(Devise.mappings[:member]) + end + + describe "GET edit" do + it "assigns the requested member as @member" do + get :edit + assigns(:member).should eq(@member) + end + + it "picks up the twitter auth" do + @auth = FactoryGirl.create(:authentication, :member => @member) + get :edit + assigns(:twitter_auth).should eq @auth + end + end + +end diff --git a/spec/factories/authentications.rb b/spec/factories/authentications.rb index 94588b6f9..806edbb4b 100644 --- a/spec/factories/authentications.rb +++ b/spec/factories/authentications.rb @@ -2,9 +2,10 @@ FactoryGirl.define do factory :authentication do - member_id 1 - provider "MyString" - uid "MyString" - secret "MyString" + member + provider 'twitter' + uid 'foo' + secret 'bar' + name 'baz' end end diff --git a/spec/models/authentication_spec.rb b/spec/models/authentication_spec.rb index 7a30df466..2a9df9aec 100644 --- a/spec/models/authentication_spec.rb +++ b/spec/models/authentication_spec.rb @@ -1,5 +1,10 @@ require 'spec_helper' describe Authentication do - pending "add some examples to (or delete) #{__FILE__}" + + it 'creates an authentication' do + @auth = FactoryGirl.create(:authentication) + @auth.should be_an_instance_of Authentication + @auth.member.should be_an_instance_of Member + end end diff --git a/spec/views/devise/registrations/edit_spec.rb b/spec/views/devise/registrations/edit_spec.rb index 9d15b523e..d22a3d359 100644 --- a/spec/views/devise/registrations/edit_spec.rb +++ b/spec/views/devise/registrations/edit_spec.rb @@ -11,14 +11,18 @@ describe 'devise/registrations/edit.html.haml', :type => "view" do @view.stub(:resource_name).and_return("member") @view.stub(:resource_class).and_return(Member) @view.stub(:devise_mapping).and_return(Devise.mappings[:member]) - render end it 'should have some fields' do - rendered.should contain 'Email' + render + rendered.should contain 'Email' end context 'email section' do + before(:each) do + render + end + it 'has a heading' do assert_select "h2", "Email settings" end @@ -29,6 +33,10 @@ describe 'devise/registrations/edit.html.haml', :type => "view" do end context 'profile section' do + before(:each) do + render + end + it 'has a heading' do assert_select "h2", "Profile details" end @@ -46,7 +54,34 @@ describe 'devise/registrations/edit.html.haml', :type => "view" do end end + context 'other sites section' do + it 'has a heading' do + render + assert_select "h2", "Linked accounts" + end + context 'not connected to twitter' do + it 'has a link to connect' do + render + assert_select "a", "Connect to Twitter" + end + end + context 'connected to twitter' do + before(:each) do + @twitter_auth = FactoryGirl.create(:authentication, :member => @member) + render + end + it 'has a link to twitter profile' do + assert_select "a", :href => "http://twitter.com/#{@twitter_auth.name}" + end + it 'has a link to disconnect' do + render + assert_select "a", :href => @twitter_auth, :text => "Disconnect" + end + end + end + it 'should have a password section' do + render assert_select "h2", "Change password" end From f05a8f9ce6e86b2aec08ddc0de9792d302a0da68 Mon Sep 17 00:00:00 2001 From: Skud Date: Thu, 18 Apr 2013 23:56:50 +1000 Subject: [PATCH 24/57] added twitter link to profile page --- app/controllers/members_controller.rb | 5 +-- app/controllers/registrations_controller.rb | 2 +- app/views/members/show.html.haml | 36 ++++++++++++++------- spec/controllers/member_controller_spec.rb | 6 ++++ spec/views/members/show.html.haml_spec.rb | 24 +++++++++++--- 5 files changed, 55 insertions(+), 18 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 797ee229d..67a4c2583 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -11,8 +11,9 @@ class MembersController < ApplicationController end def show - @member = Member.confirmed.find(params[:id]) - @posts = @member.posts + @member = Member.confirmed.find(params[:id]) + @twitter_auth = @member.authentications.find_by_provider('twitter') + @posts = @member.posts # The garden form partial is called from the "New Garden" tab; # it requires a garden to be passed in @garden. # The new garden is not persisted unless Garden#save is called. diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 79c809ead..f863a02f3 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -25,7 +25,7 @@ class RegistrationsController < Devise::RegistrationsController set_flash_message :notice, :updated # Sign in the member bypassing validation in case his password changed sign_in @member, :bypass => true - redirect_to after_update_path_for(@member) + redirect_to edit_member_registration_path else render "edit" end diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 455cfd573..39a7893af 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -12,21 +12,32 @@ =link_to 'Send Message', new_notification_path(:sender_id => current_member.id, :recipient_id => @member.id), :class => 'btn btn-primary' %p - %strong Member since: + %strong Member since: = @member.created_at.to_s(:date) + + - if @twitter_auth || @member.show_email + %h4 Contact + + - if @twitter_auth + %p + = image_tag "twitter_32.png", :size => "32x32", :alt => 'Twitter logo' + =link_to @twitter_auth.name, "http://twitter.com/#{@twitter_auth.name}" + + - if @member.show_email + %p + Email: + = mail_to @member.email + - if @member.location.to_s != '' + %h4 Location %p - %strong Location: + = image_tag("http://maps.google.com/maps/api/staticmap?size=200x200&maptype=roadmap&sensor=false&markers=color:green|label:A|#{@member.latitude},#{@member.longitude}&zoom=12", :alt => "Map showing #{@member.location}", :width => 200, :height => 200 ) + %br/ + Location: = @member.location %br/ = link_to 'Find members near here', nearby_members_path(:location => @member.location) - %br/ - = image_tag("http://maps.google.com/maps/api/staticmap?size=200x200&maptype=roadmap&sensor=false&markers=color:green|label:A|#{@member.latitude},#{@member.longitude}&zoom=12", :alt => "Map showing #{@member.location}", :width => 200, :height => 200 ) %p - - if @member.show_email - %p - Email: - = mail_to @member.email - if current_member == @member %p = link_to 'Edit Settings', "edit", :class => 'btn btn-mini' @@ -64,6 +75,9 @@ %h3 Create a new garden = render 'gardens/form' - %h3 Updates - - @member.posts.each do |post| - = render :partial => "posts/single", :locals => { :post => post, :subject => true } + %h3 Posts + - if @member.posts.count > 0 + - @member.posts.each do |post| + = render :partial => "posts/single", :locals => { :post => post, :subject => true } + - else + %p Nothing posted yet. diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index 71a9fb68b..c37d79afe 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -5,6 +5,7 @@ describe MembersController do before :each do @member = FactoryGirl.create(:member) @posts = [ FactoryGirl.create(:post, :author => @member) ] + @twitter_auth = FactoryGirl.create(:authentication, :member => @member) end describe "GET index" do @@ -37,6 +38,11 @@ describe MembersController do assigns(:posts).should eq(@posts) end + it "assigns @twitter_auth" do + get :show, {:id => @member.id} + assigns(:posts).should eq(@posts) + end + it "doesn't show completely nonsense members" do lambda { get :show, {:id => 9999} }.should raise_error end diff --git a/spec/views/members/show.html.haml_spec.rb b/spec/views/members/show.html.haml_spec.rb index f141694ec..ed03dcb4c 100644 --- a/spec/views/members/show.html.haml_spec.rb +++ b/spec/views/members/show.html.haml_spec.rb @@ -23,6 +23,22 @@ describe "members/show" do end end + context 'twitter' do + context "no twitter" do + it "doesn't show twitter link" do + render + assert_select "a[href^=http://twitter.com/]", :count => 0 + end + end + context 'has twitter' do + it "shows twitter link" do + @twitter_auth = FactoryGirl.create(:authentication, :member => @member) + render + assert_select "a", :href => "http://twitter.com/#{@twitter_auth.name}" + end + end + end + context "gardens and plantings" do before(:each) do @planting = FactoryGirl.create(:planting, :garden => @garden) @@ -59,7 +75,7 @@ describe "members/show" do it "does not contain a 'New Garden' tab" do assert_select "#garden_new", false - end + end end context "signed in member" do @@ -93,11 +109,11 @@ describe "members/show" do it "does not contain a 'New Garden' link" do assert_select "a[href=#garden_new]", false end - + it "does not contain a 'New Garden' tab" do assert_select "#garden_new", false - end - + end + it "contains no edit settings button" do rendered.should_not contain "Edit Settings" end From 6caf8e4160d92b88aae34a6de70fbdfb5bc975a8 Mon Sep 17 00:00:00 2001 From: Cesy Avon Date: Tue, 23 Apr 2013 09:05:12 -0700 Subject: [PATCH 25/57] Writing tests first --- spec/controllers/member_controller_spec.rb | 6 ++++++ spec/views/members/nearby.html.haml_spec.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index c37d79afe..b919c6dcb 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -99,6 +99,12 @@ describe MembersController do get :nearby, { :location => @member_far.location } assigns(:nearby_members).should_not include @member_near end + + it "finds lonely members if you increase the distance" do + get :nearby, { :distance => "50000" } + assigns(:nearby_members).should include @member_far + end + end context "when the user is logged in but hasn't set their location" do diff --git a/spec/views/members/nearby.html.haml_spec.rb b/spec/views/members/nearby.html.haml_spec.rb index 0199a8605..8d7342005 100644 --- a/spec/views/members/nearby.html.haml_spec.rb +++ b/spec/views/members/nearby.html.haml_spec.rb @@ -18,6 +18,10 @@ describe "members/nearby" do assert_select "#location", :value => @location end + it "shows the default distance in the textbox" do + assert_select "#distance", :value => "100" + end + it "shows the names of nearby members" do @nearby_members.each do |m| rendered.should contain m.login_name From cebd49271a593b4bcde2d0141f7438fefb3953b2 Mon Sep 17 00:00:00 2001 From: Cesy Avon Date: Tue, 23 Apr 2013 10:13:21 -0700 Subject: [PATCH 26/57] Finding nearby members by distance Distance is now configurable Units framework is there but it's not working yet --- app/controllers/members_controller.rb | 17 +++++++++++++++-- app/views/members/nearby.html.haml | 5 ++++- spec/controllers/member_controller_spec.rb | 10 ++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 67a4c2583..c02d08272 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -36,8 +36,21 @@ class MembersController < ApplicationController else @location = nil end - @distance = 100 - @nearby_members = @location ? Member.near(@location, @distance) : [] + + if !params[:distance].blank? + @distance = params[:distance] + else + @distance = 100 + end + + # This isn't actually working yet + if !params[:units].blank? + @units = params[:units] + else + @units = :mi + end + + @nearby_members = @location ? Member.near(@location, @distance, :units => @units) : [] respond_to do |format| format.html # nearby.html.haml format.json { render json: @nearby_members } diff --git a/app/views/members/nearby.html.haml b/app/views/members/nearby.html.haml index 9dba3a259..77cc75fd1 100644 --- a/app/views/members/nearby.html.haml +++ b/app/views/members/nearby.html.haml @@ -4,7 +4,10 @@ %p = form_tag(nearby_members_path, :method => :get, :class => 'form-inline') do - = label_tag :location, "Find members near", :class => 'control-label' + = label_tag :distance, "Find members within", :class => 'control-label' + = text_field_tag :distance, @distance, :class => 'input-mini' + - #= select_tag :units, options_for_select(["miles" => :mi, "km" => :km], @units), :width => "2em", :class => 'input-mini' + = label_tag :location, "miles of", :class => 'control-label' = text_field_tag :location, @location = submit_tag "Search", :class => 'btn btn-primary' diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index b919c6dcb..60efe89f5 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -105,6 +105,16 @@ describe MembersController do assigns(:nearby_members).should include @member_far end + it "finds them by miles" #do + # get :nearby, { :distance => "350", :units => :mi, :location => [55.953252, -3.188267] } + # assigns(:nearby_members).should include @member_near + #end + + it "doesn't find them by km" #do + # get :nearby, { :distance => "350", :units => :km, :location => [55.953252, -3.188267] } + # assigns(:nearby_members).should_not include @member_near + #end + end context "when the user is logged in but hasn't set their location" do From 00573d5d8ab718ab5f4412d1634b6525e46585d6 Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 24 Apr 2013 20:11:21 -0400 Subject: [PATCH 27/57] Removed duplicate stylesheet_link_tag --- app/views/layouts/_meta.html.haml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/layouts/_meta.html.haml b/app/views/layouts/_meta.html.haml index c9f52d851..edd940210 100644 --- a/app/views/layouts/_meta.html.haml +++ b/app/views/layouts/_meta.html.haml @@ -10,7 +10,6 @@ %title = content_for?(:title) ? yield(:title) + " - #{ Growstuff::Application.config.site_name} " : Growstuff::Application.config.site_name - = stylesheet_link_tag "application", :media => "all" = csrf_meta_tags / Le HTML5 shim, for IE6-8 support of HTML elements /[if lt IE 9] From a16d07cfef3e7298745a1d80f0f75efd1c4c4131 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 25 Apr 2013 22:53:07 +0100 Subject: [PATCH 28/57] Fix tests for units in Members#nearby --- app/controllers/members_controller.rb | 2 +- spec/controllers/member_controller_spec.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index c02d08272..dc2921fcd 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -45,7 +45,7 @@ class MembersController < ApplicationController # This isn't actually working yet if !params[:units].blank? - @units = params[:units] + @units = params[:units].to_sym else @units = :mi end diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index 60efe89f5..635009c06 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -105,15 +105,15 @@ describe MembersController do assigns(:nearby_members).should include @member_far end - it "finds them by miles" #do - # get :nearby, { :distance => "350", :units => :mi, :location => [55.953252, -3.188267] } - # assigns(:nearby_members).should include @member_near - #end + it "finds them by miles" do + get :nearby, { :distance => "350", :units => :mi, :location => [55.953252, -3.188267] } + assigns(:nearby_members).should include @member_near + end - it "doesn't find them by km" #do - # get :nearby, { :distance => "350", :units => :km, :location => [55.953252, -3.188267] } - # assigns(:nearby_members).should_not include @member_near - #end + it "doesn't find them by km" do + get :nearby, { :distance => "350", :units => :km, :location => [55.953252, -3.188267] } + assigns(:nearby_members).should_not include @member_near + end end From a8fd75492aaf0e20e320a51ca7550f51560b9730 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 25 Apr 2013 23:05:08 +0100 Subject: [PATCH 29/57] Units: be less trusting of user input. --- app/controllers/members_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index dc2921fcd..a55330ebc 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -43,11 +43,10 @@ class MembersController < ApplicationController @distance = 100 end - # This isn't actually working yet - if !params[:units].blank? + if params[:units] == "mi" || params[:units] == "km" @units = params[:units].to_sym else - @units = :mi + @units = :km end @nearby_members = @location ? Member.near(@location, @distance, :units => @units) : [] From 643c8f09173cf25a792343941337865c85bcb687 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 25 Apr 2013 23:17:29 +0100 Subject: [PATCH 30/57] Rename local vars in tests for greater clarity. --- config/environments/test.rb | 9 ++++ spec/controllers/member_controller_spec.rb | 57 +++++++++++----------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 0de67c729..5f48eccfa 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -66,3 +66,12 @@ Geocoder::Lookup::Test.add_stub( } ] ) + +Geocoder::Lookup::Test.add_stub( + "Edinburgh", [ + { + 'latitude' => 55.953252, + 'longitude' => -3.188267, + } + ] +) diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index 635009c06..5a067afed 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -65,8 +65,8 @@ describe MembersController do describe "GET nearby members" do before(:each) do - @member_near = FactoryGirl.create(:geolocated_member) - @member_far = FactoryGirl.create(:lonely_geolocated_member) + @member_london = FactoryGirl.create(:geolocated_member) + @member_south_pole = FactoryGirl.create(:lonely_geolocated_member) end context "when the user is logged in and has set their location" do @@ -82,38 +82,39 @@ describe MembersController do it "assigns nearby members as nearby" do get :nearby - assigns(:nearby_members).should include @member_near + assigns(:nearby_members).should include @member_london end it "doesn't assign far-off members as nearby" do get :nearby - assigns(:nearby_members).should_not include @member_far + assigns(:nearby_members).should_not include @member_south_pole end it "gets members near the specified location if one is set" do - get :nearby, { :location => @member_far.location } - assigns(:nearby_members).should include @member_far + get :nearby, { :location => @member_south_pole.location } + assigns(:nearby_members).should include @member_south_pole end it "does not assign members near current_member if a location is set" do - get :nearby, { :location => @member_far.location } - assigns(:nearby_members).should_not include @member_near + get :nearby, { :location => @member_south_pole.location } + assigns(:nearby_members).should_not include @member_london end - it "finds lonely members if you increase the distance" do - get :nearby, { :distance => "50000" } - assigns(:nearby_members).should include @member_far - end + it "finds faraway members if you increase the distance" do + get :nearby, { :distance => "50000" } + assigns(:nearby_members).should include @member_south_pole + end - it "finds them by miles" do - get :nearby, { :distance => "350", :units => :mi, :location => [55.953252, -3.188267] } - assigns(:nearby_members).should include @member_near - end + # Edinburgh and London are approximately 330mi/530km apart + it "finds London members within 350 miles of Edinburgh" do + get :nearby, { :distance => "350", :units => :mi, :location => "Edinburgh" } + assigns(:nearby_members).should include @member_london + end - it "doesn't find them by km" do - get :nearby, { :distance => "350", :units => :km, :location => [55.953252, -3.188267] } - assigns(:nearby_members).should_not include @member_near - end + it "doesn't find London members within 350 km of Edinburgh" do + get :nearby, { :distance => "350", :units => :km, :location => "Edinburgh" } + assigns(:nearby_members).should_not include @member_london + end end @@ -129,13 +130,13 @@ describe MembersController do end it "assigns nearby members if a location is set" do - get :nearby, { :location => @member_near.location } - assigns(:nearby_members).should include @member_near + get :nearby, { :location => @member_london.location } + assigns(:nearby_members).should include @member_london end it "does not assign far members if a location is set" do - get :nearby, { :location => @member_near.location } - assigns(:nearby_members).should_not include @member_far + get :nearby, { :location => @member_london.location } + assigns(:nearby_members).should_not include @member_south_pole end end @@ -152,13 +153,13 @@ describe MembersController do end it "assigns nearby members if a location is set" do - get :nearby, { :location => @member_near.location } - assigns(:nearby_members).should include @member_near + get :nearby, { :location => @member_london.location } + assigns(:nearby_members).should include @member_london end it "does not assign far members if a location is set" do - get :nearby, { :location => @member_near.location } - assigns(:nearby_members).should_not include @member_far + get :nearby, { :location => @member_london.location } + assigns(:nearby_members).should_not include @member_south_pole end end end From 2421126825b3f26503985eee8ba52c9bf1a5f612 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 25 Apr 2013 23:27:52 +0100 Subject: [PATCH 31/57] Put locations in geolocated_member factory names. --- spec/controllers/home_controller_spec.rb | 2 +- spec/controllers/member_controller_spec.rb | 6 +++--- spec/factories/member.rb | 4 ++-- spec/models/member_spec.rb | 6 +++--- spec/views/home/index_spec.rb | 4 ++-- spec/views/members/index.html.haml_spec.rb | 2 +- spec/views/members/nearby.html.haml_spec.rb | 2 +- spec/views/members/show.html.haml_spec.rb | 2 +- spec/views/plantings/show.html.haml_spec.rb | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 839545b51..2038c823d 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -21,7 +21,7 @@ describe HomeController do end it 'assigns interesting members' do - @member = FactoryGirl.create(:geolocated_member) + @member = FactoryGirl.create(:london_member) get :index, {} assigns(:interesting_members).should eq [@member] end diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index 5a067afed..738ee1ab5 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -65,13 +65,13 @@ describe MembersController do describe "GET nearby members" do before(:each) do - @member_london = FactoryGirl.create(:geolocated_member) - @member_south_pole = FactoryGirl.create(:lonely_geolocated_member) + @member_london = FactoryGirl.create(:london_member) + @member_south_pole = FactoryGirl.create(:south_pole_member) end context "when the user is logged in and has set their location" do before(:each) do - @member = FactoryGirl.create(:geolocated_member) + @member = FactoryGirl.create(:london_member) controller.stub(:current_member) { @member } end diff --git a/spec/factories/member.rb b/spec/factories/member.rb index 9c3531a1c..5e5b7f455 100644 --- a/spec/factories/member.rb +++ b/spec/factories/member.rb @@ -24,7 +24,7 @@ FactoryGirl.define do show_email true end - factory :geolocated_member do + factory :london_member do sequence(:login_name) { |n| "JohnH#{n}" } # for the astronomer who figured out longitude location 'Greenwich, UK' # including lat/long explicitly because geocoder doesn't work with FG @@ -32,7 +32,7 @@ FactoryGirl.define do longitude 0.004 end - factory :lonely_geolocated_member do + factory :south_pole_member do sequence(:login_name) { |n| "ScottRF#{n}" } location 'Amundsen-Scott Base, Antarctica' latitude -90 diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index e1f756634..cd5decf14 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -221,9 +221,9 @@ describe 'member' do # 1) confirmed # 2) ordered by the most recent sign in it 'finds interesting members' do - @member1 = FactoryGirl.create(:geolocated_member) - @member2 = FactoryGirl.create(:geolocated_member) - @member3 = FactoryGirl.create(:geolocated_member) + @member1 = FactoryGirl.create(:london_member) + @member2 = FactoryGirl.create(:london_member) + @member3 = FactoryGirl.create(:london_member) @member4 = FactoryGirl.create(:unconfirmed_member) @member1.updated_at = 3.days.ago diff --git a/spec/views/home/index_spec.rb b/spec/views/home/index_spec.rb index b75f6b491..e123927f5 100644 --- a/spec/views/home/index_spec.rb +++ b/spec/views/home/index_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe 'home/index.html.haml', :type => "view" do context 'logged out' do before(:each) do - @member = FactoryGirl.create(:geolocated_member) + @member = FactoryGirl.create(:london_member) @member.updated_at = 2.days.ago @post = FactoryGirl.create(:post, :author => @member) @planting = FactoryGirl.create(:planting, :garden => @member.gardens.first) @@ -35,7 +35,7 @@ describe 'home/index.html.haml', :type => "view" do context 'logged in' do before(:each) do - @member = FactoryGirl.create(:geolocated_member) + @member = FactoryGirl.create(:london_member) controller.stub(:current_user) { @member } sign_in @member assign(:member, @member) diff --git a/spec/views/members/index.html.haml_spec.rb b/spec/views/members/index.html.haml_spec.rb index 3da0b4f40..22fd9c04f 100644 --- a/spec/views/members/index.html.haml_spec.rb +++ b/spec/views/members/index.html.haml_spec.rb @@ -6,7 +6,7 @@ describe "members/index" do page = 1 per_page = 2 total_entries = 2 - @member = FactoryGirl.create(:geolocated_member) + @member = FactoryGirl.create(:london_member) members = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| pager.replace([ @member, @member ]) end diff --git a/spec/views/members/nearby.html.haml_spec.rb b/spec/views/members/nearby.html.haml_spec.rb index 8d7342005..2992e21d5 100644 --- a/spec/views/members/nearby.html.haml_spec.rb +++ b/spec/views/members/nearby.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe "members/nearby" do before(:each) do - @member = FactoryGirl.create(:geolocated_member) + @member = FactoryGirl.create(:london_member) @nearby_members = [FactoryGirl.create(:member)] end diff --git a/spec/views/members/show.html.haml_spec.rb b/spec/views/members/show.html.haml_spec.rb index ed03dcb4c..6b9c5b767 100644 --- a/spec/views/members/show.html.haml_spec.rb +++ b/spec/views/members/show.html.haml_spec.rb @@ -140,7 +140,7 @@ describe "members/show" do context "geolocations" do before(:each) do - @member = FactoryGirl.create(:geolocated_member) + @member = FactoryGirl.create(:london_member) render end it "shows the location" do diff --git a/spec/views/plantings/show.html.haml_spec.rb b/spec/views/plantings/show.html.haml_spec.rb index 8eabcd535..414209f1d 100644 --- a/spec/views/plantings/show.html.haml_spec.rb +++ b/spec/views/plantings/show.html.haml_spec.rb @@ -57,7 +57,7 @@ describe "plantings/show" do context "location set" do before(:each) do controller.stub(:current_user) { nil } - @member = FactoryGirl.create(:geolocated_member) + @member = FactoryGirl.create(:london_member) create_planting_for(@member) render end From 38246bd00bc496313b4cbd3f95d82d978154c401 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 25 Apr 2013 23:32:00 +0100 Subject: [PATCH 32/57] Add a dropdown to select units on members/nearby. --- app/views/members/nearby.html.haml | 2 +- spec/views/members/nearby.html.haml_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/members/nearby.html.haml b/app/views/members/nearby.html.haml index 77cc75fd1..68da6f4e3 100644 --- a/app/views/members/nearby.html.haml +++ b/app/views/members/nearby.html.haml @@ -6,7 +6,7 @@ = form_tag(nearby_members_path, :method => :get, :class => 'form-inline') do = label_tag :distance, "Find members within", :class => 'control-label' = text_field_tag :distance, @distance, :class => 'input-mini' - - #= select_tag :units, options_for_select(["miles" => :mi, "km" => :km], @units), :width => "2em", :class => 'input-mini' + = select_tag :units, options_for_select({"miles" => :mi, "km" => :km}, @units), :width => "2em", :class => 'input-mini' = label_tag :location, "miles of", :class => 'control-label' = text_field_tag :location, @location = submit_tag "Search", :class => 'btn btn-primary' diff --git a/spec/views/members/nearby.html.haml_spec.rb b/spec/views/members/nearby.html.haml_spec.rb index 2992e21d5..782003f4a 100644 --- a/spec/views/members/nearby.html.haml_spec.rb +++ b/spec/views/members/nearby.html.haml_spec.rb @@ -22,6 +22,12 @@ describe "members/nearby" do assert_select "#distance", :value => "100" end + it "shows a dropdown with miles and km" do + assert_select "select#units" + assert_select "select#units option[value=km]" + assert_select "select#units option[value=mi]" + end + it "shows the names of nearby members" do @nearby_members.each do |m| rendered.should contain m.login_name From 59a44be34b22ea649e957dac8cb03fbdcc8c9cfc Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 26 Apr 2013 13:18:53 +1000 Subject: [PATCH 33/57] added CONTRIBUTING.md --- CONTRIBUTING.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..3160d39b5 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +Thanks for contributing to Growstuff! We have different contribution +guidelines depending on whether your change is a small one (a one-line +bugfix or similar) or a larger one. + +## Small changes (no more than a couple of lines) + +Send us a pull request! We will get one of our pairs of coders to +review it. + +If you are interested in becoming a more regular contributor or working +on larger features, please see the [Growstuff +wiki](http://wiki.growstuff.org/) for more information. + +## Larger changes + +Growstuff does pair programming (two coders working together) for all +significant changes. This means that if you submit a pull request and +weren't working in a pair, we can't merge it into the project as-is. + +If you would like to work on any larger change, we would appreciate it +if you would get in touch with us first, preferably via our [mailing +list](http://lists.growstuff.org/mailman/listinfo/discuss), and talk to +us about it first. We'll try and hook you up with a partner so you can +work as a pair, either in person or remotely depending on where you are. +The [Growstuff wiki](http://wiki.growstuff.org/) has lots more +information on our dev process, if you're interested. + +If you submit a significant change without working in a pair, we will +treat your work as an experimental "spike" and get one of our pairs of +programmers to look over it and maybe use what you've done as the basis +for re-implementing it using our processes. **We'd much rather work with +you, so please talk to us first!** + From ddde2d30e3299fdb67a62ccb445a01680292a046 Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 26 Apr 2013 13:23:44 +1000 Subject: [PATCH 34/57] minor wording changes --- CONTRIBUTING.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3160d39b5..b43c0d134 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,12 +18,13 @@ significant changes. This means that if you submit a pull request and weren't working in a pair, we can't merge it into the project as-is. If you would like to work on any larger change, we would appreciate it -if you would get in touch with us first, preferably via our [mailing +if you would get in touch with us, preferably via our [mailing list](http://lists.growstuff.org/mailman/listinfo/discuss), and talk to us about it first. We'll try and hook you up with a partner so you can work as a pair, either in person or remotely depending on where you are. The [Growstuff wiki](http://wiki.growstuff.org/) has lots more -information on our dev process, if you're interested. +information on our dev process, to get you started if you would like to +join us. If you submit a significant change without working in a pair, we will treat your work as an experimental "spike" and get one of our pairs of From 70fa93ab420f7605fff230f7f78683c81343b277 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Fri, 26 Apr 2013 14:27:35 +0100 Subject: [PATCH 35/57] Replace tabs with spaces. --- app/controllers/members_controller.rb | 8 ++++---- spec/views/members/nearby.html.haml_spec.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index a55330ebc..913e7080c 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -37,9 +37,9 @@ class MembersController < ApplicationController @location = nil end - if !params[:distance].blank? - @distance = params[:distance] - else + if !params[:distance].blank? + @distance = params[:distance] + else @distance = 100 end @@ -49,7 +49,7 @@ class MembersController < ApplicationController @units = :km end - @nearby_members = @location ? Member.near(@location, @distance, :units => @units) : [] + @nearby_members = @location ? Member.near(@location, @distance, :units => @units) : [] respond_to do |format| format.html # nearby.html.haml format.json { render json: @nearby_members } diff --git a/spec/views/members/nearby.html.haml_spec.rb b/spec/views/members/nearby.html.haml_spec.rb index 782003f4a..c00ab7b9b 100644 --- a/spec/views/members/nearby.html.haml_spec.rb +++ b/spec/views/members/nearby.html.haml_spec.rb @@ -19,7 +19,7 @@ describe "members/nearby" do end it "shows the default distance in the textbox" do - assert_select "#distance", :value => "100" + assert_select "#distance", :value => "100" end it "shows a dropdown with miles and km" do From 5b2dbc571e05ea762f34a4121f57ae48898592b4 Mon Sep 17 00:00:00 2001 From: Skud Date: Sat, 27 Apr 2013 10:23:32 +1000 Subject: [PATCH 36/57] security fix: check ENV for rails secret token --- config/initializers/secret_token.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 57bd5fc79..8ebcc27d3 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -4,4 +4,4 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -Growstuff::Application.config.secret_token = '6b61c7a7c5f5684945c445d80ea3df725ee2bb3101a3a57a4bec349657e092a562aa714cb4706c038d7fb1bdbd497c4b103aa1247f3bdf79044e03363ea8ee50' +Growstuff::Application.config.secret_token = ENV['RAILS_SECRET_TOKEN'] || "this is not a real secret token but it's here to make life easier for developers" From 58482bfbc9a2037f4dbd561c320f62ca0955d456 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 29 Apr 2013 09:39:30 +1000 Subject: [PATCH 37/57] added contact link to footer --- app/controllers/about_controller.rb | 2 ++ app/views/about/contact.html.haml | 17 +++++++++++++++++ app/views/layouts/_footer.html.haml | 1 + config/routes.rb | 2 ++ spec/views/about/contact_spec.rb | 12 ++++++++++++ spec/views/layouts/_footer_spec.rb | 1 + 6 files changed, 35 insertions(+) create mode 100644 app/controllers/about_controller.rb create mode 100644 app/views/about/contact.html.haml create mode 100644 spec/views/about/contact_spec.rb diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb new file mode 100644 index 000000000..f1549add2 --- /dev/null +++ b/app/controllers/about_controller.rb @@ -0,0 +1,2 @@ +class AboutController < ApplicationController +end diff --git a/app/views/about/contact.html.haml b/app/views/about/contact.html.haml new file mode 100644 index 000000000..c4de94d5c --- /dev/null +++ b/app/views/about/contact.html.haml @@ -0,0 +1,17 @@ +-content_for :title, 'Contact' + +%dl + %dt General contact email + %dd= link_to 'info@growstuff.org', 'mailto:info@growstuff.org' +%dl + %dt + Support and accounts enquiries (not covered by the + =succeed ")" do + =link_to 'FAQ', url_for(:controller => '/support') + %dd= link_to 'support@growstuff.org', 'mailto:support@growstuff.org' +%dl + %dt Media/Press enquiries + %dd= link_to 'media@growstuff.org', 'mailto:media@growstuff.org' +%dl + %dt Twitter + %dd= link_to '@Growstuff', 'http:/twitter.com/Growstuff' diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 9ca101d7a..88d130a1e 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -4,6 +4,7 @@ .container %ul.nav %li= link_to "About", "http://wiki.growstuff.org" + %li= link_to "Contact", url_for(:controller => '/about', :action => 'contact') %li= link_to "Terms of Service", url_for(:controller => '/policy', :action => 'tos') %li= link_to "Privacy Policy", url_for(:controller => %'/policy', :action => 'privacy') %li= link_to "Community Guidelines", url_for(:controller => '/policy', :action => 'community') diff --git a/config/routes.rb b/config/routes.rb index 4373efb3b..cf757e9af 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -80,5 +80,7 @@ Growstuff::Application.routes.draw do match '/policy/:action' => 'policy#:action' match '/support' => 'support#index' match '/support/:action' => 'support#:action' + match '/about' => 'about#index' + match '/about/:action' => 'about#:action' end diff --git a/spec/views/about/contact_spec.rb b/spec/views/about/contact_spec.rb new file mode 100644 index 000000000..85d232126 --- /dev/null +++ b/spec/views/about/contact_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe 'about/contact.html.haml', :type => "view" do + before(:each) do + render + end + + it 'should show support faq' do + render + rendered.should contain 'General contact email' + end +end diff --git a/spec/views/layouts/_footer_spec.rb b/spec/views/layouts/_footer_spec.rb index a746f2e70..c3dc3a9b7 100644 --- a/spec/views/layouts/_footer_spec.rb +++ b/spec/views/layouts/_footer_spec.rb @@ -8,6 +8,7 @@ describe 'layouts/_footer.html.haml', :type => "view" do it 'should have links in footer' do rendered.should contain 'About' + rendered.should contain 'Contact' assert_select("a[href=/policy/tos]", 'Terms of Service') assert_select("a[href=/policy/privacy]", 'Privacy Policy') assert_select("a[href=/policy/community]", 'Community Guidelines') From b471ce757666c8014b5a3bef58581e17bffaa2e7 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 29 Apr 2013 09:43:50 +1000 Subject: [PATCH 38/57] removed Courtney from about section --- app/views/support/index.html.haml | 4 ++-- spec/views/support/index_spec.rb | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/views/support/index.html.haml b/app/views/support/index.html.haml index 70ead408a..24a41dd04 100644 --- a/app/views/support/index.html.haml +++ b/app/views/support/index.html.haml @@ -5,8 +5,8 @@ ### Who runs Growstuff? - Growstuff is run by Alex Bayley ([Skud](/members/skud)) and Courtney - Webster ([phazel](/members/phazel)), two software developers from Melbourne, Australia. + Growstuff is run by Alex Bayley ([Skud](/members/skud)) an open source + software developer and keen veggie gardener from Melbourne, Australia. ### How did Growstuff get started? diff --git a/spec/views/support/index_spec.rb b/spec/views/support/index_spec.rb index 7945ff5d3..0c7491ed7 100644 --- a/spec/views/support/index_spec.rb +++ b/spec/views/support/index_spec.rb @@ -6,7 +6,11 @@ describe 'support/index.html.haml', :type => "view" do end it 'should show support faq' do - render rendered.should contain 'About Growstuff' end + + it 'should not mention Courtney any more' do + rendered.should_not contain 'Courtney' + rendered.should_not contain 'phazel' + end end From c98ff6a879cbbc8f68d2d6d8ec5de61995f3b5cb Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 29 Apr 2013 10:39:29 +1000 Subject: [PATCH 39/57] Added continuous deployment script Also: - removed notifications (they weren't really working for us) - added rvm line as per suggestion by travis-lint --- .travis.yml | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index d350b77ee..1ea54e202 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,29 @@ +--- language: ruby +rvm: + - 1.9.3 script: - - bundle exec rake db:migrate --trace - - bundle exec rspec spec/ +- bundle exec rake db:migrate --trace +- bundle exec rspec spec/ -notifications: - recipients: - - discuss@lists.growstuff.org - email: - on_success: change - on_failure: always - irc: - channels: - - "irc.parrot.org#growstuff" - on_success: change - on_failure: change +after_success: + - if [[ "$TRAVIS_BRANCH" == "dev" ]]; then git remote add heroku git@heroku.com:growstuff-dev.git + - wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh + - echo "Host heroku.com" >> ~/.ssh/config + - echo " StrictHostKeyChecking no" >> ~/.ssh/config + - echo " CheckHostIP no" >> ~/.ssh/config + - echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config + - heroku keys:clear + - yes | heroku keys:add + - yes | git push heroku dev:master + - yes | heroku run rake db:migrate + - yes | heroku restart + - fi + +env: + global: + - secure: ! 'LihQ5mCdGmQr9hXeh0yGO0YQH8fgpQ6govovNI2lPzchLD79R0T/m8UgcDmP + + R+/rlOoZtxxaBt+kO5ueWUTa7+PF2a9Yy3N+WozrxHL1sW0NXY6X82ZERwxA + + ekXwH2PqCWqR5x2+dOgvz2B3MdaE5piMiXz3lORbxXv5M5w9skw=' From 9ba86cd674dc4e83847db752aaac76f360712e35 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 29 Apr 2013 11:01:22 +1000 Subject: [PATCH 40/57] actually let's have a specific deploy user for this --- .travis.yml | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1ea54e202..25bd15cd6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,27 @@ --- language: ruby rvm: - - 1.9.3 +- 1.9.3 script: - bundle exec rake db:migrate --trace - bundle exec rspec spec/ - after_success: - - if [[ "$TRAVIS_BRANCH" == "dev" ]]; then git remote add heroku git@heroku.com:growstuff-dev.git - - wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh - - echo "Host heroku.com" >> ~/.ssh/config - - echo " StrictHostKeyChecking no" >> ~/.ssh/config - - echo " CheckHostIP no" >> ~/.ssh/config - - echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config - - heroku keys:clear - - yes | heroku keys:add - - yes | git push heroku dev:master - - yes | heroku run rake db:migrate - - yes | heroku restart - - fi - +- if [[ "$TRAVIS_BRANCH" == "dev" ]]; then git remote add heroku git@heroku.com:growstuff-dev.git +- wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh +- echo "Host heroku.com" >> ~/.ssh/config +- echo " StrictHostKeyChecking no" >> ~/.ssh/config +- echo " CheckHostIP no" >> ~/.ssh/config +- echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config +- heroku keys:clear +- yes | heroku keys:add +- yes | git push heroku dev:master +- yes | heroku run rake db:migrate +- yes | heroku restart +- fi env: global: - - secure: ! 'LihQ5mCdGmQr9hXeh0yGO0YQH8fgpQ6govovNI2lPzchLD79R0T/m8UgcDmP + - secure: ! 'arc+bJUPRjyUVcAo0QPEJFXdJJDnyccPhSfGtD8rpg6rg9stqgFYfspTvMz6 - R+/rlOoZtxxaBt+kO5ueWUTa7+PF2a9Yy3N+WozrxHL1sW0NXY6X82ZERwxA + 9hW8mf8z5HU69x2PBSARy4mZDIPfPfX87HQUkLIWmxtpwDRTFSEJQADAI8Ea - ekXwH2PqCWqR5x2+dOgvz2B3MdaE5piMiXz3lORbxXv5M5w9skw=' + QPKFoAyJB8FEZ2ecRNzuZzSCHL4z7qRIuKyE2wHdMMTr9X8kCJM=' From da5e79365df14a975ffe7a2c5667a2d4702de384 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 29 Apr 2013 11:10:58 +1000 Subject: [PATCH 41/57] fixed linebreaks in "secure" line (what's generated by travis-encrypt --add seems to be wrong.) --- .travis.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 25bd15cd6..e9fdb44d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,8 +20,4 @@ after_success: - fi env: global: - - secure: ! 'arc+bJUPRjyUVcAo0QPEJFXdJJDnyccPhSfGtD8rpg6rg9stqgFYfspTvMz6 - - 9hW8mf8z5HU69x2PBSARy4mZDIPfPfX87HQUkLIWmxtpwDRTFSEJQADAI8Ea - - QPKFoAyJB8FEZ2ecRNzuZzSCHL4z7qRIuKyE2wHdMMTr9X8kCJM=' + - secure: "WdBJxngS0ChPZnCOdGn0DJ41NmQ1k7uOhfdXjyNp5DyrXcY8oOgJ3iK16eJh\nPDcTDJja9vRuNc8qlBm3p6OS6keWu2PUdgarAf2nztgit5cXJaE/z0W4tYTo\nfFdwCvEuh2hWIQ0yjPz7eRx5Y0L9fnA3GxPZq0Xcvg62mKij5xY=" From eac1448fcdbf5ea5e47fc6cf114dbfef70100760 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 29 Apr 2013 11:30:01 +1000 Subject: [PATCH 42/57] trying to get keys working --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e9fdb44d6..88d1ea0e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,12 +12,11 @@ after_success: - echo " StrictHostKeyChecking no" >> ~/.ssh/config - echo " CheckHostIP no" >> ~/.ssh/config - echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config -- heroku keys:clear - yes | heroku keys:add -- yes | git push heroku dev:master -- yes | heroku run rake db:migrate -- yes | heroku restart +- git push heroku dev:master +- heroku run rake db:migrate +- heroku restart - fi env: global: - - secure: "WdBJxngS0ChPZnCOdGn0DJ41NmQ1k7uOhfdXjyNp5DyrXcY8oOgJ3iK16eJh\nPDcTDJja9vRuNc8qlBm3p6OS6keWu2PUdgarAf2nztgit5cXJaE/z0W4tYTo\nfFdwCvEuh2hWIQ0yjPz7eRx5Y0L9fnA3GxPZq0Xcvg62mKij5xY=" + - secure: "WdBJxngS0ChPZnCOdGn0DJ41NmQ1k7uOhfdXjyNp5DyrXcY8oOgJ3iK16eJh\nPDcTDJja9vRuNc8qlBm3p6OS6keWu2PUdgarAf2nztgit5cXJaE/z0W4tYTo\nfFdwCvEuh2hWIQ0yjPz7eRx5Y0L9fnA3GxPZq0Xcvg62mKij5xY=" From a6ab80fd8ba0bba3d5542210124a28c88bbf9ce3 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 29 Apr 2013 11:55:15 +1000 Subject: [PATCH 43/57] another try at getting keys working --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 88d1ea0e6..0bfa1fd78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,4 +19,4 @@ after_success: - fi env: global: - - secure: "WdBJxngS0ChPZnCOdGn0DJ41NmQ1k7uOhfdXjyNp5DyrXcY8oOgJ3iK16eJh\nPDcTDJja9vRuNc8qlBm3p6OS6keWu2PUdgarAf2nztgit5cXJaE/z0W4tYTo\nfFdwCvEuh2hWIQ0yjPz7eRx5Y0L9fnA3GxPZq0Xcvg62mKij5xY=" + secure: "QFQbCdNGyjeatp/H0j0y0oGiue45fpG2w6eA2QAbq2RmvhabgXbd5WIobN90\ndrae3S7TRxPDpMpus90icykX6EzOTLXCEvaC4rh9pCcRktj3SZqq5b9rVTvs\n1MvlS6HhtsVqsrKjQUb0WmPpnganIzTs0RtGaQspo2joPJO18A4=" From f336b8811184747cc9504ce90c880c6e77777b88 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 29 Apr 2013 12:18:58 +1000 Subject: [PATCH 44/57] commented out auto-deployment stuff for now --- .travis.yml | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0bfa1fd78..0928a1e53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,18 +5,21 @@ rvm: script: - bundle exec rake db:migrate --trace - bundle exec rspec spec/ -after_success: -- if [[ "$TRAVIS_BRANCH" == "dev" ]]; then git remote add heroku git@heroku.com:growstuff-dev.git -- wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh -- echo "Host heroku.com" >> ~/.ssh/config -- echo " StrictHostKeyChecking no" >> ~/.ssh/config -- echo " CheckHostIP no" >> ~/.ssh/config -- echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config -- yes | heroku keys:add -- git push heroku dev:master -- heroku run rake db:migrate -- heroku restart -- fi + +# after_success: +# - if [[ "$TRAVIS_BRANCH" == "dev" ]]; then git remote add heroku git@heroku.com:growstuff-dev.git +# - wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh +# - echo "Host heroku.com" >> ~/.ssh/config +# - echo " StrictHostKeyChecking no" >> ~/.ssh/config +# - echo " CheckHostIP no" >> ~/.ssh/config +# - echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config +# - heroku keys:clear +# - yes | heroku keys:add +# - yes | git push heroku dev:master +# - heroku run rake db:migrate +# - heroku restart +# - fi + env: global: secure: "QFQbCdNGyjeatp/H0j0y0oGiue45fpG2w6eA2QAbq2RmvhabgXbd5WIobN90\ndrae3S7TRxPDpMpus90icykX6EzOTLXCEvaC4rh9pCcRktj3SZqq5b9rVTvs\n1MvlS6HhtsVqsrKjQUb0WmPpnganIzTs0RtGaQspo2joPJO18A4=" From c0c7b5f93ca4f15f7b0a39544d585a04e8a8aa08 Mon Sep 17 00:00:00 2001 From: Lilly Date: Mon, 29 Apr 2013 16:16:20 +1000 Subject: [PATCH 45/57] Added full stop to end of link to gravatar.com --- app/views/devise/registrations/edit.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 235658336..32ac5612c 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -25,7 +25,8 @@ %p %br/ To change your profile picture, visit - = link_to 'gravatar.com', "http://gravatar.com/" + = succeed "." do + = link_to 'gravatar.com', "http://gravatar.com/" .control-group =f.label :location, 'Your location', :class => 'control-label' From 2b84fa8bad5d7070df31cd26348643b445e9876e Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 29 Apr 2013 21:30:26 +0100 Subject: [PATCH 46/57] Show previous comments when creating a comment. - Move "show previous comments" into a partial - invoke said partial from the new comment form - add tests. --- app/controllers/comments_controller.rb | 1 + app/views/comments/_form.html.haml | 2 ++ app/views/posts/_comments.html.haml | 11 ++++++++++ app/views/posts/show.html.haml | 11 +--------- spec/controllers/comments_controller_spec.rb | 7 +++++++ spec/factories/comments.rb | 3 ++- spec/views/comments/new.html.haml_spec.rb | 22 +++++++++++++++----- 7 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 app/views/posts/_comments.html.haml diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 53e453410..ed90a6213 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -29,6 +29,7 @@ class CommentsController < ApplicationController @post = Post.find_by_id(params[:post_id]) if @post + @comments = @post.comments respond_to do |format| format.html # new.html.erb format.json { render json: @comment } diff --git a/app/views/comments/_form.html.haml b/app/views/comments/_form.html.haml index e023bc968..06b6d0f8b 100644 --- a/app/views/comments/_form.html.haml +++ b/app/views/comments/_form.html.haml @@ -1,5 +1,7 @@ = render :partial => "posts/single", :locals => { :post => @post || @comment.post, :subject => true } += render :partial => "posts/comments" + %h2 Your comment = form_for @comment do |f| - if @comment.errors.any? diff --git a/app/views/posts/_comments.html.haml b/app/views/posts/_comments.html.haml new file mode 100644 index 000000000..f68ed96c0 --- /dev/null +++ b/app/views/posts/_comments.html.haml @@ -0,0 +1,11 @@ +%a{:name => "comments"} +- if !@comments.empty? + %h2 + =pluralize(@comments.length, "comment") + - @comments.each do |c| + = render :partial => "comments/single", :locals => { :comment => c } + +- else + %h2 There are no comments yet + + diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index 532b93b15..607e9f1f7 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -10,16 +10,7 @@ = link_to 'Delete Post', @post, method: :delete, | data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini' - -%a{:name => "comments"} -- if @comments - %h2 - =pluralize(@comments.length, "comment") - - @comments.each do |c| - = render :partial => "comments/single", :locals => { :comment => c } - -- else - %h2 There are no comments yet += render :partial => "comments", :locals => { :post => @post } - if can? :create, Comment .post-actions diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index a3b085553..02cc2960e 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -38,6 +38,13 @@ describe CommentsController do assigns(:post).should eq(post) end + it "assigns the old comments as @comments" do + post = FactoryGirl.create(:post) + old_comment = FactoryGirl.create(:comment, :post => post) + get :new, {:post_id => post.id} + assigns(:comments).should eq [old_comment] + end + it "dies if no post specified" do get :new response.should redirect_to(root_url) diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index 404ac5313..b1a88a7a6 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -2,6 +2,7 @@ FactoryGirl.define do factory :comment do post author - body "OMG LOL" + sequence(:body) { |n| "OMG LOL #{n}" } # because our commenters are more + # polite than YouTube's end end diff --git a/spec/views/comments/new.html.haml_spec.rb b/spec/views/comments/new.html.haml_spec.rb index 1fe66ef5f..90b5e1cb3 100644 --- a/spec/views/comments/new.html.haml_spec.rb +++ b/spec/views/comments/new.html.haml_spec.rb @@ -3,20 +3,32 @@ require 'spec_helper' describe "comments/new" do before(:each) do controller.stub(:current_user) { nil } - assign(:comment, FactoryGirl.create(:comment)) + @post = FactoryGirl.create(:post) + @previous_comment = FactoryGirl.create(:comment, :post => @post) + assign(:comment, FactoryGirl.create(:comment, :post => @post)) + assign(:comments, [@previous_comment]) + render + end + + it "shows the text of the post under discussion" do + rendered.should contain @post.body + end + + it "shows previous comments" do + rendered.should contain @previous_comment.body + end + + it "shows the correct comment count" do + rendered.should contain "1 comment" end it "renders new comment form" do - render - - # Run the generator again with the --webrat flag if you want to use webrat matchers assert_select "form", :action => comments_path, :method => "post" do assert_select "textarea#comment_body", :name => "comment[body]" end end it 'shows markdown help' do - render rendered.should contain 'Markdown' end From c53dd6797fdf2bba2e1409175794e6840472b470 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Mon, 29 Apr 2013 21:44:30 +0100 Subject: [PATCH 47/57] Show other comments on post when editing a comment. --- app/controllers/comments_controller.rb | 1 + app/views/posts/_comments.html.haml | 2 +- spec/controllers/comments_controller_spec.rb | 9 +++++++++ spec/views/posts/show.html.haml_spec.rb | 3 --- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index ed90a6213..d6bc30bd1 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -43,6 +43,7 @@ class CommentsController < ApplicationController # GET /comments/1/edit def edit @comment = Comment.find(params[:id]) + @comments = @comment.post.comments end # POST /comments diff --git a/app/views/posts/_comments.html.haml b/app/views/posts/_comments.html.haml index f68ed96c0..c06124014 100644 --- a/app/views/posts/_comments.html.haml +++ b/app/views/posts/_comments.html.haml @@ -1,5 +1,5 @@ %a{:name => "comments"} -- if !@comments.empty? +- if @comments %h2 =pluralize(@comments.length, "comment") - @comments.each do |c| diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 02cc2960e..587d24407 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -57,6 +57,15 @@ describe CommentsController do get :edit, {:id => comment.to_param} assigns(:comment).should eq(comment) end + + it "assigns previous comments as @comments" do + post = FactoryGirl.create(:post) + old_comment = FactoryGirl.create(:comment, :post => post) + comment = FactoryGirl.create(:comment, :post => post) + get :edit, {:id => comment.to_param} + assigns(:comments).should eq([old_comment, comment]) + end + end describe "POST create" do diff --git a/spec/views/posts/show.html.haml_spec.rb b/spec/views/posts/show.html.haml_spec.rb index 34c21f9e0..d9682b015 100644 --- a/spec/views/posts/show.html.haml_spec.rb +++ b/spec/views/posts/show.html.haml_spec.rb @@ -107,7 +107,4 @@ describe "posts/show" do end - - - end From c56666e68fe548491131aa105001fde8913b0b59 Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 30 Apr 2013 10:11:22 +1000 Subject: [PATCH 48/57] added credentials.example --- credentials.example | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 credentials.example diff --git a/credentials.example b/credentials.example new file mode 100755 index 000000000..3f3f00ef3 --- /dev/null +++ b/credentials.example @@ -0,0 +1,28 @@ +#!/bin/bash + +# This file is an empty sample file which you (i.e. Growstuff +# developers) can copy and use to store your API credentials for +# external APIs used by the Growstuff application. + +# To use this file, simply copy it to credentials.sh (which is +# .gitignore'd) and then fill in whatever credentials you need. Then in +# the window where you run "rails s", first run: +# +# source credentials.sh +# +# If you then run "rails s", it will have all the environment variables +# available to it. + +### CREDENTIALS ### + +# Mandrill is used to send transactional email (eg. signup +# confirmations). If using Heroku connect to Mandrill via Heroku addons +# list then go to tools menu (upper right) and choose "SMTP and API +# Credentials" +export MANDRILL_USERNAME="" +export MANDRILL_APIKEY="" + +# Used for connecting member accounts to Twitter +# Get Twitter key from https://dev.twitter.com/apps +export TWITTER_KEY="" +export TWITTER_SECRET="" From 8bc4d8f4ce8b85c076695c6911227dbd69c454dc Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 30 Apr 2013 10:39:57 +0100 Subject: [PATCH 49/57] Use km by default. --- config/initializers/geocoder.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 config/initializers/geocoder.rb diff --git a/config/initializers/geocoder.rb b/config/initializers/geocoder.rb new file mode 100644 index 000000000..cd284077b --- /dev/null +++ b/config/initializers/geocoder.rb @@ -0,0 +1 @@ +Geocoder.configure(:units => :km) From 40b9104094d82f4bf3f5b1b23cb2606b710c4620 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 30 Apr 2013 10:43:40 +0100 Subject: [PATCH 50/57] Make units dropdown wide enough to contain "miles". It's now "miles" wide. Hehehe. --- app/views/members/nearby.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/members/nearby.html.haml b/app/views/members/nearby.html.haml index 68da6f4e3..cbcf51da6 100644 --- a/app/views/members/nearby.html.haml +++ b/app/views/members/nearby.html.haml @@ -6,7 +6,7 @@ = form_tag(nearby_members_path, :method => :get, :class => 'form-inline') do = label_tag :distance, "Find members within", :class => 'control-label' = text_field_tag :distance, @distance, :class => 'input-mini' - = select_tag :units, options_for_select({"miles" => :mi, "km" => :km}, @units), :width => "2em", :class => 'input-mini' + = select_tag :units, options_for_select({"miles" => :mi, "km" => :km}, @units), :class => 'input-small' = label_tag :location, "miles of", :class => 'control-label' = text_field_tag :location, @location = submit_tag "Search", :class => 'btn btn-primary' From a41c60b7deb0fb2a686ce0f266f56fcaa6d0570a Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Tue, 30 Apr 2013 10:54:52 +0100 Subject: [PATCH 51/57] Be even more paranoid about params[:units] And save a to_s call while we're at it. --- app/controllers/members_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 913e7080c..6b193a521 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -43,8 +43,8 @@ class MembersController < ApplicationController @distance = 100 end - if params[:units] == "mi" || params[:units] == "km" - @units = params[:units].to_sym + if params[:units] == "mi" + @units = :mi else @units = :km end From df1cded83c16294043bab4be14e79c6299bda82f Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 30 Apr 2013 22:10:05 +1000 Subject: [PATCH 52/57] added flickr key/secret --- credentials.example | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/credentials.example b/credentials.example index 3f3f00ef3..74b7fa9df 100755 --- a/credentials.example +++ b/credentials.example @@ -26,3 +26,8 @@ export MANDRILL_APIKEY="" # Get Twitter key from https://dev.twitter.com/apps export TWITTER_KEY="" export TWITTER_SECRET="" + +# Used for connecting member accounts to Flickr +# Get Flickr key from http://www.flickr.com/services/apps/create/apply/ +export FLICKR_KEY="" +export FLICKR_SECRET="" From d006854a6c223a590f37cec1f5d1c7d0f3201fa3 Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 30 Apr 2013 22:55:40 +1000 Subject: [PATCH 53/57] added omniauth-flickr gem --- Gemfile | 1 + Gemfile.lock | 3 +++ config/initializers/omniauth.rb | 1 + 3 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index ba7e4a619..3f4318236 100644 --- a/Gemfile +++ b/Gemfile @@ -78,6 +78,7 @@ gem 'bootstrap-datepicker-rails' # For connecting to other services (eg Twitter) gem 'omniauth' gem 'omniauth-twitter' +gem 'omniauth-flickr' gem 'authbuttons-rails' # for phusion passenger (i.e. mod_rails) on the server diff --git a/Gemfile.lock b/Gemfile.lock index e46fff46f..35ab7f28b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -131,6 +131,8 @@ GEM omniauth (1.1.3) hashie (~> 1.2) rack + omniauth-flickr (0.0.11) + omniauth-oauth (~> 1.0) omniauth-oauth (1.0.1) oauth omniauth (~> 1.0) @@ -255,6 +257,7 @@ DEPENDENCIES less-rails newrelic_rpm omniauth + omniauth-flickr omniauth-twitter passenger pg diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 05d79edae..ad19ed66d 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,3 +1,4 @@ Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] + provider :flickr, ENV['FLICKR_KEY'], ENV['FLICKR_SECRET'] end From 45935c6e3857fb769eb4b96b266363cec1e1572e Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 30 Apr 2013 23:01:18 +1000 Subject: [PATCH 54/57] connect to flickr --- app/controllers/authentications_controller.rb | 13 ++++++++++- app/controllers/members_controller.rb | 1 + app/controllers/registrations_controller.rb | 1 + app/views/devise/registrations/edit.html.haml | 8 +++++++ spec/controllers/member_controller_spec.rb | 8 ++++++- .../registrations_controller_spec.rb | 6 +++++ spec/factories/authentications.rb | 5 +++++ spec/views/devise/registrations/edit_spec.rb | 22 +++++++++++++++++++ 8 files changed, 62 insertions(+), 2 deletions(-) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index aa3498fd9..96456d996 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -16,10 +16,21 @@ class AuthenticationsController < ApplicationController auth = request.env['omniauth.auth'] @authentication = nil if auth + + name = '' + case auth['provider'] + when 'twitter' + name = auth['info']['nickname'] + when 'flickr' + name = auth['info']['name'] + else + name = auth['info']['name'] + end + @authentication = current_member.authentications.find_or_create_by_provider_and_uid( :provider => auth['provider'], :uid => auth['uid'], - :name => auth['info']['nickname'] || auth['info']['name'], + :name => name, :token => auth['credentials']['token'], :secret => auth['credentials']['secret']) flash[:notice] = "Authentication successful." diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 6b193a521..d05c85f01 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -13,6 +13,7 @@ class MembersController < ApplicationController def show @member = Member.confirmed.find(params[:id]) @twitter_auth = @member.authentications.find_by_provider('twitter') + @flickr_auth = @member.authentications.find_by_provider('flickr') @posts = @member.posts # The garden form partial is called from the "New Garden" tab; # it requires a garden to be passed in @garden. diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index f863a02f3..e23bebf0c 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -3,6 +3,7 @@ class RegistrationsController < Devise::RegistrationsController def edit @twitter_auth = current_member.authentications.find_by_provider('twitter') + @flickr_auth = current_member.authentications.find_by_provider('flickr') render "edit" end diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 863d912a5..d8a36e1ce 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -52,6 +52,14 @@ = link_to "Disconnect", @twitter_auth, :confirm => "Are you sure you want to remove this connection?", :method => :delete, :class => "remove" - else =link_to 'Connect to Twitter', '/auth/twitter' + %p + - if @flickr_auth + You are connected to Flickr as + = succeed "." do + =link_to @flickr_auth.name, "http://flickr.com/photos/#{@flickr_auth.uid}" + = link_to "Disconnect", @flickr_auth, :confirm => "Are you sure you want to remove this connection?", :method => :delete, :class => "remove" + - else + =link_to 'Connect to Flickr', '/auth/flickr' %h2 Change password %p diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index 738ee1ab5..f15cd049c 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -6,6 +6,7 @@ describe MembersController do @member = FactoryGirl.create(:member) @posts = [ FactoryGirl.create(:post, :author => @member) ] @twitter_auth = FactoryGirl.create(:authentication, :member => @member) + @flickr_auth = FactoryGirl.create(:flickr_authentication, :member => @member) end describe "GET index" do @@ -40,7 +41,12 @@ describe MembersController do it "assigns @twitter_auth" do get :show, {:id => @member.id} - assigns(:posts).should eq(@posts) + assigns(:twitter_auth).should eq(@twitter_auth) + end + + it "assigns @flickr_auth" do + get :show, {:id => @member.id} + assigns(:flickr_auth).should eq(@flickr_auth) end it "doesn't show completely nonsense members" do diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index bc0a93433..0ba0e29e6 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -20,6 +20,12 @@ describe RegistrationsController do get :edit assigns(:twitter_auth).should eq @auth end + + it "picks up the flickr auth" do + @auth = FactoryGirl.create(:flickr_authentication, :member => @member) + get :edit + assigns(:flickr_auth).should eq @auth + end end end diff --git a/spec/factories/authentications.rb b/spec/factories/authentications.rb index 806edbb4b..8b26549f0 100644 --- a/spec/factories/authentications.rb +++ b/spec/factories/authentications.rb @@ -7,5 +7,10 @@ FactoryGirl.define do uid 'foo' secret 'bar' name 'baz' + + factory :flickr_authentication do + provider 'flickr' + uid 'blah@blah' + end end end diff --git a/spec/views/devise/registrations/edit_spec.rb b/spec/views/devise/registrations/edit_spec.rb index d22a3d359..594bb9657 100644 --- a/spec/views/devise/registrations/edit_spec.rb +++ b/spec/views/devise/registrations/edit_spec.rb @@ -59,6 +59,7 @@ describe 'devise/registrations/edit.html.haml', :type => "view" do render assert_select "h2", "Linked accounts" end + context 'not connected to twitter' do it 'has a link to connect' do render @@ -78,6 +79,27 @@ describe 'devise/registrations/edit.html.haml', :type => "view" do assert_select "a", :href => @twitter_auth, :text => "Disconnect" end end + + context 'not connected to flickr' do + it 'has a link to connect' do + render + assert_select "a", "Connect to Flickr" + end + end + context 'connected to flickr' do + before(:each) do + @flickr_auth = FactoryGirl.create(:flickr_authentication, :member => @member) + render + end + it 'has a link to flickr photostream' do + assert_select "a", :href => "http://flickr.com/photos/#{@flickr_auth.uid}" + end + it 'has a link to disconnect' do + render + assert_select "a", :href => @flickr_auth, :text => "Disconnect" + end + end + end it 'should have a password section' do From e4dd0cba5bf14861e9bd702cb05b7b0ba01ecbba Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 30 Apr 2013 23:07:21 +1000 Subject: [PATCH 55/57] added flickr link to profile page --- app/views/members/show.html.haml | 7 ++++++- spec/views/members/show.html.haml_spec.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 39a7893af..297bac8c7 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -15,7 +15,7 @@ %strong Member since: = @member.created_at.to_s(:date) - - if @twitter_auth || @member.show_email + - if @twitter_auth || @flickr_auth || @member.show_email %h4 Contact - if @twitter_auth @@ -23,6 +23,11 @@ = image_tag "twitter_32.png", :size => "32x32", :alt => 'Twitter logo' =link_to @twitter_auth.name, "http://twitter.com/#{@twitter_auth.name}" + - if @flickr_auth + %p + Flickr: + =link_to @flickr_auth.name, "http://flickr.com/photos/#{@flickr_auth.uid}" + - if @member.show_email %p Email: diff --git a/spec/views/members/show.html.haml_spec.rb b/spec/views/members/show.html.haml_spec.rb index 6b9c5b767..aab5be98b 100644 --- a/spec/views/members/show.html.haml_spec.rb +++ b/spec/views/members/show.html.haml_spec.rb @@ -39,6 +39,22 @@ describe "members/show" do end end + context 'flickr' do + context "no flickr" do + it "doesn't show flickr link" do + render + assert_select "a[href^=http://flickr.com/]", :count => 0 + end + end + context 'has flickr' do + it "shows flickr link" do + @flickr_auth = FactoryGirl.create(:flickr_authentication, :member => @member) + render + assert_select "a", :href => "http://flickr.com/photos/#{@flickr_auth.uid}" + end + end + end + context "gardens and plantings" do before(:each) do @planting = FactoryGirl.create(:planting, :garden => @garden) From 949821a947d431185172784425f08c5d98b0453a Mon Sep 17 00:00:00 2001 From: Skud Date: Thu, 2 May 2013 11:18:46 +1000 Subject: [PATCH 56/57] create admin and wrangler users in dev environment --- db/seeds.rb | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index d05a986fc..427caf22b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -18,8 +18,8 @@ CSV.foreach(Rails.root.join('db', 'seeds', 'crops.csv')) do |row| end puts "Finished loading crops" -puts "Loading test users..." if Rails.env.development? or Rails.env.test? + puts "Loading test users..." (1..3).each do |i| @user = Member.create( :login_name => "test#{i}", @@ -30,5 +30,34 @@ if Rails.env.development? or Rails.env.test? @user.confirm! @user.save! end + puts "Finished loading test users" + + puts "Creating admin role..." + @admin = Role.create(:name => 'Admin') + puts "Creating crop wrangler role..." + @wrangler = Role.create(:name => 'Crop Wrangler') + + puts "Adding admin and crop wrangler members..." + @admin_user = Member.create( + :login_name => "admin1", + :email => "admin1@example.com", + :password => "password1", + :tos_agreement => true + ) + @admin_user.confirm! + @admin_user.roles << @admin + @admin_user.save! + + @wrangler_user = Member.create( + :login_name => "wrangler1", + :email => "wrangler1@example.com", + :password => "password1", + :tos_agreement => true + ) + @wrangler_user.confirm! + @wrangler_user.roles << @wrangler + @wrangler_user.save! + puts "Done!" + end -puts "Finished loading test users" + From c95e722f997d7b2517aa8ea4d3cd5b1af0e6dd1d Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 3 May 2013 15:09:29 +1000 Subject: [PATCH 57/57] added planting counts to crop pages --- app/views/crops/_thumbnail.html.haml | 4 ++++ app/views/crops/show.html.haml | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/views/crops/_thumbnail.html.haml b/app/views/crops/_thumbnail.html.haml index a6c453a1e..5e4c6cb63 100644 --- a/app/views/crops/_thumbnail.html.haml +++ b/app/views/crops/_thumbnail.html.haml @@ -8,6 +8,10 @@ %i %small = crop.scientific_names.first.scientific_name + %br/ + %small + Planted + = pluralize(crop.plantings_count, "time") - else = image_tag('http://placehold.it/150x150', :alt => '', :class => 'img-rounded') Sample crop diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index e3364fa15..3b92068c5 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -2,11 +2,19 @@ .row .span9 - %p - =link_to "Plant this", new_planting_path(:crop_id => @crop.id), :class => 'btn btn-primary' - %h2 Who's growing this? - - @crop.plantings.each do |p| - = render :partial => "plantings/thumbnail", :locals => { :planting => p, :title => 'owner' } + - if @crop.plantings_count > 0 + %p + Planted + = pluralize(@crop.plantings_count, "time") + by #{Growstuff::Application.config.site_name} members + %p= link_to "Plant this", new_planting_path(:crop_id => @crop.id), :class => 'btn btn-primary' + + - @crop.plantings.each do |p| + = render :partial => "plantings/thumbnail", :locals => { :planting => p, :title => 'owner' } + + - else + %p Nobody is growing this yet. You could be the first! + %p= link_to "Plant this", new_planting_path(:crop_id => @crop.id), :class => 'btn btn-primary' .span3 %h4 Scientific names: