finished dmails and favorites functional tests
This commit is contained in:
@@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
|
||||
before_filter :initialize_cookies
|
||||
before_filter :set_title
|
||||
layout "default"
|
||||
|
||||
rescue_from User::PrivilegeError, :with => :access_denied
|
||||
|
||||
protected
|
||||
def access_denied
|
||||
@@ -12,7 +14,7 @@ protected
|
||||
|
||||
respond_to do |fmt|
|
||||
fmt.html do
|
||||
if request.get? && Rails.env.test?
|
||||
if request.get?
|
||||
redirect_to new_session_path(:url => previous_url), :notice => "Access denied"
|
||||
else
|
||||
redirect_to new_session_path, :notice => "Access denied"
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
class DmailsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only
|
||||
rescue_from User::PrivilegeError, :with => "static/access_denied"
|
||||
|
||||
def new
|
||||
@dmail = Dmail.new(params[:dmail])
|
||||
respond_width(@dmail)
|
||||
if params[:respond_to_id]
|
||||
@dmail = Dmail.find(params[:respond_to_id]).build_response(:forward => params[:forward])
|
||||
else
|
||||
@dmail = Dmail.new(params[:dmail])
|
||||
end
|
||||
|
||||
respond_with(@dmail)
|
||||
end
|
||||
|
||||
def index
|
||||
|
||||
@@ -3,21 +3,23 @@ class FavoritesController < ApplicationController
|
||||
if params[:tags]
|
||||
redirect_to(posts_path(:tags => "fav:#{CurrentUser.name} #{params[:tags]}"))
|
||||
else
|
||||
@posts = PostSets::Favorite.new(CurrentUser.user)
|
||||
@post_set = PostSets::Favorite.new(CurrentUser.user)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@favorite = Favorite.create(
|
||||
:user_id => CurrentUser.id,
|
||||
:post_id => params[:favorite][:post_id]
|
||||
:post_id => params[:id]
|
||||
)
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
def destroy
|
||||
Favorite.destroy(
|
||||
:user_id => CurrentUser.id,
|
||||
:post_id => params[:favorite][:post_id]
|
||||
:post_id => params[:id]
|
||||
)
|
||||
render :nothing => true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,6 +13,10 @@ class Favorite
|
||||
# ignore
|
||||
end
|
||||
|
||||
def self.count(user_id)
|
||||
select_value_sql("SELECT COUNT(*) FROM #{table_name_for(user_id)}").to_i
|
||||
end
|
||||
|
||||
def self.destroy(conditions)
|
||||
if conditions[:user_id] && conditions[:post_id]
|
||||
destroy_for_post_and_user(conditions[:post_id], conditions[:user_id])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module PostSets
|
||||
class Base
|
||||
attr_accessor :page, :before_id, :count
|
||||
attr_accessor :page, :before_id, :count, :posts
|
||||
|
||||
def initialize(options = {})
|
||||
@page = options[:page].to_i
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
module PostSets
|
||||
class FavoriteSet < Base
|
||||
class Favorite < Base
|
||||
attr_accessor :user
|
||||
|
||||
def initialize(options = {})
|
||||
super(options)
|
||||
def initialize(user)
|
||||
@user = user
|
||||
super()
|
||||
end
|
||||
|
||||
def tags
|
||||
@@ -12,7 +12,11 @@ module PostSets
|
||||
end
|
||||
|
||||
def load_posts
|
||||
user.favorite_posts(:before_id => before_id)
|
||||
@posts = user.favorite_posts(:before_id => before_id)
|
||||
end
|
||||
|
||||
def limit
|
||||
Danbooru.config.posts_per_page
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ class Dmail < ActiveRecord::Base
|
||||
belongs_to :from, :class_name => "User"
|
||||
after_create :update_recipient
|
||||
after_create :send_dmail
|
||||
attr_accessible :title, :body, :is_deleted, :to_id
|
||||
attr_accessible :title, :body, :is_deleted, :to_id, :to
|
||||
scope :for, lambda {|user| where(["owner_id = ?", user])}
|
||||
scope :inbox, where("to_id = owner_id")
|
||||
scope :sent, where("from_id = owner_id")
|
||||
@@ -42,6 +42,8 @@ class Dmail < ActiveRecord::Base
|
||||
|
||||
module ClassMethods
|
||||
def create_split(params)
|
||||
copy = nil
|
||||
|
||||
Dmail.transaction do
|
||||
copy = Dmail.new(params)
|
||||
copy.owner_id = copy.to_id
|
||||
@@ -51,6 +53,8 @@ class Dmail < ActiveRecord::Base
|
||||
copy.owner_id = CurrentUser.id
|
||||
copy.save!
|
||||
end
|
||||
|
||||
copy
|
||||
end
|
||||
|
||||
def new_blank
|
||||
@@ -60,14 +64,13 @@ class Dmail < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def build_response
|
||||
def build_response(options = {})
|
||||
Dmail.new do |dmail|
|
||||
dmail.title = "Re: #{title}"
|
||||
dmail.owner_id = from_id
|
||||
dmail.body = quoted_body
|
||||
dmail.to_id = from_id
|
||||
dmail.to_id = from_id unless options[:forward]
|
||||
dmail.from_id = to_id
|
||||
dmail.parent_id = id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,7 +61,7 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def id_to_pretty_name(user_id)
|
||||
id_to_name.tr("_", " ")
|
||||
id_to_name(user_id).tr("_", " ")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
<h1>Edit Message</h1>
|
||||
<%= render "form", :locals => {:dmail => @dmail} %>
|
||||
<%= render :partial => "form", :locals => {:dmail => @dmail} %>
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
<tbody>
|
||||
<% @dmails.each do |dmail| %>
|
||||
<% if params[:folder] == "sent" %>
|
||||
<%= render "sent", :locals => {:dmail => dmail} %>
|
||||
<%= render :partial => "sent", :locals => {:dmail => dmail} %>
|
||||
<% else %>
|
||||
<%= render "received", :locals => {:dmail => dmail} %>
|
||||
<%= render :partial => "received", :locals => {:dmail => dmail} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
<h1>New Message</h1>
|
||||
<%= render "form", :locals => {:dmail => @dmail} %>
|
||||
<%= render :partial => "form", :locals => {:dmail => @dmail} %>
|
||||
|
||||
12
app/views/dmails/show.html.erb
Normal file
12
app/views/dmails/show.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<div class="dmails">
|
||||
<div class="show">
|
||||
<div class="dmail">
|
||||
<h1><%= @dmail.title %></h1>
|
||||
<%= format_text(@dmail.body) %>
|
||||
<p>
|
||||
<%= link_to "Respond", new_dmail_path(:respond_to_id => @dmail) %>
|
||||
| <%= link_to "Forward", new_dmail_path(:respond_to_id => @dmail, :forward => true) %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user