finished dmails and favorites functional tests
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -5,6 +5,7 @@ group :test do
|
|||||||
gem "factory_girl"
|
gem "factory_girl"
|
||||||
gem "mocha"
|
gem "mocha"
|
||||||
gem "ffaker", :git => "http://github.com/EmmanuelOga/ffaker.git"
|
gem "ffaker", :git => "http://github.com/EmmanuelOga/ffaker.git"
|
||||||
|
gem "simplecov", :require => false
|
||||||
end
|
end
|
||||||
|
|
||||||
gem "rails", "3.0.0"
|
gem "rails", "3.0.0"
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ GEM
|
|||||||
rake (0.8.7)
|
rake (0.8.7)
|
||||||
shoulda (2.11.3)
|
shoulda (2.11.3)
|
||||||
simple_form (1.2.2)
|
simple_form (1.2.2)
|
||||||
|
simplecov (0.3.7)
|
||||||
|
simplecov-html (>= 0.3.7)
|
||||||
|
simplecov-html (0.3.9)
|
||||||
super_exception_notifier (3.0.13)
|
super_exception_notifier (3.0.13)
|
||||||
actionmailer
|
actionmailer
|
||||||
rake
|
rake
|
||||||
@@ -119,5 +122,6 @@ DEPENDENCIES
|
|||||||
rails (= 3.0.0)
|
rails (= 3.0.0)
|
||||||
shoulda
|
shoulda
|
||||||
simple_form
|
simple_form
|
||||||
|
simplecov
|
||||||
super_exception_notifier
|
super_exception_notifier
|
||||||
will_paginate!
|
will_paginate!
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
|
|||||||
before_filter :initialize_cookies
|
before_filter :initialize_cookies
|
||||||
before_filter :set_title
|
before_filter :set_title
|
||||||
layout "default"
|
layout "default"
|
||||||
|
|
||||||
|
rescue_from User::PrivilegeError, :with => :access_denied
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def access_denied
|
def access_denied
|
||||||
@@ -12,7 +14,7 @@ protected
|
|||||||
|
|
||||||
respond_to do |fmt|
|
respond_to do |fmt|
|
||||||
fmt.html do
|
fmt.html do
|
||||||
if request.get? && Rails.env.test?
|
if request.get?
|
||||||
redirect_to new_session_path(:url => previous_url), :notice => "Access denied"
|
redirect_to new_session_path(:url => previous_url), :notice => "Access denied"
|
||||||
else
|
else
|
||||||
redirect_to new_session_path, :notice => "Access denied"
|
redirect_to new_session_path, :notice => "Access denied"
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
class DmailsController < ApplicationController
|
class DmailsController < ApplicationController
|
||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
|
before_filter :member_only
|
||||||
rescue_from User::PrivilegeError, :with => "static/access_denied"
|
rescue_from User::PrivilegeError, :with => "static/access_denied"
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@dmail = Dmail.new(params[:dmail])
|
if params[:respond_to_id]
|
||||||
respond_width(@dmail)
|
@dmail = Dmail.find(params[:respond_to_id]).build_response(:forward => params[:forward])
|
||||||
|
else
|
||||||
|
@dmail = Dmail.new(params[:dmail])
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_with(@dmail)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -3,21 +3,23 @@ class FavoritesController < ApplicationController
|
|||||||
if params[:tags]
|
if params[:tags]
|
||||||
redirect_to(posts_path(:tags => "fav:#{CurrentUser.name} #{params[:tags]}"))
|
redirect_to(posts_path(:tags => "fav:#{CurrentUser.name} #{params[:tags]}"))
|
||||||
else
|
else
|
||||||
@posts = PostSets::Favorite.new(CurrentUser.user)
|
@post_set = PostSets::Favorite.new(CurrentUser.user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@favorite = Favorite.create(
|
@favorite = Favorite.create(
|
||||||
:user_id => CurrentUser.id,
|
:user_id => CurrentUser.id,
|
||||||
:post_id => params[:favorite][:post_id]
|
:post_id => params[:id]
|
||||||
)
|
)
|
||||||
|
render :nothing => true
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
Favorite.destroy(
|
Favorite.destroy(
|
||||||
:user_id => CurrentUser.id,
|
:user_id => CurrentUser.id,
|
||||||
:post_id => params[:favorite][:post_id]
|
:post_id => params[:id]
|
||||||
)
|
)
|
||||||
|
render :nothing => true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ class Favorite
|
|||||||
# ignore
|
# ignore
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.count(user_id)
|
||||||
|
select_value_sql("SELECT COUNT(*) FROM #{table_name_for(user_id)}").to_i
|
||||||
|
end
|
||||||
|
|
||||||
def self.destroy(conditions)
|
def self.destroy(conditions)
|
||||||
if conditions[:user_id] && conditions[:post_id]
|
if conditions[:user_id] && conditions[:post_id]
|
||||||
destroy_for_post_and_user(conditions[:post_id], conditions[:user_id])
|
destroy_for_post_and_user(conditions[:post_id], conditions[:user_id])
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module PostSets
|
module PostSets
|
||||||
class Base
|
class Base
|
||||||
attr_accessor :page, :before_id, :count
|
attr_accessor :page, :before_id, :count, :posts
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@page = options[:page].to_i
|
@page = options[:page].to_i
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
module PostSets
|
module PostSets
|
||||||
class FavoriteSet < Base
|
class Favorite < Base
|
||||||
attr_accessor :user
|
attr_accessor :user
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(user)
|
||||||
super(options)
|
|
||||||
@user = user
|
@user = user
|
||||||
|
super()
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
@@ -12,7 +12,11 @@ module PostSets
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_posts
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class Dmail < ActiveRecord::Base
|
|||||||
belongs_to :from, :class_name => "User"
|
belongs_to :from, :class_name => "User"
|
||||||
after_create :update_recipient
|
after_create :update_recipient
|
||||||
after_create :send_dmail
|
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 :for, lambda {|user| where(["owner_id = ?", user])}
|
||||||
scope :inbox, where("to_id = owner_id")
|
scope :inbox, where("to_id = owner_id")
|
||||||
scope :sent, where("from_id = owner_id")
|
scope :sent, where("from_id = owner_id")
|
||||||
@@ -42,6 +42,8 @@ class Dmail < ActiveRecord::Base
|
|||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def create_split(params)
|
def create_split(params)
|
||||||
|
copy = nil
|
||||||
|
|
||||||
Dmail.transaction do
|
Dmail.transaction do
|
||||||
copy = Dmail.new(params)
|
copy = Dmail.new(params)
|
||||||
copy.owner_id = copy.to_id
|
copy.owner_id = copy.to_id
|
||||||
@@ -51,6 +53,8 @@ class Dmail < ActiveRecord::Base
|
|||||||
copy.owner_id = CurrentUser.id
|
copy.owner_id = CurrentUser.id
|
||||||
copy.save!
|
copy.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
copy
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_blank
|
def new_blank
|
||||||
@@ -60,14 +64,13 @@ class Dmail < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_response
|
def build_response(options = {})
|
||||||
Dmail.new do |dmail|
|
Dmail.new do |dmail|
|
||||||
dmail.title = "Re: #{title}"
|
dmail.title = "Re: #{title}"
|
||||||
dmail.owner_id = from_id
|
dmail.owner_id = from_id
|
||||||
dmail.body = quoted_body
|
dmail.body = quoted_body
|
||||||
dmail.to_id = from_id
|
dmail.to_id = from_id unless options[:forward]
|
||||||
dmail.from_id = to_id
|
dmail.from_id = to_id
|
||||||
dmail.parent_id = id
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def id_to_pretty_name(user_id)
|
def id_to_pretty_name(user_id)
|
||||||
id_to_name.tr("_", " ")
|
id_to_name(user_id).tr("_", " ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
<h1>Edit Message</h1>
|
<h1>Edit Message</h1>
|
||||||
<%= render "form", :locals => {:dmail => @dmail} %>
|
<%= render :partial => "form", :locals => {:dmail => @dmail} %>
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% @dmails.each do |dmail| %>
|
<% @dmails.each do |dmail| %>
|
||||||
<% if params[:folder] == "sent" %>
|
<% if params[:folder] == "sent" %>
|
||||||
<%= render "sent", :locals => {:dmail => dmail} %>
|
<%= render :partial => "sent", :locals => {:dmail => dmail} %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= render "received", :locals => {:dmail => dmail} %>
|
<%= render :partial => "received", :locals => {:dmail => dmail} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
<h1>New Message</h1>
|
<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>
|
||||||
@@ -4,7 +4,6 @@ class CreateDmails < ActiveRecord::Migration
|
|||||||
t.column :owner_id, :integer, :null => false
|
t.column :owner_id, :integer, :null => false
|
||||||
t.column :from_id, :integer, :null => false
|
t.column :from_id, :integer, :null => false
|
||||||
t.column :to_id, :integer, :null => false
|
t.column :to_id, :integer, :null => false
|
||||||
t.column :parent_id, :integer
|
|
||||||
t.column :title, :string, :null => false
|
t.column :title, :string, :null => false
|
||||||
t.column :body, :text, :null => false
|
t.column :body, :text, :null => false
|
||||||
t.column :message_index, "tsvector", :null => false
|
t.column :message_index, "tsvector", :null => false
|
||||||
@@ -14,7 +13,6 @@ class CreateDmails < ActiveRecord::Migration
|
|||||||
end
|
end
|
||||||
|
|
||||||
add_index :dmails, :owner_id
|
add_index :dmails, :owner_id
|
||||||
add_index :dmails, :parent_id
|
|
||||||
|
|
||||||
execute "CREATE INDEX index_dmails_on_message_index ON dmails USING GIN (message_index)"
|
execute "CREATE INDEX index_dmails_on_message_index ON dmails USING GIN (message_index)"
|
||||||
execute "CREATE TRIGGER trigger_dmails_on_update BEFORE INSERT OR UPDATE ON dmails FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('message_index', 'pg_catalog.english', 'title', 'body')"
|
execute "CREATE TRIGGER trigger_dmails_on_update BEFORE INSERT OR UPDATE ON dmails FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('message_index', 'pg_catalog.english', 'title', 'body')"
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
Factory.define(:dmail) do |f|
|
Factory.define(:dmail) do |f|
|
||||||
f.owner {|x| x.association(:user)}
|
|
||||||
f.from_id {|x| x.owner_id}
|
|
||||||
f.to {|x| x.association(:user)}
|
f.to {|x| x.association(:user)}
|
||||||
f.title {Faker::Lorem.words}
|
f.title {Faker::Lorem.words.join(" ")}
|
||||||
f.body {Faker::Lorem.sentences}
|
f.body {Faker::Lorem.sentences.join(" ")}
|
||||||
f.is_read false
|
f.is_read false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,22 +7,22 @@ class AdvertisementsControllerTest < ActionController::TestCase
|
|||||||
@advertiser = Factory.create(:admin_user)
|
@advertiser = Factory.create(:admin_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the new page" do
|
should "get the new page" do
|
||||||
get :new, {}, {:user_id => @advertiser.id}
|
get :new, {}, {:user_id => @advertiser.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the edit page" do
|
should "get the edit page" do
|
||||||
get :edit, {:id => @ad.id}, {:user_id => @advertiser.id}
|
get :edit, {:id => @ad.id}, {:user_id => @advertiser.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the index page" do
|
should "get the index page" do
|
||||||
get :index, {}, {:user_id => @advertiser.id}
|
get :index, {}, {:user_id => @advertiser.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the show page" do
|
should "get the show page" do
|
||||||
get :show, {:id => @ad.id}, {:user_id => @advertiser.id}
|
get :show, {:id => @ad.id}, {:user_id => @advertiser.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ class ArtistVersionsControllerTest < ActionController::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the index page" do
|
should "get the index page" do
|
||||||
get :index
|
get :index
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the index page when searching for something" do
|
should "get the index page when searching for something" do
|
||||||
get :index, {:search => {:name_equals => @artist.name}}
|
get :index, {:search => {:name_equals => @artist.name}}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,22 +14,22 @@ class ArtistsControllerTest < ActionController::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the new page" do
|
should "get the new page" do
|
||||||
get :new, {}, {:user_id => @user.id}
|
get :new, {}, {:user_id => @user.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the edit page" do
|
should "get the edit page" do
|
||||||
get :edit, {:id => @artist.id}, {:user_id => @user.id}
|
get :edit, {:id => @artist.id}, {:user_id => @user.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the show page" do
|
should "get the show page" do
|
||||||
get :show, {:id => @artist.id}
|
get :show, {:id => @artist.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the index page" do
|
should "get the index page" do
|
||||||
get :index
|
get :index
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,22 +14,22 @@ class BansControllerTest < ActionController::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the new page" do
|
should "get the new page" do
|
||||||
get :new, {}, {:user_id => @user.id}
|
get :new, {}, {:user_id => @user.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the edit page" do
|
should "get the edit page" do
|
||||||
get :edit, {:id => @ban.id}, {:user_id => @user.id}
|
get :edit, {:id => @ban.id}, {:user_id => @user.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the show page" do
|
should "get the show page" do
|
||||||
get :show, {:id => @ban.id}
|
get :show, {:id => @ban.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the index page" do
|
should "get the index page" do
|
||||||
get :index
|
get :index
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class CommentsControllerTest < ActionController::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render the index page" do
|
should "get the index page" do
|
||||||
get :index
|
get :index
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,99 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class DmailsControllerTest < ActionController::TestCase
|
class DmailsControllerTest < ActionController::TestCase
|
||||||
# Replace this with your real tests.
|
context "The dmails controller" do
|
||||||
test "the truth" do
|
setup do
|
||||||
assert true
|
@user = Factory.create(:user)
|
||||||
|
@unrelated_user = Factory.create(:user)
|
||||||
|
CurrentUser.user = @user
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
@dmail = Factory.create(:dmail, :owner => @user)
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
CurrentUser.ip_addr = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
context "new action" do
|
||||||
|
should "get the page" do
|
||||||
|
get :new, {}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a respond_to_id" do
|
||||||
|
should "prefill the fields" do
|
||||||
|
get :new, {:respond_to_id => @dmail}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:dmail)
|
||||||
|
assert_equal(@dmail.from_id, assigns(:dmail).to_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "and a forward flag" do
|
||||||
|
should "not populate the to field" do
|
||||||
|
get :new, {:respond_to_id => @dmail, :forward => true}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:dmail)
|
||||||
|
assert_nil(assigns(:dmail).to_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "index action" do
|
||||||
|
should "show dmails owned by the current user" do
|
||||||
|
get :index, {:owner_id_equals => @dmail.owner_id, :folder => "sent"}, {:user_id => @dmail.owner_id}
|
||||||
|
assert_response :success
|
||||||
|
|
||||||
|
get :index, {:owner_id_equals => @dmail.owner_id, :folder => "received"}, {:user_id => @dmail.owner_id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not show dmails not owned by the current user" do
|
||||||
|
assert_raises(User::PrivilegeError) do
|
||||||
|
get :index, {:owner_id_equals => @dmail.owner_id}, {:user_id => @unrelated_user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "show action" do
|
||||||
|
should "show dmails owned by the current user" do
|
||||||
|
get :show, {:id => @dmail.id}, {:user_id => @dmail.owner_id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not show dmails not owned by the current user" do
|
||||||
|
assert_raises(User::PrivilegeError) do
|
||||||
|
get :show, {:id => @dmail.id}, {:user_id => @unrelated_user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create action" do
|
||||||
|
should "create two messages, one for the sender and one for the recipient" do
|
||||||
|
assert_difference("Dmail.count", 2) do
|
||||||
|
dmail_attribs = Factory.attributes_for(:dmail).merge(:to_id => Factory.create(:user).id)
|
||||||
|
post :create, {:dmail => dmail_attribs}, {:user_id => @user.id}
|
||||||
|
assert_redirected_to dmail_path(Dmail.last)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "destroy action" do
|
||||||
|
should "allow deletion if the dmail is owned by the current user" do
|
||||||
|
assert_difference("Dmail.count", -1) do
|
||||||
|
post :destroy, {:id => @dmail.id}, {:user_id => @dmail.owner_id}
|
||||||
|
assert_redirected_to dmails_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not allow deletion if the dmail is not owned by the current user" do
|
||||||
|
assert_difference("Dmail.count", 0) do
|
||||||
|
assert_raises(User::PrivilegeError) do
|
||||||
|
post :destroy, {:id => @dmail.id}, {:user_id => @unrelated_user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,59 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class FavoritesControllerTest < ActionController::TestCase
|
class FavoritesControllerTest < ActionController::TestCase
|
||||||
# Replace this with your real tests.
|
context "The favorites controller" do
|
||||||
test "the truth" do
|
setup do
|
||||||
assert true
|
@user = Factory.create(:user)
|
||||||
|
CurrentUser.user = @user
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
CurrentUser.ip_addr = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
context "index action" do
|
||||||
|
context "with a specified tags parameter" do
|
||||||
|
should "redirect to the posts controller" do
|
||||||
|
get :index, {:tags => "abc"}, {:user_id => @user}
|
||||||
|
assert_redirected_to(posts_path(:tags => "fav:#{@user.name} abc"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "display the current user's favorites" do
|
||||||
|
get :index, {}, {:user_id => @user.id}
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil(assigns(:post_set))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create action" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "create a favorite for the current user" do
|
||||||
|
assert_difference("Favorite.count(#{@user.id})", 1) do
|
||||||
|
post :create, {:id => @post.id}, {:user_id => @user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "destroy action" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post)
|
||||||
|
Favorite.create(
|
||||||
|
:user_id => @user.id,
|
||||||
|
:post_id => @post.id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "remove the favorite from the current user" do
|
||||||
|
assert_difference("Favorite.count(#{@user.id})", -1) do
|
||||||
|
post :destroy, {:id => @post.id}, {:user_id => @user.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
ENV["RAILS_ENV"] = "test"
|
ENV["RAILS_ENV"] = "test"
|
||||||
|
|
||||||
|
require 'simplecov'
|
||||||
|
SimpleCov.start 'rails'
|
||||||
|
|
||||||
require File.expand_path('../../config/environment', __FILE__)
|
require File.expand_path('../../config/environment', __FILE__)
|
||||||
require 'rails/test_help'
|
require 'rails/test_help'
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class DmailTest < ActiveSupport::TestCase
|
|||||||
dmail = Factory.create(:dmail)
|
dmail = Factory.create(:dmail)
|
||||||
response = dmail.build_response
|
response = dmail.build_response
|
||||||
assert_equal("Re: #{dmail.title}", response.title)
|
assert_equal("Re: #{dmail.title}", response.title)
|
||||||
assert_equal(dmail.id, response.parent_id)
|
|
||||||
assert_equal(dmail.from_id, response.to_id)
|
assert_equal(dmail.from_id, response.to_id)
|
||||||
assert_equal(dmail.to_id, response.from_id)
|
assert_equal(dmail.to_id, response.from_id)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user