Merge branch 'master' of github.com:diaspora/diaspora into pivots

Conflicts:
	app/controllers/users_controller.rb
	app/models/user.rb
	config/sprinkle/provision.rb
This commit is contained in:
Raphael 2010-08-19 16:09:08 -07:00
commit f66b5f4006
25 changed files with 292 additions and 52 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
.idea
*.swap
*.swp
*.swo
*~

13
Gemfile
View file

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

View file

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

View file

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

View file

@ -1,6 +1,17 @@
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])
@user_profile = @user.person.profile
@ -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

View file

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

View file

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

View file

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

View file

@ -16,5 +16,8 @@ class Group
timestamps!
def to_s
name
end
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

86
config/selenium.yml Normal file
View file

@ -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 <application_address>:<application_port> to localhost:<tunnel_to_localhost_port>
# 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: ""

View file

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

View file

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

View file

@ -0,0 +1,7 @@
class SampleWebratTest < ActionController::IntegrationTest
def test_widget
visit "/"
assert_contain "sign in"
end
end

View file

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

View file

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