diff --git a/.gitignore b/.gitignore index 721b1f830..dafc5e44d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +*.swap *.swp *.swo *~ diff --git a/Gemfile b/Gemfile index f2b895e32..55ecc7a8b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,9 @@ source 'http://rubygems.org' -gem 'rails', '3.0.0.rc' -gem 'bundler', '1.0.0.rc.5' -#gem 'rails', '3.0.0.beta4' -#gem 'bundler', '0.9.26' +#gem 'rails', '3.0.0.rc' +#gem 'bundler', '1.0.0.rc.5' +gem 'rails', '3.0.0.beta4' +gem 'bundler', '0.9.26' #Security gem 'devise', :git => 'http://github.com/BadMinus/devise.git' @@ -40,11 +40,14 @@ group :test do gem 'rspec', '>= 2.0.0.beta.17' gem 'rspec-rails', '2.0.0.beta.17' gem 'mocha' - gem 'webrat' + gem 'webrat', '0.7.2.beta.1' gem 'redgreen' gem 'autotest' gem 'factory_girl_rails' gem 'database_cleaner' + gem 'saucelabs-adapter', '= 0.8.12' + gem 'selenium-rc' + gem 'json' end group :development do diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 28b5de57d..4019b871c 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -14,8 +14,10 @@ class PeopleController < ApplicationController def show @person = current_user.visible_person_by_id(params[:id]) @profile = @person.profile - @posts = Post.find_all_by_person_id(@person.id).paginate :page => params[:page], :order => 'created_at DESC' - @latest_status_message = StatusMessage.newest_for(@person) + + @posts = Post.where(:person_id => @person.id, :_id.in => current_user.visible_post_ids).paginate :page => params[:page], :order => 'created_at DESC' + + @latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last @post_count = @posts.count end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index ae274c142..24c4634b8 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -31,9 +31,10 @@ class RequestsController < ApplicationController end def create + puts params.inspect rel_hash = relationship_flow(params[:request][:destination_url]) Rails.logger.debug("Sending request: #{rel_hash}") - @request = current_user.send_request(rel_hash, params[:request][:group]) + @request = current_user.send_request(rel_hash, params[:request][:group_id]) if @request flash[:notice] = "a friend request was sent to #{@request.destination_url}" diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5d407e724..c6c5c74bc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,16 @@ class UsersController < ApplicationController before_filter :authenticate_user!, :except => [:new, :create] + + def index + @groups_array = current_user.groups.collect{|x| [x.to_s, x.id]} + + unless params[:q] + @people = Person.all + render :index + else + @people = Person.search(params[:q]) + end + end def show @user= User.first(:id => params[:id]) @@ -8,20 +19,19 @@ class UsersController < ApplicationController def edit @user = User.first(:id => params[:id]) + @person = @user.person @profile = @user.profile - @photos = Photo.paginate :page => params[:page], :order => 'created_at DESC' + @photos = Photo.where(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' end def update @user = User.where(:id => params[:id]).first if @user.update_profile(params[:user]) - flash[:notice] = "Successfully updated user." - redirect_to @user + flash[:notice] = "Successfully updated your profile" + redirect_to @user.person else render :action => 'edit' end end - - end diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb new file mode 100644 index 000000000..fd9ff371c --- /dev/null +++ b/app/helpers/people_helper.rb @@ -0,0 +1,11 @@ +module PeopleHelper + + def search_or_index + if params[:q] + " results for #{params[:q]}" + else + " people on this pod" + end + + end +end diff --git a/app/helpers/photos_helper.rb b/app/helpers/photos_helper.rb index b9231fe94..c518ceec5 100644 --- a/app/helpers/photos_helper.rb +++ b/app/helpers/photos_helper.rb @@ -1,7 +1,7 @@ module PhotosHelper def linked_scaled_photo(photo, album) - link_to (image_tag photo.image.url(:scaled_full)), photo_path(album.next_photo(photo)), :rel => "prefetch" + link_to (image_tag photo.url(:scaled_full)), photo_path(album.next_photo(photo)), :rel => "prefetch" end def link_to_prev(photo, album) diff --git a/app/helpers/requests_helper.rb b/app/helpers/requests_helper.rb index 37a5485c4..c0320c0b8 100644 --- a/app/helpers/requests_helper.rb +++ b/app/helpers/requests_helper.rb @@ -29,6 +29,7 @@ module RequestsHelper action = :none url = nil local_person = Person.by_webfinger identifier + puts local_person.inspect if local_person action = (local_person == current_user.person ? :none : :friend) url = local_person.receive_url diff --git a/app/models/group.rb b/app/models/group.rb index 275bbf3a5..a01dcca5f 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -15,6 +15,9 @@ class Group belongs_to :user, :class_name => 'User' timestamps! - + + def to_s + name + end end diff --git a/app/models/post.rb b/app/models/post.rb index e1821d615..8f30586a0 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -31,7 +31,7 @@ class Post #Querying def self.newest_for(person) - self.first(:person_id => person.id, :order => '_id desc') + self.where(:person_id => person.id, :order => '_id desc') end #ENCRYPTION diff --git a/app/models/user.rb b/app/models/user.rb index b90bb9df1..1a02d6ddc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -21,6 +21,7 @@ class User after_create :seed_groups after_save :check_for_tommy + before_validation :do_bad_things ######## Making things work ######## key :email, String #validates_true_for :email, :logic => lambda {self.pivotal_email?} @@ -307,6 +308,12 @@ class User end ###Helpers############ + def self.instantiate!( opts = {} ) + opts[:person][:email] = opts[:email] + opts[:person][:serialized_key] = generate_key + User.create!( opts) + end + def terse_url terse= self.url.gsub(/https?:\/\//, '') terse.gsub!(/www\./, '') @@ -314,6 +321,10 @@ class User terse end + def do_bad_things + self.password_confirmation = self.password + end + def visible_person_by_id( id ) id = ensure_bson id return self.person if id == self.person.id @@ -346,14 +357,22 @@ class User id = ensure_bson person.id groups.select {|group| group.person_ids.include? id} end +<<<<<<< HEAD protected def setup_person self.person.serialized_key ||= generate_key.export +======= + + def setup_person + self.person.serialized_key = generate_key.export +>>>>>>> 2e76987e259ff23455d00c077fd347b4376d7e0e self.person.email = email self.person.save! end + protected + def generate_key OpenSSL::PKey::RSA::generate 1024 end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 006872e5b..da2b73eb8 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -38,6 +38,7 @@ %li.name= link_to current_user.real_name, current_user.person %li= link_to "requests (#{@request_count})", requests_path, :class => new_request(@request_count) %li= link_to "settings", edit_user_path(current_user) + %li= link_to "search", users_path %li= link_to "logout", destroy_user_session_path - else = link_to "login", new_user_session_path diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml index cfc12dcc9..8b7b488ec 100644 --- a/app/views/people/index.html.haml +++ b/app/views/people/index.html.haml @@ -1,10 +1,10 @@ -%h1.big_text - .back - = link_to '⇧ home', root_path - Friends - .button.right - = link_to 'Add Friend', requests_path - +/ %h1.big_text +/ .back +/ = link_to '⇧ home', root_path +/ Friends +/ .button.right +/ = link_to 'Add Friend', requests_path += @people.count.to_s + search_or_index %table %tr %th real name diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index af8eb86ab..39c60ec7e 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -5,7 +5,8 @@ %h1 = @person.real_name - - unless @person.id == current_user.id + - unless @person.id == current_user.person.id + .right = link_to 'remove friend', @person, :confirm => 'Are you sure?', :method => :delete, :class => "button" diff --git a/app/views/requests/_new_request.haml b/app/views/requests/_new_request.haml index 42cd8b5e5..5dbe3b203 100644 --- a/app/views/requests/_new_request.haml +++ b/app/views/requests/_new_request.haml @@ -7,6 +7,6 @@ Enter a Diaspora URL, Diaspora username, or random email address: = f.text_field :destination_url - = f.hidden_field :group, :value => @group.id + = f.hidden_field :group_id, :value => @group.id = f.submit diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 24aa8e7f0..e4c884d83 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -1,11 +1,11 @@ +%h1.big_text + .back + = link_to "⇧ home", root_path + + Editing your profile + = form_for @user do |f| - %h1.big_text - .back - = link_to "⇧ home", root_path - - Editing your profile - = f.error_messages @@ -16,11 +16,11 @@ = p.hidden_field :image_url, :value => @profile.image_url, :id => 'image_url_field' - for photo in @photos - if photo.url(:thumb_medium) == @profile.image_url - %div.small_photo{:id => photo.image.thumb_medium.url, :class=>'selected'} + %div.small_photo{:id => photo.url(:thumb_medium), :class=>'selected'} = check_box_tag 'checked_photo', true, true = link_to image_tag(photo.url(:thumb_medium)), "#" - else - %div.small_photo{:id => photo.image.thumb_medium.url} + %div.small_photo{:id => photo.url(:thumb_medium)} = check_box_tag 'checked_photo' = link_to image_tag(photo.url(:thumb_medium)), "#" =will_paginate @photos diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml index 6f210359c..bbd50ddd0 100644 --- a/app/views/users/index.html.haml +++ b/app/views/users/index.html.haml @@ -1,12 +1,42 @@ -- title "Users" +%h1.big_text + .back + = link_to "⇧ home", root_path + Search + +%p + =form_tag '/users', :method => "get" do + = text_field_tag :q + = submit_tag "search" + = link_to "reset", users_path + += (@people.count).to_s + search_or_index %table %tr - %th Real Name + %th real name %th email - %th Password - - for user in @users - %tr - %td= user.real_name - %td= user.email - %td= user.encrypted_password + %th url + - for person in @people + %tr + %td= person.real_name + %td= person.email + %td= person.url + + -if current_user.friends.include? person + + - elsif person.id == current_user.person.id + %td + %td thats you! + -elsif current_user.pending_requests.find_by_person_id(person.id) + %td + %td ^-you have a friend request from this person + -elsif current_user.pending_requests.find_by_url(person.receive_url) + %td + %td friend request pending + -else + %td + %td + = form_for Request.new do |f| + = f.select(:group_id, @groups_array) + = f.hidden_field :destination_url, :value => person.email + = f.submit "add friend" diff --git a/config/application.rb b/config/application.rb index 206139b5e..bbceb6f94 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,7 +15,7 @@ module Diaspora # -- all .rb files in that directory are automatically loaded. # Add additional load paths for your own custom dirs - config.autoload_paths += %W(#{config.root}/lib) + #config.autoload_paths += %W(#{config.root}/lib) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named diff --git a/config/routes.rb b/config/routes.rb index b0e12b30b..946d34729 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ -Diaspora::Application.routes.draw do |map| +Diaspora::Application.routes.draw do resources :people - resources :users, :only => [:edit, :show, :update] + resources :users, :except => [:create, :new] resources :status_messages resources :comments resources :requests diff --git a/config/selenium.yml b/config/selenium.yml new file mode 100644 index 000000000..32bbc92fd --- /dev/null +++ b/config/selenium.yml @@ -0,0 +1,86 @@ +common: &common + # Try to kill mongrel after suite if tmp/pids/mongrel_selenium.pid exists + # kill_mongrel_after_suite: true + +local: &local + <<: *common + test_framework: webrat + selenium_server_address: "127.0.0.1" + selenium_server_port: "4444" + selenium_browser_key: "*chrome /Applications/Firefox.app/Contents/MacOS/firefox-bin" + application_address: "127.0.0.1" + application_port: "4000" + +local_jsunit: + <<: *local + application_port: "8080" + +# Possible Sauce Labs configurations as of 2009/11/19 +# From: http://saucelabs.com/products/docs/sauce-ondemand/browsers +# +# saucelabs_browser_os saucelabs_browser saucelabs_browser_version (pick one) +# +# "Windows 2003" "iexplore" "6.", "7.", "8." +# "firefox" "2.", "3.0", "3.5" +# "safari" "3.", "4." +# "opera" "9." +# "googlechrome" "" +# "Linux" "firefox" "3." +saucelabs: &saucelabs + <<: *common + test_framework: webrat + # URL of Selenium RC server: + selenium_server_address: "saucelabs.com" + selenium_server_port: "4444" + # Saucelabs credentials / Browser to drive + saucelabs_username: "YOUR-SAUCELABS-USERNAME" + saucelabs_access_key: "YOUR-SAUCELABS-ACCESS-KEY" + saucelabs_browser_os: "Linux" + saucelabs_browser: "firefox" + saucelabs_browser_version: "3." + saucelabs_max_duration_seconds: 1800 + # Selenium RC browser connects to and tests the app at this URL: + application_address: "testhost.com" # this will be ovewritten if tunnel_method == :saucetunnel + application_port: 80 + # App host can actually be a tunnel that tunnels from : to localhost: + # There are 3 kinds of tunnels: + # + # tunnel_method: :saucetunnel + # tunnel_to_localhost_port: 4000 # Warning: application_port and tunnel_to_localhost_port must be identical if you are using Webrat + # tunnel_startup_timeout: 240 + # + # tunnel_method: :sshtunnel + # application_address: proxy.mycompany.com + # application_port: 12345 # or can be a range XXXX-YYYY + # tunnel_to_localhost_port: 4000 # Warning: application_port and tunnel_to_localhost_port must be identical if you are using Webrat + # tunnel_username: fred + # tunnel_keyfile: "/Users/<%= ENV['USER'] %>/.ssh/id_rsa" # or tunnel_password: "password" + # + # tunnel_method: :othertunnel You're managing your tunnel independently + +saucelabs_jsunit: &saucelabs_jsunit + <<: *saucelabs + # We are using the Jetty server for Saucelabs JsUnit selenium testing. + localhost_app_server_port: "8080" + +saucelabs_jsunit_firefox: + <<: *saucelabs_jsunit + +saucelabs_jsunit_ie: + <<: *saucelabs_jsunit + saucelabs_browser_os: "Windows 2003" + saucelabs_browser: "iexplore" + saucelabs_browser_version: "7." + jsunit_polling_interval_seconds: 300 + +saucelabs_jsunit_safari: + <<: *saucelabs_jsunit + saucelabs_browser_os: "Windows 2003" + saucelabs_browser: "safari" + saucelabs_browser_version: "4." + +saucelabs_jsunit_chrome: + <<: *saucelabs_jsunit + saucelabs_browser_os: "Windows 2003" + saucelabs_browser: "googlechrome" + saucelabs_browser_version: "" diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb index 10a7e910e..49b8734ff 100644 --- a/db/seeds/tom.rb +++ b/db/seeds/tom.rb @@ -3,21 +3,21 @@ require 'config/environment' remote_url = "http://tom.joindiaspora.com/" remote_url = "http://localhost:3000/" # Create seed user -user = User.create!( :email => "tom@tom.joindiaspora.com", +user = User.instantiate!( :email => "tom@tom.joindiaspora.com", :password => "evankorth", - :person => Person.new( + :person => { :email => "tom@tom.joindiaspora.com", :url => remote_url, - :profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" )) + :profile => { :first_name => "Alexander", :last_name => "Hamiltom" }} ) user.person.save! -user2 = User.create!( :email => "korth@tom.joindiaspora.com", +user2 = User.instantiate!( :email => "korth@tom.joindiaspora.com", :password => "evankorth", - :person => Person.new( :email => "korth@tom.joindiaspora.com", + :person => { :email => "korth@tom.joindiaspora.com", :url => remote_url, - :profile => Profile.new( :first_name => "Evan", - :last_name => "Korth"))) + :profile => { :first_name => "Evan", + :last_name => "Korth"}}) user2.person.save! diff --git a/lib/tasks/saucelabs_adapter.rake b/lib/tasks/saucelabs_adapter.rake new file mode 100644 index 000000000..e9c32be08 --- /dev/null +++ b/lib/tasks/saucelabs_adapter.rake @@ -0,0 +1,53 @@ +require 'saucelabs_adapter/run_utils' + +class Rake::Task + def self.exists?(name) + tasks.any? { |t| t.name == name } + end +end + +namespace :selenium do + + # Rake tasks are cumulative, and some old plugins are still defining selenium:server, so clear it. + Rake::Task[:'selenium:server'].clear_actions if Rake::Task.exists?('selenium:server') + + desc "Run the selenium remote-control server" + task :server do + system('bundle exec selenium-rc') + end + + desc "Run the selenium remote-control server in the background" + task :server_bg do + system('nohup selenium-rc 2&>1 &') + end + + desc "Runs Selenium tests locally (selenium server must already be started)" + task :local => [:local_env, :suite] + + desc "Run Selenium tests at saucelabs.com (using configuration 'saucelabs' in config/selenium.yml)" + task :sauce => [:sauce_env, :suite] + + desc "Run Selenium tests using configuration SELENIUM_ENV (from config/selenium.yml)" + task :custom => [:check_selenium_env_is_set, :suite] + + task :local_env do + ENV['SELENIUM_ENV'] = 'local' + end + + task :sauce_env do + ENV['SELENIUM_ENV'] = 'saucelabs' + end + + task :check_selenium_env_is_set do + raise "SELENIUM_ENV must be set" unless ENV['SELENIUM_ENV'] + end + + task :suite do + if (File.exists?("test/selenium/selenium_suite.rb")) + RunUtils.run "ruby test/selenium/selenium_suite.rb" + else + puts "test/selenium/selenium_suite.rb not found, bailing.\nPlease create a script that will run your selenium tests." + exit 1 + end + end +end diff --git a/test/selenium/sample_webrat_test.rb b/test/selenium/sample_webrat_test.rb new file mode 100644 index 000000000..102985a97 --- /dev/null +++ b/test/selenium/sample_webrat_test.rb @@ -0,0 +1,7 @@ +class SampleWebratTest < ActionController::IntegrationTest + + def test_widget + visit "/" + assert_contain "sign in" + end +end diff --git a/test/selenium/selenium_suite.rb b/test/selenium/selenium_suite.rb new file mode 100644 index 000000000..2734b4309 --- /dev/null +++ b/test/selenium/selenium_suite.rb @@ -0,0 +1,11 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper')) +require 'test/unit/ui/console/testrunner' +require 'webrat' +require 'saucelabs_adapter' + +Webrat.configure do |config| + config.mode = :selenium + config.application_framework = :rack +end + +require File.join(File.dirname(__FILE__), 'sample_webrat_test') diff --git a/test/test_helper.rb b/test/test_helper.rb index 8bf1192ff..22895cbd0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -7,7 +7,7 @@ class ActiveSupport::TestCase # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting - fixtures :all + #fixtures :all # Add more helper methods to be used by all tests here... end