* Refactored PostSet, splitting it into PostSets::Post and PostSets::Favorite
* Additional functional tests
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
class AdvertisementsController < ApplicationController
|
class AdvertisementsController < ApplicationController
|
||||||
|
before_filter :advertiser_only
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@advertisement = Advertisement.new(
|
@advertisement = Advertisement.new(
|
||||||
:ad_type => "vertical",
|
:ad_type => "vertical",
|
||||||
@@ -12,18 +14,8 @@ class AdvertisementsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@advertisements = Advertisement.all
|
@advertisements = Advertisement.all
|
||||||
|
@start_date = 1.month.ago.to_date
|
||||||
if params[:start_date]
|
@end_date = Date.today
|
||||||
@start_date = Date.parse(params[:start_date])
|
|
||||||
else
|
|
||||||
@start_date = 1.month.ago.to_date
|
|
||||||
end
|
|
||||||
|
|
||||||
if params[:end_date]
|
|
||||||
@end_date = Date.parse(params[:end_date])
|
|
||||||
else
|
|
||||||
@end_date = Date.today
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@@ -55,4 +47,12 @@ class AdvertisementsController < ApplicationController
|
|||||||
@advertisement.destroy
|
@advertisement.destroy
|
||||||
redirect_to advertisements_path, :notice => "Advertisement destroyed"
|
redirect_to advertisements_path, :notice => "Advertisement destroyed"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def advertiser_only
|
||||||
|
if !Danbooru.config.is_user_advertiser?(CurrentUser.user)
|
||||||
|
redirect_to "/static/access_denied"
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ class ArtistVersionsController < ApplicationController
|
|||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@search = Artist.search(params[:search])
|
@search = ArtistVersion.search(params[:search])
|
||||||
@artist_versions = @search.paginate :order => "version desc", :per_page => 25, :page => params[:page]
|
@artist_versions = @search.paginate :order => "id desc", :per_page => 25, :page => params[:page]
|
||||||
respond_with(@artist_versions)
|
respond_with(@artist_versions)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
class FavoritesController < ApplicationController
|
class FavoritesController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@posts = CurrentUser.favorite_posts(params)
|
if params[:tags]
|
||||||
|
redirect_to(posts_path(:tags => "fav:#{CurrentUser.name} #{params[:tags]}"))
|
||||||
|
else
|
||||||
|
@posts = PostSets::Favorite.new(CurrentUser.user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class PostsController < ApplicationController
|
|||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@post_set = PostSet.new(params[:tags], params[:page], params[:before_id])
|
@post_set = PostSets::Post.new(params[:tags], :page => params[:page], :before_id => params[:before_id])
|
||||||
respond_with(@post_set)
|
respond_with(@post_set)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -35,26 +35,26 @@ class Favorite
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def self.destroy_for_post_and_user(post_id, user_id)
|
def self.destroy_for_post_and_user(post_id, user_id)
|
||||||
execute_sql("DELETE FROM #{table_name_for(user_id)} WHERE post_id = #{post_id} AND user_id = #{user_id}")
|
execute_sql("DELETE FROM #{table_name_for(user_id)} WHERE post_id = #{post_id} AND user_id = #{user_id}")
|
||||||
end
|
|
||||||
|
|
||||||
def self.destroy_for_post(post)
|
|
||||||
0.upto(9) do |i|
|
|
||||||
execute_sql("DELETE FROM favorites_#{i} WHERE post_id = #{post.id}")
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.destroy_for_user(user)
|
def self.destroy_for_post(post)
|
||||||
execute_sql("DELETE FROM #{table_name_for(user)} WHERE user_id = #{user.id}")
|
0.upto(9) do |i|
|
||||||
end
|
execute_sql("DELETE FROM favorites_#{i} WHERE post_id = #{post.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.select_value_sql(sql, *params)
|
def self.destroy_for_user(user)
|
||||||
ActiveRecord::Base.select_value_sql(sql, *params)
|
execute_sql("DELETE FROM #{table_name_for(user)} WHERE user_id = #{user.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.execute_sql(sql, *params)
|
def self.select_value_sql(sql, *params)
|
||||||
ActiveRecord::Base.execute_sql(sql, *params)
|
ActiveRecord::Base.select_value_sql(sql, *params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.execute_sql(sql, *params)
|
||||||
|
ActiveRecord::Base.execute_sql(sql, *params)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
class PostSet
|
|
||||||
class Error < Exception ; end
|
|
||||||
|
|
||||||
attr_accessor :tags, :page, :before_id, :errors, :count
|
|
||||||
attr_accessor :wiki_page, :artist, :posts, :suggestions
|
|
||||||
|
|
||||||
def initialize(tags, page, before_id = nil)
|
|
||||||
@tags = Tag.normalize(tags)
|
|
||||||
@page = page.to_i
|
|
||||||
@before_id = before_id
|
|
||||||
@errors = []
|
|
||||||
load_associations
|
|
||||||
load_posts
|
|
||||||
load_suggestions
|
|
||||||
validate
|
|
||||||
end
|
|
||||||
|
|
||||||
def use_sequential_paginator?
|
|
||||||
!use_numbered_paginator?
|
|
||||||
end
|
|
||||||
|
|
||||||
def use_numbered_paginator?
|
|
||||||
before_id.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_errors?
|
|
||||||
errors.any?
|
|
||||||
end
|
|
||||||
|
|
||||||
def offset
|
|
||||||
x = (page - 1) * limit
|
|
||||||
if x < 0
|
|
||||||
x = 0
|
|
||||||
end
|
|
||||||
x
|
|
||||||
end
|
|
||||||
|
|
||||||
def limit
|
|
||||||
Danbooru.config.posts_per_page
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_single_tag?
|
|
||||||
tag_array.size == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
def date_tag
|
|
||||||
tag_array.grep(/date:/).first
|
|
||||||
end
|
|
||||||
|
|
||||||
def load_associations
|
|
||||||
if is_single_tag?
|
|
||||||
@wiki_page = WikiPage.find_by_title(tags)
|
|
||||||
@artist = Artist.find_by_name(tags)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def load_posts
|
|
||||||
@count = Post.fast_count(tags)
|
|
||||||
@posts = Post.find_by_tags(tags, :before_id => before_id).all(:order => "posts.id desc", :limit => limit, :offset => offset)
|
|
||||||
end
|
|
||||||
|
|
||||||
def load_suggestions
|
|
||||||
if count < limit && is_single_tag?
|
|
||||||
@suggestions = Tag.find_suggestions(tags)
|
|
||||||
else
|
|
||||||
@suggestions = []
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def tag_array
|
|
||||||
@tag_array ||= Tag.scan_query(tags)
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate
|
|
||||||
validate_page
|
|
||||||
validate_query_count
|
|
||||||
rescue Error => x
|
|
||||||
@errors << x.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_page
|
|
||||||
if page > 1_000
|
|
||||||
raise Error.new("You cannot explicitly specify the page after page 1000")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_query_count
|
|
||||||
if !CurrentUser.user.is_privileged? && tag_array.size > 2
|
|
||||||
raise Error.new("You can only search up to two tags at once with a basic account")
|
|
||||||
end
|
|
||||||
|
|
||||||
if tag_array.size > 6
|
|
||||||
raise Error.new("You can only search up to six tags at once")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_xml
|
|
||||||
posts.to_xml
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_json
|
|
||||||
posts.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
def presenter
|
|
||||||
@presnter ||= PostSetPresenter.new(self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
39
app/logical/post_sets/base.rb
Normal file
39
app/logical/post_sets/base.rb
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
module PostSets
|
||||||
|
class Base
|
||||||
|
attr_accessor :page, :before_id, :count
|
||||||
|
|
||||||
|
def initialize(options = {})
|
||||||
|
@page = options[:page].to_i
|
||||||
|
@before_id = options[:before_id]
|
||||||
|
load_posts
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_wiki?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def use_sequential_paginator?
|
||||||
|
!use_numbered_paginator?
|
||||||
|
end
|
||||||
|
|
||||||
|
def use_numbered_paginator?
|
||||||
|
before_id.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_posts
|
||||||
|
raise NotImplementedError
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_xml
|
||||||
|
posts.to_xml
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_json
|
||||||
|
posts.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def presenter
|
||||||
|
@presnter ||= PostSetPresenter.new(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
18
app/logical/post_sets/favorite.rb
Normal file
18
app/logical/post_sets/favorite.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
module PostSets
|
||||||
|
class FavoriteSet < Base
|
||||||
|
attr_accessor :user
|
||||||
|
|
||||||
|
def initialize(options = {})
|
||||||
|
super(options)
|
||||||
|
@user = user
|
||||||
|
end
|
||||||
|
|
||||||
|
def tags
|
||||||
|
"fav:#{user.name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_posts
|
||||||
|
user.favorite_posts(:before_id => before_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
92
app/logical/post_sets/post.rb
Normal file
92
app/logical/post_sets/post.rb
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
module PostSets
|
||||||
|
class Post < Base
|
||||||
|
class Error < Exception ; end
|
||||||
|
|
||||||
|
attr_accessor :tags, :errors, :count
|
||||||
|
attr_accessor :wiki_page, :artist, :suggestions
|
||||||
|
|
||||||
|
def initialize(tags, options = {})
|
||||||
|
super(options)
|
||||||
|
@tags = Tag.normalize(tags)
|
||||||
|
@errors = []
|
||||||
|
load_associations
|
||||||
|
load_suggestions
|
||||||
|
validate
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_wiki?
|
||||||
|
is_single_tag?
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_errors?
|
||||||
|
errors.any?
|
||||||
|
end
|
||||||
|
|
||||||
|
def offset
|
||||||
|
x = (page - 1) * limit
|
||||||
|
if x < 0
|
||||||
|
x = 0
|
||||||
|
end
|
||||||
|
x
|
||||||
|
end
|
||||||
|
|
||||||
|
def limit
|
||||||
|
Danbooru.config.posts_per_page
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_single_tag?
|
||||||
|
tag_array.size == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def date_tag
|
||||||
|
tag_array.grep(/date:/).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_associations
|
||||||
|
if is_single_tag?
|
||||||
|
@wiki_page = WikiPage.find_by_title(tags)
|
||||||
|
@artist = Artist.find_by_name(tags)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_posts
|
||||||
|
@count = Post.fast_count(tags)
|
||||||
|
@posts = Post.find_by_tags(tags, :before_id => before_id).all(:order => "posts.id desc", :limit => limit, :offset => offset)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_suggestions
|
||||||
|
if count < limit && is_single_tag?
|
||||||
|
@suggestions = Tag.find_suggestions(tags)
|
||||||
|
else
|
||||||
|
@suggestions = []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def tag_array
|
||||||
|
@tag_array ||= Tag.scan_query(tags)
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate
|
||||||
|
validate_page
|
||||||
|
validate_query_count
|
||||||
|
rescue Error => x
|
||||||
|
@errors << x.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_page
|
||||||
|
if page > 1_000
|
||||||
|
raise Error.new("You cannot explicitly specify the page after page 1000")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_query_count
|
||||||
|
if !CurrentUser.is_privileged? && tag_array.size > 2
|
||||||
|
raise Error.new("You can only search up to two tags at once with a basic account")
|
||||||
|
end
|
||||||
|
|
||||||
|
if tag_array.size > 6
|
||||||
|
raise Error.new("You can only search up to six tags at once")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -32,6 +32,10 @@ class Advertisement < ActiveRecord::Base
|
|||||||
"#{Rails.root}/public/images/advertisements/#{file_name}"
|
"#{Rails.root}/public/images/advertisements/#{file_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def file
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def file=(f)
|
def file=(f)
|
||||||
if f.size > 0
|
if f.size > 0
|
||||||
self.file_name = unique_identifier + File.extname(f.original_filename)
|
self.file_name = unique_identifier + File.extname(f.original_filename)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class PostSetPresenter < Presenter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def wiki_html(template)
|
def wiki_html(template)
|
||||||
if post_set.is_single_tag?
|
if post_set.has_wiki?
|
||||||
wiki_page = WikiPage.find_by_title(post_set.tags)
|
wiki_page = WikiPage.find_by_title(post_set.tags)
|
||||||
html = '<section>'
|
html = '<section>'
|
||||||
if wiki_page.nil?
|
if wiki_page.nil?
|
||||||
|
|||||||
@@ -1,28 +1,7 @@
|
|||||||
<% form_for @advertisement, :html => {:multipart => true} do |f| %>
|
<%= simple_form_for @advertisement, :html => {:multipart => true} do |f| %>
|
||||||
<table width="100%">
|
<%= f.input :file, :as => :file %>
|
||||||
<tfoot>
|
<%= f.input :referral_url %>
|
||||||
<tr>
|
<%= f.input :ad_type, :collection => %w(vertical horizontal) %>
|
||||||
<td></td>
|
<%= f.input :status, :collection => %w(active inactive) %>
|
||||||
<td><%= submit_tag "Submit" %></td>
|
<%= f.button :submit %>
|
||||||
</tr>
|
|
||||||
</tfoot>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th width="15%"><%= f.label :file %></th>
|
|
||||||
<td width="85%"><%= f.file_field "file" %></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><%= f.label :referral_url %></th>
|
|
||||||
<td><%= f.text_field :referral_url %></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><%= f.label :ad_type %></th>
|
|
||||||
<td><%= f.select :ad_type, ["vertical", "horizontal"] %></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th><%= f.label :status %></th>
|
|
||||||
<td><%= f.select :status, ["active", "inactive"] %></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -1,28 +1,5 @@
|
|||||||
<h4>Advertisements</h4>
|
<h4>Advertisements</h4>
|
||||||
|
|
||||||
<div style="margin-bottom: 1em;">
|
|
||||||
<% form_tag(advertisements_path, :method => :get) do %>
|
|
||||||
<table width="100%">
|
|
||||||
<tfoot>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<td><%= submit_tag "Search" %></td>
|
|
||||||
</tr>
|
|
||||||
</tfoot>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th width="15%"><label>Start Date</label></th>
|
|
||||||
<td width="85%"><%= text_field_tag "start_date", @start_date %></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th width="15%"><label>End Date</label></th>
|
|
||||||
<td width="85%"><%= text_field_tag "end_date", @end_date %></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<table width="100%" class="highlightable">
|
<table width="100%" class="highlightable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -20,9 +20,9 @@
|
|||||||
<td><%= h artist_version.other_names %></td>
|
<td><%= h artist_version.other_names %></td>
|
||||||
<td><%= h artist_version.group_name %></td>
|
<td><%= h artist_version.group_name %></td>
|
||||||
<td><%= time_ago_in_words artist_version.created_at %> ago</td>
|
<td><%= time_ago_in_words artist_version.created_at %> ago</td>
|
||||||
<td><%= link_to artist_version.updater_name, user_path(artist_version.user_id) %></td>
|
<td><%= link_to artist_version.updater_name, user_path(artist_version.updater_id) %></td>
|
||||||
<td><%= artist_version.is_active? %></td>
|
<td><%= artist_version.is_active? %></td>
|
||||||
<td><%= artist_version.urls.join(" ") %></td>
|
<td><%= artist_version.url_string %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<div class="favorites">
|
||||||
|
<div class="index">
|
||||||
|
<aside id="sidebar">
|
||||||
|
<section id="search-box">
|
||||||
|
<h1>Search Favorites</h1>
|
||||||
|
<%= form_tag(favorites_path, :method => "get") do %>
|
||||||
|
<%= text_field_tag("tags", params[:tags], :size => 20) %>
|
||||||
|
<%= submit_tag "Go" %>
|
||||||
|
<% end %>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<% if CurrentUser.is_privileged? %>
|
||||||
|
<section id="mode-box">
|
||||||
|
<%= render :partial => "posts/partials/index/mode_menu" %>
|
||||||
|
</section>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<section id="blacklist-box">
|
||||||
|
<h1>Blacklisted</h1>
|
||||||
|
<%= link_to "Hidden", "#" %>
|
||||||
|
<ul>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<section id="content">
|
||||||
|
<h1>Posts</h1>
|
||||||
|
<%= @post_set.presenter.post_previews_html %>
|
||||||
|
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
|
||||||
|
<div class="paginator">
|
||||||
|
<%= @post_set.presenter.pagination_html(self) %>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
/ fav:<%= CurrentUser.name %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -198,6 +198,10 @@ module Danbooru
|
|||||||
!user.is_privileged?
|
!user.is_privileged?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_user_advertiser?(user)
|
||||||
|
user.is_admin?
|
||||||
|
end
|
||||||
|
|
||||||
def can_user_see_post?(user, post)
|
def can_user_see_post?(user, post)
|
||||||
if is_user_restricted?(user) && is_post_restricted?(post)
|
if is_user_restricted?(user) && is_post_restricted?(post)
|
||||||
false
|
false
|
||||||
|
|||||||
@@ -31,5 +31,9 @@ module Danbooru
|
|||||||
</script>
|
</script>
|
||||||
}.html_safe
|
}.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_user_advertiser?(user)
|
||||||
|
user.is_admin? || user.name == "ppayne"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
17
test/functional/advertisement_hits_controller_test.rb
Normal file
17
test/functional/advertisement_hits_controller_test.rb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class AdvertisementHitsControllerTest < ActionController::TestCase
|
||||||
|
context "An advertisement hits controller" do
|
||||||
|
setup do
|
||||||
|
@ad = Factory.create(:advertisement)
|
||||||
|
@advertiser = Factory.create(:admin_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "create a new hit" do
|
||||||
|
assert_difference("AdvertisementHit.count", 1) do
|
||||||
|
post :create, {:id => @ad.id}
|
||||||
|
end
|
||||||
|
assert_redirected_to(@ad.referral_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,4 +1,58 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class AdvertisementsControllerTest < ActionController::TestCase
|
class AdvertisementsControllerTest < ActionController::TestCase
|
||||||
|
context "An advertisement controller" do
|
||||||
|
setup do
|
||||||
|
@ad = Factory.create(:advertisement)
|
||||||
|
@advertiser = Factory.create(:admin_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render the new page" do
|
||||||
|
get :new, {}, {:user_id => @advertiser.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render the edit page" do
|
||||||
|
get :edit, {:id => @ad.id}, {:user_id => @advertiser.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render the index page" do
|
||||||
|
get :index, {}, {:user_id => @advertiser.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render the show page" do
|
||||||
|
get :show, {:id => @ad.id}, {:user_id => @advertiser.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
should "create an ad" do
|
||||||
|
assert_difference("Advertisement.count", 1) do
|
||||||
|
post :create, {:advertisement => Factory.attributes_for(:advertisement)}, {:user_id => @advertiser.id}
|
||||||
|
end
|
||||||
|
ad = Advertisement.last
|
||||||
|
assert_redirected_to(advertisement_path(ad))
|
||||||
|
end
|
||||||
|
|
||||||
|
should "update an ad" do
|
||||||
|
post :update, {:id => @ad.id, :advertisement => {:width => 100}}, {:user_id => @advertiser.id}
|
||||||
|
ad = Advertisement.last
|
||||||
|
assert_equal(100, ad.width)
|
||||||
|
assert_redirected_to(advertisement_path(ad))
|
||||||
|
end
|
||||||
|
|
||||||
|
should "delete an ad" do
|
||||||
|
assert_difference("Advertisement.count", -1) do
|
||||||
|
post :destroy, {:id => @ad.id}, {:user_id => @advertiser.id}
|
||||||
|
end
|
||||||
|
assert_redirected_to(advertisements_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "block non-advertisers" do
|
||||||
|
regular_user = Factory.create(:user)
|
||||||
|
get :index, {}, {:user_id => regular_user.id}
|
||||||
|
assert_redirected_to("/static/access_denied")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,26 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ArtistVersionsControllerTest < ActionController::TestCase
|
class ArtistVersionsControllerTest < ActionController::TestCase
|
||||||
# Replace this with your real tests.
|
context "An artist versions controller" do
|
||||||
test "the truth" do
|
setup do
|
||||||
assert true
|
CurrentUser.user = Factory.create(:user)
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
@artist = Factory.create(:artist)
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
CurrentUser.ip_addr = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render the index page" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render the index page when searching for something" do
|
||||||
|
get :index, {:search => {:name_equals => @artist.name}}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user