diff --git a/app/assets/javascripts/post_mode_menu.js b/app/assets/javascripts/post_mode_menu.js index 9efd7c45b..246d2d61b 100644 --- a/app/assets/javascripts/post_mode_menu.js +++ b/app/assets/javascripts/post_mode_menu.js @@ -15,6 +15,10 @@ Danbooru.PostModeMenu.initialize_shortcuts = function() { $(document).bind("keypress", "1 2 3 4 5 6 7 8 9 0", Danbooru.PostModeMenu.change_tag_script); } + + Danbooru.PostModeMenu.show_notice = function(i) { + Danbooru.notice("Switched to tag script #" + i + ". To switch tag scripts, use the number keys."); + } Danbooru.PostModeMenu.change_tag_script = function(e) { if ($("#mode-box select").val() === "tag-script") { @@ -27,7 +31,7 @@ $("#tag-script-field").val(new_tag_script); Danbooru.Cookie.put("current_tag_script_id", new_tag_script_id); if (old_tag_script_id != new_tag_script_id) { - Danbooru.notice("Switched to tag script #" + new_tag_script_id + ". To switch tag scripts, use the number keys."); + Danbooru.PostModeMenu.show_notice(new_tag_script_id); } e.preventDefault(); @@ -121,6 +125,7 @@ var script = Danbooru.Cookie.get("tag-script-" + current_script_id); $("#tag-script-field").val(script).show(); + Danbooru.PostModeMenu.show_notice(current_script_id); } else { $("#tag-script-field").hide(); } diff --git a/app/assets/stylesheets/specific/meta_searches.css.scss b/app/assets/stylesheets/specific/meta_searches.css.scss new file mode 100644 index 000000000..98133734d --- /dev/null +++ b/app/assets/stylesheets/specific/meta_searches.css.scss @@ -0,0 +1,5 @@ +#c-meta-searches { + section { + margin-bottom: 2em; + } +} \ No newline at end of file diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 64a317543..fdb721cd4 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -9,24 +9,8 @@ module Admin def update @user = User.find(params[:id]) - sanitize_params! - @user.level = params[:user][:level] - @user.inviter_id = CurrentUser.id - TransactionLogItem.record_account_upgrade(@user) - @user.save + @user.promote_to!(params[:user][:level]) redirect_to edit_admin_user_path(@user), :notice => "User updated" end - - protected - def sanitize_params! - # admins can do anything - return if CurrentUser.is_admin? - - # can't promote/demote moderators - raise User::PrivilegeError if @user.is_moderator? - - # can't promote to admin - raise User::PrivilegeError if params[:user] && params[:user][:level].to_i >= User::Levels::ADMIN - end end end diff --git a/app/controllers/meta_searches_controller.rb b/app/controllers/meta_searches_controller.rb new file mode 100644 index 000000000..c9fd25126 --- /dev/null +++ b/app/controllers/meta_searches_controller.rb @@ -0,0 +1,6 @@ +class MetaSearchesController < ApplicationController + def tags + @meta_search = MetaSearches::Tag.new(params) + @meta_search.load_all + end +end diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index 67106a213..96a55ff8f 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -12,14 +12,6 @@ class TagAliasesController < ApplicationController respond_with(@tag_alias) end - def general_search - if params[:commit] == "Search Aliases" - redirect_to tag_aliases_path(:search => {:name_matches => params[:query]}) - else - redirect_to tag_implications_path(:search => {:name_matches => params[:query]}) - end - end - def index @search = TagAlias.search(params[:search]) @tag_aliases = @search.order("(case status when 'pending' then 0 when 'queued' then 1 else 2 end), antecedent_name, consequent_name").paginate(params[:page], :limit => params[:limit]) diff --git a/app/controllers/user_name_change_requests_controller.rb b/app/controllers/user_name_change_requests_controller.rb index 2d9ff126a..2f62cf54e 100644 --- a/app/controllers/user_name_change_requests_controller.rb +++ b/app/controllers/user_name_change_requests_controller.rb @@ -51,7 +51,7 @@ class UserNameChangeRequestsController < ApplicationController private def check_privileges!(change_request) - return if CurrentUser.is_janitor? + return if CurrentUser.is_admin? raise User::PrivilegeError if change_request.user_id != CurrentUser.user.id end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2bbb33d59..ac05ecbaa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,8 @@ module ApplicationHelper + def wordbreakify(string) + raw(string.gsub(/(.{10})/, "\\1")) + end + def nav_link_to(text, url, options = nil) if nav_link_match(params[:controller], url) klass = "current" @@ -139,7 +143,7 @@ protected when "artists", "artist_versions" /^\/artist/ - when "tags" + when "tags", "meta_searches" /^\/tags/ when "pools", "pool_versions" diff --git a/app/helpers/post_versions_helper.rb b/app/helpers/post_versions_helper.rb index aa9716d58..a344ed09c 100644 --- a/app/helpers/post_versions_helper.rb +++ b/app/helpers/post_versions_helper.rb @@ -4,14 +4,14 @@ module PostVersionsHelper html = [] diff[:added_tags].each do |tag| prefix = diff[:obsolete_added_tags].include?(tag) ? '+' : '+' - html << prefix + link_to(tag, posts_path(:tags => tag)) + '' + html << prefix + link_to(wordbreakify(tag), posts_path(:tags => tag)) + '' end diff[:removed_tags].each do |tag| prefix = diff[:obsolete_removed_tags].include?(tag) ? '-' : '-' - html << prefix + link_to(tag, posts_path(:tags => tag)) + '' + html << prefix + link_to(wordbreakify(tag), posts_path(:tags => tag)) + '' end diff[:unchanged_tags].each do |tag| - html << '' + link_to(tag, posts_path(:tags => tag)) + '' + html << '' + link_to(wordbreakify(tag), posts_path(:tags => tag)) + '' end return html.join(" ").html_safe end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 2abf9b765..5c753f7f3 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -19,11 +19,11 @@ module PostsHelper def post_source_tag(post) if post.source =~ %r!http://img\d+\.pixiv\.net/img/([^\/]+)/! - text = "pixiv/#{$1}" + text = "pixiv/#{wordbreakify($1)}" source_link = link_to(text, post.normalized_source) source_search = "source:#{text}/" elsif post.source =~ %r!http://i\d\.pixiv\.net/img\d+/img/([^\/]+)/! - text = "pixiv/#{$1}" + text = "pixiv/#{wordbreakify($1)}" source_link = link_to(text, post.normalized_source) source_search = "source:#{text}/" elsif post.source =~ %r{\Ahttps?://} diff --git a/app/logical/api_cache_generator.rb b/app/logical/api_cache_generator.rb index b871520ee..e0aa15f1e 100644 --- a/app/logical/api_cache_generator.rb +++ b/app/logical/api_cache_generator.rb @@ -1,7 +1,8 @@ class ApiCacheGenerator def generate_tag_cache - FileUtils.mkdir_p("/var/www/danbooru2/shared/system/cache") - File.open("/var/www/danbooru2/shared/system/cache/tags.json", "w") do |f| + path = File.expand_path(File.join(Rails.root, "..", "shared")) + FileUtils.mkdir_p("#{path}/system/cache") + File.open("#{path}/system/cache/tags.json", "w") do |f| f.print("[") Tag.without_timeout do Tag.find_each do |tag| @@ -20,11 +21,11 @@ class ApiCacheGenerator f.seek(-2, IO::SEEK_END) f.print("]\n") end - Zlib::GzipWriter.open("/var/www/danbooru2/shared/system/cache/tags.json.gz") do |gz| - gz.write(IO.binread("/var/www/danbooru2/shared/system/cache/tags.json")) + Zlib::GzipWriter.open("#{path}/system/cache/tags.json.gz") do |gz| + gz.write(IO.binread("#{path}/system/cache/tags.json")) gz.close end - RemoteFileManager.new("/var/www/danbooru2/shared/system/cache/tags.json").distribute - RemoteFileManager.new("/var/www/danbooru2/shared/system/cache/tags.json.gz").distribute + RemoteFileManager.new("#{path}/system/cache/tags.json").distribute + RemoteFileManager.new("#{path}/shared/system/cache/tags.json.gz").distribute end end diff --git a/app/logical/daily_maintenance.rb b/app/logical/daily_maintenance.rb index c127e09ec..c648a944a 100644 --- a/app/logical/daily_maintenance.rb +++ b/app/logical/daily_maintenance.rb @@ -7,6 +7,7 @@ class DailyMaintenance ModAction.delete_all(['created_at < ?', 3.days.ago]) Delayed::Job.delete_all(['created_at < ?', 7.days.ago]) PostVote.delete_all(['created_at < ?', 1.month.ago]) + CommentVote.delete_all(['created_at < ?', 1.month.ago]) TagSubscription.process_all ApiCacheGenerator.new.generate_tag_cache end diff --git a/app/logical/meta_searches/tag.rb b/app/logical/meta_searches/tag.rb new file mode 100644 index 000000000..46eec97d3 --- /dev/null +++ b/app/logical/meta_searches/tag.rb @@ -0,0 +1,30 @@ +class MetaSearches::Tag + MAX_RESULTS = 25 + attr_reader :search_params, :tags, :tag_aliases, :tag_implications + + def initialize(search_params) + @search_params = search_params + end + + def load_all + load_tags + load_tag_aliases + load_tag_implications + end + + def load_tags + @tags = ::Tag.name_matches(name_param).limit(MAX_RESULTS) + end + + def load_tag_aliases + @tag_aliases = TagAlias.name_matches(name_param).limit(MAX_RESULTS) + end + + def load_tag_implications + @tag_implications = TagImplication.name_matches(name_param).limit(MAX_RESULTS) + end + + def name_param + search_params[:name] || "" + end +end diff --git a/app/logical/user_promotion.rb b/app/logical/user_promotion.rb new file mode 100644 index 000000000..d6a2d0e83 --- /dev/null +++ b/app/logical/user_promotion.rb @@ -0,0 +1,78 @@ +class UserPromotion + attr_reader :user, :promoter, :new_level + + def initialize(user, promoter, new_level) + @user = user + @promoter = promoter + @new_level = new_level + end + + def promote! + user.level = new_level + user.inviter_id = promoter.id + + validate + create_transaction_log_item + create_user_feedback + create_dmail + + user.save + end + +private + + def validate + # admins can do anything + return if promoter.is_admin? + + # can't promote/demote moderators + raise User::PrivilegeError if user.is_moderator? + + # can't promote to admin + raise User::PrivilegeError if new_level.to_i >= User::Levels::ADMIN + end + + def create_transaction_log_item + TransactionLogItem.record_account_upgrade(user) + end + + def create_user_feedback + if user.level > user.level_was + body_prefix = "Promoted" + elsif user.level < user.level_was + body_prefix = "Demoted" + else + body_prefix = "Updated" + end + + user.feedback.create( + :category => "neutral", + :body => "#{body_prefix} by #{promoter.name} from #{user.level_string_was} to #{user.level_string}", + :disable_dmail_notification => true + ) + end + + def create_dmail + if user.level >= user.level_was + create_promotion_dmail + else + create_demotion_dmail + end + end + + def create_promotion_dmail + Dmail.create_split( + :to_id => user.id, + :title => "You have been promoted", + :body => "You have been promoted to a #{user.level_string} level account." + ) + end + + def create_demotion_dmail + Dmail.create_split( + :to_id => user.id, + :title => "You have been demoted", + :body => "You have been demoted to a #{user.level_string} level account." + ) + end +end diff --git a/app/models/post.rb b/app/models/post.rb index fdc70ee56..3a9dfe6bd 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -624,7 +624,7 @@ class Post < ActiveRecord::Base module FavoriteMethods def clean_fav_string? - rand(100) < [Math.log(fav_string.size, 2), 5].min + rand(100) < 50 end def clean_fav_string! diff --git a/app/models/user.rb b/app/models/user.rb index b37409996..99b181b48 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -242,8 +242,8 @@ class User < ActiveRecord::Base end end - def promote_to(level) - update_attributes({:level => level}, :as => :admin) + def promote_to!(new_level) + UserPromotion.new(self, CurrentUser.user, new_level).promote! end def promote_to_admin_if_first_user @@ -281,6 +281,10 @@ class User < ActiveRecord::Base end end + def level_string_was + level_string(level_was) + end + def level_string(value = nil) case (value || level) when Levels::BLOCKED @@ -357,7 +361,7 @@ class User < ActiveRecord::Base def create_mod_action if level_changed? - ModAction.create(:description => %{"#{name}":/users/#{id} level changed #{level_string(level_was)} -> #{level_string}}) + ModAction.create(:description => %{"#{name}":/users/#{id} level changed #{level_string_was} -> #{level_string}}) end end diff --git a/app/models/user_feedback.rb b/app/models/user_feedback.rb index ed8f5e7ff..70933353b 100644 --- a/app/models/user_feedback.rb +++ b/app/models/user_feedback.rb @@ -3,7 +3,8 @@ class UserFeedback < ActiveRecord::Base belongs_to :user belongs_to :creator, :class_name => "User" before_validation :initialize_creator, :on => :create - attr_accessible :body, :user_id, :category, :user_name + attr_accessor :disable_dmail_notification + attr_accessible :body, :user_id, :category, :user_name, :disable_dmail_notification validates_presence_of :user, :creator, :body, :category validates_inclusion_of :category, :in => %w(positive negative neutral) validate :creator_is_gold @@ -74,8 +75,10 @@ class UserFeedback < ActiveRecord::Base end def create_dmail - body = %{#{creator_name} created a "#{category} record":/user_feedbacks?search[user_id]=#{user_id} for your account. #{body}} - Dmail.create_split(:to_id => user_id, :title => "Your user record has been updated", :body => body) + unless disable_dmail_notification + body = %{#{creator_name} created a "#{category} record":/user_feedbacks?search[user_id]=#{user_id} for your account. #{body}} + Dmail.create_split(:to_id => user_id, :title => "Your user record has been updated", :body => body) + end end def creator_is_gold diff --git a/app/views/meta_searches/tags.html.erb b/app/views/meta_searches/tags.html.erb new file mode 100644 index 000000000..21a3bffb3 --- /dev/null +++ b/app/views/meta_searches/tags.html.erb @@ -0,0 +1,129 @@ +
+
+

MetaSearch Tags

+ +
+ <%= form_tag(meta_searches_tags_path, :method => :get) do %> + <%= text_field_tag "name", params[:name] %> + <%= submit_tag "Go" %> + <% end %> +
+ +
+

Tags

+ + <% if @meta_search.tags.empty? %> +

No results

+ <% else %> + + + + + + + + + + + <% @meta_search.tags.each do |tag| %> + + + + + + <% end %> + +
NameCount
<%= tag.name %><%= tag.post_count %> + <% if tag.editable_by?(CurrentUser.user) %> + <%= link_to "edit", edit_tag_path(tag) %> + <% end %> + <% if CurrentUser.is_builder? %> + | <%= link_to "fix", new_tag_correction_path(:tag_id => tag.id) %> + <% end %> +
+ <% end %> +
+ + +
+

Tag Aliases

+ <% if @meta_search.tag_aliases.empty? %> +

No results

+ <% else %> + + + + + + + + + + + <% @meta_search.tag_aliases.each do |tag_alias| %> + + + + + + <% end %> + +
FromTo
<%= tag_alias.antecedent_name %><%= tag_alias.consequent_name %> + <%= link_to "Show", tag_alias_path(tag_alias) %> + <% if tag_alias.deletable_by?(CurrentUser.user) %> + | <%= link_to "Delete", tag_alias_path(tag_alias), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this alias?" %> + <% end %> + + <% if CurrentUser.is_admin? && tag_alias.is_pending? %> + | <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %> + <% end %> + + <% if CurrentUser.is_janitor? %> + | <%= link_to "Fix", tag_alias_correction_path(:tag_alias_id => tag_alias.id) %> + <% end %> +
+ <% end %> +
+ +
+

Tag Implications

+ <% if @meta_search.tag_implications.empty? %> +

No results

+ <% else %> + + + + + + + + + + + <% @meta_search.tag_implications.each do |tag_implication| %> + + + + + + <% end %> + +
FromTo
<%= tag_implication.antecedent_name %><%= tag_implication.consequent_name %> + <%= link_to "Show", tag_implication_path(tag_implication) %> + <% if tag_implication.deletable_by?(CurrentUser.user) %> + | <%= link_to "Delete", tag_implication_path(tag_implication), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this implication?" %> + <% end %> + <% if CurrentUser.user.is_admin? && tag_implication.is_pending? %> + | <%= link_to "Approve", approve_tag_implication_path(tag_implication), :remote => true, :method => :post %> + <% end %> +
+ <% end %> +
+
+
+ +<%= render "tags/secondary_links" %> + +<% content_for(:page_title) do %> + MetaSearch - Tags - <%= Danbooru.config.app_name %> +<% end %> \ No newline at end of file diff --git a/app/views/posts/partials/index/_mode_menu.html.erb b/app/views/posts/partials/index/_mode_menu.html.erb index a16e63c21..a2edbc453 100644 --- a/app/views/posts/partials/index/_mode_menu.html.erb +++ b/app/views/posts/partials/index/_mode_menu.html.erb @@ -22,6 +22,6 @@ <% end %> + - <% end %> diff --git a/app/views/tag_aliases/_secondary_links.html.erb b/app/views/tag_aliases/_secondary_links.html.erb index b7fc8f59c..663069a99 100644 --- a/app/views/tag_aliases/_secondary_links.html.erb +++ b/app/views/tag_aliases/_secondary_links.html.erb @@ -1,6 +1,7 @@ <% content_for(:secondary_links) do %>
  • <%= link_to "Listing", tag_aliases_path %>
  • +
  • <%= link_to "MetaSearch", meta_searches_tags_path %>
  • <% if CurrentUser.is_admin? %>
  • <%= link_to "New", new_tag_alias_path %>
  • <% else %> diff --git a/app/views/tag_aliases/index.html.erb b/app/views/tag_aliases/index.html.erb index 10f98ca82..6e74c4ad6 100644 --- a/app/views/tag_aliases/index.html.erb +++ b/app/views/tag_aliases/index.html.erb @@ -1,10 +1,9 @@
    diff --git a/app/views/tag_implications/_secondary_links.html.erb b/app/views/tag_implications/_secondary_links.html.erb index 77351b538..aafe29969 100644 --- a/app/views/tag_implications/_secondary_links.html.erb +++ b/app/views/tag_implications/_secondary_links.html.erb @@ -1,6 +1,7 @@ <% content_for(:secondary_links) do %>
  • <%= link_to "Listing", tag_implications_path %>
  • +
  • <%= link_to "MetaSearch", meta_searches_tags_path %>
  • <% if CurrentUser.is_admin? %>
  • <%= link_to "New", new_tag_implication_path %>
  • <% else %> diff --git a/app/views/tag_implications/index.html.erb b/app/views/tag_implications/index.html.erb index 6c018da22..46e54abe5 100644 --- a/app/views/tag_implications/index.html.erb +++ b/app/views/tag_implications/index.html.erb @@ -1,10 +1,9 @@
    diff --git a/app/views/tags/_secondary_links.html.erb b/app/views/tags/_secondary_links.html.erb index 672a295a4..854f4eff6 100644 --- a/app/views/tags/_secondary_links.html.erb +++ b/app/views/tags/_secondary_links.html.erb @@ -2,8 +2,7 @@
  • <%= render "tags/quick_search" %>
  • <%= link_to "Listing", tags_path %>
  • -
  • <%= link_to "Aliases", tag_aliases_path %>
  • -
  • <%= link_to "Implications", tag_implications_path %>
  • +
  • <%= link_to "MetaSearch", meta_searches_tags_path %>
  • <%= link_to "Cheatsheet", wiki_pages_path(:search => {:title => "help:cheatsheet"}) %>
  • <%= link_to "Help", wiki_pages_path(:search => {:title => "help:tags"}) %>
  • <% if @tag %> diff --git a/app/views/users/_post_summary.html.erb b/app/views/users/_post_summary.html.erb index 6675133a9..e3093232b 100644 --- a/app/views/users/_post_summary.html.erb +++ b/app/views/users/_post_summary.html.erb @@ -1,28 +1,24 @@ -
    -

    <%= link_to "Uploads", posts_path(:tags => "user:#{user.name}") %>

    - <% if presenter.has_uploads? %> +<% if presenter.has_uploads? %> +
    +

    <%= link_to "Uploads", posts_path(:tags => "user:#{user.name}") %>

    <% presenter.uploads.each do |post| %> <%= PostPresenter.preview(post, :tags => "user:#{user.name}") %> <% end %>
    - <% else %> -

    None

    - <% end %> -
    +
    +<% end %> -
    -

    <%= link_to "Favorites", favorites_path(:user_id => user.id) %>

    - <% if presenter.has_favorites? %> +<% if presenter.has_favorites? %> +
    +

    <%= link_to "Favorites", favorites_path(:user_id => user.id) %>

    <% presenter.favorites.each do |post| %> <%= PostPresenter.preview(post, :tags => "fav:#{user.name}") %> <% end %>
    - <% else %> -

    None

    - <% end %> -
    +
    +<% end %> <% presenter.subscriptions.each do |subscription| %>
    diff --git a/config/deploy.rb b/config/deploy.rb index 8be25577b..cb37b7251 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -14,6 +14,10 @@ set :whenever_command, "bundle exec whenever" set :whenever_environment, defer {stage} require 'whenever/capistrano' +require 'securerandom' +set :secret_1, SecureRandom.base64(32) +set :secret_2, SecureRandom.base64(32) + set :application, "danbooru" set :repository, "git://github.com/r888888888/danbooru.git" set :scm, :git @@ -30,6 +34,15 @@ namespace :local_config do run "mkdir -p #{deploy_to}/shared/config" end + desc "Initialize the secrets" + task :setup_secrets do + run "mkdir -p ~/.danbooru" + run "if [[ ! -e ~/.danbooru/session_secret_key ]] ; then echo '#{secret_1}' > ~/.danbooru/session_secret_key ; fi" + run "if [[ ! -e ~/.danbooru/secret_token ]] ; then echo '#{secret_2}' > ~/.danbooru/secret_token ; fi" + run "chmod -R 600 ~/.danbooru" + run "chown -R #{user}:#{user} ~/.danbooru" + end + desc "Initialize local config files" task :setup_local_files do run "curl -s https://raw.github.com/r888888888/danbooru/master/script/install/danbooru_local_config.rb.templ > #{deploy_to}/shared/config/danbooru_local_config.rb" @@ -138,6 +151,7 @@ after "deploy:setup", "reset_ownership_of_common_directory" after "deploy:setup", "local_config:setup_shared_directory" after "deploy:setup", "local_config:setup_local_files" after "deploy:setup", "data:setup_directories" +after "deploy:setup", "local_config:setup_secrets" after "deploy:create_symlink", "local_config:link_local_files" after "deploy:create_symlink", "data:link_directories" after "deploy:start", "delayed_job:start" diff --git a/config/routes.rb b/config/routes.rb index e2cb274d9..dc85c2382 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -202,9 +202,6 @@ Danbooru::Application.routes.draw do member do post :approve end - collection do - get :general_search - end end resource :tag_alias_request, :only => [:new, :create] resources :tag_implications do @@ -370,6 +367,7 @@ Danbooru::Application.routes.draw do match "/static/contact" => "static#contact", :as => "contact" match "/static/benchmark" => "static#benchmark" match "/static/name_change" => "static#name_change", :as => "name_change" + match "/meta_searches/tags" => "meta_searches#tags", :as => "meta_searches_tags" root :to => "posts#index" end diff --git a/test/unit/meta_searches/tag_test.rb b/test/unit/meta_searches/tag_test.rb new file mode 100644 index 000000000..fdb5b8a02 --- /dev/null +++ b/test/unit/meta_searches/tag_test.rb @@ -0,0 +1,36 @@ +require "test_helper" + +module MetaSearches + class TagTest < ActionMailer::TestCase + context "The tag metasearcg" do + setup do + CurrentUser.user = FactoryGirl.create(:user) + CurrentUser.ip_addr = "127.0.0.1" + FactoryGirl.create(:tag, :name => "xxx") + FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb") + FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd") + end + + should "find the tag" do + meta_search = Tag.new(:name => "xxx") + meta_search.load_all + assert_equal(1, meta_search.tags.size) + assert_equal("xxx", meta_search.tags.first.name) + end + + should "find the alias" do + meta_search = Tag.new(:name => "aaa") + meta_search.load_all + assert_equal(1, meta_search.tag_aliases.size) + assert_equal("aaa", meta_search.tag_aliases.first.antecedent_name) + end + + should "find the implication" do + meta_search = Tag.new(:name => "ccc") + meta_search.load_all + assert_equal(1, meta_search.tag_implications.size) + assert_equal("ccc", meta_search.tag_implications.first.antecedent_name) + end + end + end +end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 26255e5fb..297f09d08 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -13,6 +13,32 @@ class UserTest < ActiveSupport::TestCase CurrentUser.user = nil CurrentUser.ip_addr = nil end + + context "promoting a user" do + setup do + CurrentUser.user = FactoryGirl.create(:moderator_user) + end + + should "create a transaction log item" do + assert_difference("TransactionLogItem.count") do + @user.promote_to!(User::Levels::GOLD) + end + end + + should "create a neutral feedback" do + assert_difference("UserFeedback.count") do + @user.promote_to!(User::Levels::GOLD) + end + + assert_equal("Promoted by #{CurrentUser.user.name} from Member to Gold", @user.feedback.last.body) + end + + should "create a dmail" do + assert_difference("Dmail.count", 2) do + @user.promote_to!(User::Levels::GOLD) + end + end + end context "favoriting a post" do setup do