[photohunt commit] r190 - in trunk: app/controllers app/helpers app/models app/views/layouts app/views/login app/vie...

0 views
Skip to first unread message

codesite...@google.com

unread,
Dec 5, 2007, 3:11:54 AM12/5/07
to photoh...@googlegroups.com
Author: keoki.lee
Date: Wed Dec 5 00:10:44 2007
New Revision: 190

Added:
trunk/app/controllers/upload_controller.rb
trunk/app/helpers/upload_helper.rb
trunk/app/models/photo_receiver.rb
trunk/app/models/tag.rb
trunk/app/views/photo_receiver/
trunk/app/views/upload/
trunk/app/views/upload/upload.rhtml
trunk/test/fixtures/photo_receiver/
trunk/test/fixtures/tags.yml
trunk/test/functional/upload_controller_test.rb
trunk/test/unit/mailman_test.rb
trunk/test/unit/photo_mailer_test.rb
trunk/test/unit/photo_receiver_test.rb
trunk/test/unit/tag_test.rb
Modified:
trunk/app/controllers/admin_controller.rb
trunk/app/controllers/login_controller.rb
trunk/app/controllers/pictures_controller.rb
trunk/app/helpers/application_helper.rb
trunk/app/models/picture.rb
trunk/app/views/layouts/admin.rhtml
trunk/app/views/layouts/user.rhtml
trunk/app/views/login/add_user.rhtml
trunk/db/schema.rb

Log:


Modified: trunk/app/controllers/admin_controller.rb
==============================================================================
--- trunk/app/controllers/admin_controller.rb (original)
+++ trunk/app/controllers/admin_controller.rb Wed Dec 5 00:10:44 2007
@@ -29,4 +29,12 @@
end
end
end
+
+ def create_tag
+ @tag = Tag.new(params[:tag])
+ if request.post? and @tag.save
+ flash[:notice] = "Tag successfully created."
+ redirect_to(:action => 'index')
+ end
+ end
end

Modified: trunk/app/controllers/login_controller.rb
==============================================================================
--- trunk/app/controllers/login_controller.rb (original)
+++ trunk/app/controllers/login_controller.rb Wed Dec 5 00:10:44 2007
@@ -8,9 +8,9 @@
def add_user
@user = User.new(params[:user])
if request.post? and @user.save
- flash.now[:notice] = "User #{@user.name} created."
@user = User.new
- redirect_to({:action => "login"})
+ redirect_to(:action => "login")
+ flash[:notice] = "User #{@user.name} created."
end
end


Modified: trunk/app/controllers/pictures_controller.rb
==============================================================================
--- trunk/app/controllers/pictures_controller.rb (original)
+++ trunk/app/controllers/pictures_controller.rb Wed Dec 5 00:10:44 2007
@@ -9,22 +9,6 @@
@all_pictures = Picture.find(:all, :conditions => "status='APPROVED'")
end

- def upload
- @picture = Picture.new
- end
-
- def save
- @picture = Picture.new(params[:picture])
- @picture.status = "PENDING"
- @picture.score = 0
- if @picture.save
- flash[:notice] = "Your picture has been submitted."
- redirect_to(:action => 'list')
- else
- render(:action => :upload)
- end
- end
-
def picture
@picture = Picture.find(params[:id])
send_data(@picture.data,

Added: trunk/app/controllers/upload_controller.rb
==============================================================================
--- (empty file)
+++ trunk/app/controllers/upload_controller.rb Wed Dec 5 00:10:44 2007
@@ -0,0 +1,31 @@
+class UploadController < ApplicationController
+
+ layout "user"
+
+ def index
+ redirect_to(:action => 'upload')
+ end
+
+ def upload
+ @picture = Picture.new
+ @tags = [['Select a tag', nil]]
+ taglist = Tag.find(:all, :select=>"short_description")
+ for tag in taglist
+ @tags << tag.short_description
+ end
+ end
+
+ def save
+ @picture = Picture.new(params[:picture]) do |p|
+ p.status = "PENDING"
+ p.score = 0
+ p.date = Date.today
+ end
+ if @picture.save
+ redirect_to(:controller => 'pictures', :action => 'list')
+ flash[:notice] = "Your picture has been submitted and is pending approval."
+ else
+ render(:action => :upload)
+ end
+ end
+end

Modified: trunk/app/helpers/application_helper.rb
==============================================================================
--- trunk/app/helpers/application_helper.rb (original)
+++ trunk/app/helpers/application_helper.rb Wed Dec 5 00:10:44 2007
@@ -1,3 +1,5 @@
# Methods added to this helper will be available to all templates in
the application.
module ApplicationHelper
+ # Get a list of the available tags.
+
end

Added: trunk/app/helpers/upload_helper.rb
==============================================================================
--- (empty file)
+++ trunk/app/helpers/upload_helper.rb Wed Dec 5 00:10:44 2007
@@ -0,0 +1,2 @@
+module UploadHelper
+end

Added: trunk/app/models/photo_receiver.rb
==============================================================================
--- (empty file)
+++ trunk/app/models/photo_receiver.rb Wed Dec 5 00:10:44 2007
@@ -0,0 +1,3 @@
+class PhotoReceiver < ActionMailer::Base
+
+end

Modified: trunk/app/models/picture.rb
==============================================================================
--- trunk/app/models/picture.rb (original)
+++ trunk/app/models/picture.rb Wed Dec 5 00:10:44 2007
@@ -1,6 +1,11 @@
class Picture < ActiveRecord::Base

- validates_presence_of :tag
+ validates_presence_of :tag, :user_email
+
+ validates_format_of :user_email,
+ :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,
+ :message => ' must be valid'
+
validates_format_of :content_type,
:with => /^image/,
:message => " -- you can only upload pictures."

Added: trunk/app/models/tag.rb
==============================================================================
--- (empty file)
+++ trunk/app/models/tag.rb Wed Dec 5 00:10:44 2007
@@ -0,0 +1,5 @@
+class Tag < ActiveRecord::Base
+
+ validates_presence_of :short_description
+
+end

Modified: trunk/app/views/layouts/admin.rhtml
==============================================================================
--- trunk/app/views/layouts/admin.rhtml (original)
+++ trunk/app/views/layouts/admin.rhtml Wed Dec 5 00:10:44 2007
@@ -15,6 +15,7 @@
<div class="side-navbar">
<%= link_to "Approve Photos", :controller => 'admin', :action => 'approve' %>
<%= link_to "Manage Photos", :controller => 'admin', :action => 'manage' %>
+ <%= link_to "Create tags", :controller => 'admin', :action => 'create_tag' %>
<%= link_to "Log Out", :controller => 'login', :action => 'logout' %>
</div>
<div class="content">

Modified: trunk/app/views/layouts/user.rhtml
==============================================================================
--- trunk/app/views/layouts/user.rhtml (original)
+++ trunk/app/views/layouts/user.rhtml Wed Dec 5 00:10:44 2007
@@ -13,7 +13,7 @@
</div>
<hr>
<div class="side-navbar">
- <%= link_to "Photo Upload", :controller => 'pictures', :action => 'upload' %>
+ <%= link_to "Photo Upload", :controller => 'upload', :action => 'index' %>
<%= link_to "Browse Pictures", :controller => 'pictures', :action => 'index' %>
</div>
<div class="content">

Modified: trunk/app/views/login/add_user.rhtml
==============================================================================
--- trunk/app/views/login/add_user.rhtml (original)
+++ trunk/app/views/login/add_user.rhtml Wed Dec 5 00:10:44 2007
@@ -1,8 +1,5 @@
<div class="user-form">
-
- <% if flash[:notice] -%>
- <div id="notice"><%= flash[:notice] %></div>
- <% end -%>
+
<%= error_messages_for 'user' %>

<fieldset>

Added: trunk/app/views/upload/upload.rhtml
==============================================================================
--- (empty file)
+++ trunk/app/views/upload/upload.rhtml Wed Dec 5 00:10:44 2007
@@ -0,0 +1,26 @@
+<%= error_messages_for 'picture' %>
+
+<fieldset>
+ <legend>Please enter information about the picture.</legend>
+
+<% form_for(:picture,
+ :url => {:action => 'save'},
+ :html => {:multipart => true}) do |form| %>
+ <p>
+ <label for="tag">Tag:</label>
+ <%= select("picture", 'tag', @tags ) %>
+ </p>
+ <p>
+ <label for="description">Description (optional):</label>
+ <%=form.text_field("description") %>
+ </p>
+ <p>
+ <label for="user_email">Email Address:</label>
+ <%= form.text_field("user_email")%>
+ </p>
+ <p>
+ <label for="picture">Picture:</label><%= form.file_field("uploaded_picture") %>
+ </p>
+ <%= submit_tag("Upload picture")%>
+<% end %>
+</fieldset>
\ No newline at end of file

Modified: trunk/db/schema.rb
==============================================================================
--- trunk/db/schema.rb (original)
+++ trunk/db/schema.rb Wed Dec 5 00:10:44 2007
@@ -2,10 +2,10 @@
# migrations feature of ActiveRecord to incrementally modify your
database, and
# then regenerate this schema definition.

-ActiveRecord::Schema.define(:version => 6) do
+ActiveRecord::Schema.define(:version => 8) do

create_table "pictures", :force => true do |t|
- t.column "user", :string
+ t.column "user_email", :string
t.column "tag", :string
t.column "description", :string
t.column "date", :date
@@ -23,6 +23,11 @@

add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
+
+ create_table "tags", :force => true do |t|
+ t.column "short_description", :string
+ t.column "long_description", :string
+ end

create_table "users", :force => true do |t|
t.column "name", :string

Added: trunk/test/fixtures/tags.yml
==============================================================================
--- (empty file)
+++ trunk/test/fixtures/tags.yml Wed Dec 5 00:10:44 2007
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+two:
+ id: 2

Added: trunk/test/functional/upload_controller_test.rb
==============================================================================
--- (empty file)
+++ trunk/test/functional/upload_controller_test.rb Wed Dec 5 00:10:44 2007
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'upload_controller'
+
+# Re-raise errors caught by the controller.
+class UploadController; def rescue_action(e) raise e end; end
+
+class UploadControllerTest < Test::Unit::TestCase
+ def setup
+ @controller = UploadController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end

Added: trunk/test/unit/mailman_test.rb
==============================================================================
--- (empty file)
+++ trunk/test/unit/mailman_test.rb Wed Dec 5 00:10:44 2007
@@ -0,0 +1,27 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class MailmanTest < Test::Unit::TestCase
+ FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
+ CHARSET = "utf-8"
+
+ include ActionMailer::Quoting
+
+ def setup
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+
+ @expected = TMail::Mail.new
+ @expected.set_content_type "text", "plain", { "charset" => CHARSET }
+ @expected.mime_version = '1.0'
+ end
+
+ private
+ def read_fixture(action)
+ IO.readlines("#{FIXTURES_PATH}/mailman/#{action}")
+ end
+
+ def encode(subject)
+ quoted_printable(subject, CHARSET)
+ end
+end

Added: trunk/test/unit/photo_mailer_test.rb
==============================================================================
--- (empty file)
+++ trunk/test/unit/photo_mailer_test.rb Wed Dec 5 00:10:44 2007
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PhotoMailerTest < Test::Unit::TestCase
+ FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
+ CHARSET = "utf-8"
+
+ include ActionMailer::Quoting
+
+ def setup
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+
+ @expected = TMail::Mail.new
+ @expected.set_content_type "text", "plain", { "charset" => CHARSET }
+ @expected.mime_version = '1.0'
+ end
+
+ def test_confirm
+ @expected.subject = 'PhotoMailer#confirm'
+ @expected.body = read_fixture('confirm')
+ @expected.date = Time.now
+
+ assert_equal @expected.encoded, PhotoMailer.create_confirm(@expected.date).encoded
+ end
+
+ def test_sent
+ @expected.subject = 'PhotoMailer#sent'
+ @expected.body = read_fixture('sent')
+ @expected.date = Time.now
+
+ assert_equal @expected.encoded, PhotoMailer.create_sent(@expected.date).encoded
+ end
+
+ private
+ def read_fixture(action)
+ IO.readlines("#{FIXTURES_PATH}/photo_mailer/#{action}")
+ end
+
+ def encode(subject)
+ quoted_printable(subject, CHARSET)
+ end
+end

Added: trunk/test/unit/photo_receiver_test.rb
==============================================================================
--- (empty file)
+++ trunk/test/unit/photo_receiver_test.rb Wed Dec 5 00:10:44 2007
@@ -0,0 +1,27 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class PhotoReceiverTest < Test::Unit::TestCase
+ FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
+ CHARSET = "utf-8"
+
+ include ActionMailer::Quoting
+
+ def setup
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+
+ @expected = TMail::Mail.new
+ @expected.set_content_type "text", "plain", { "charset" => CHARSET }
+ @expected.mime_version = '1.0'
+ end
+
+ private
+ def read_fixture(action)
+ IO.readlines("#{FIXTURES_PATH}/photo_receiver/#{action}")
+ end
+
+ def encode(subject)
+ quoted_printable(subject, CHARSET)
+ end
+end

Added: trunk/test/unit/tag_test.rb
==============================================================================
--- (empty file)
+++ trunk/test/unit/tag_test.rb Wed Dec 5 00:10:44 2007
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class TagTest < Test::Unit::TestCase
+ fixtures :tags
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end

Reply all
Reply to author
Forward
0 new messages