fixes #145: add test function for janitor trials

This commit is contained in:
albert
2011-10-21 17:56:02 -04:00
parent 0eb665af0d
commit 3b1d01370a
6 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
(function() {
Danbooru.JanitorTrials = {};
Danbooru.JanitorTrials.initialize_all = function() {
$("#c-janitor-trials input[value=Test]").click(function(e) {
$.ajax({
type: "get",
url: "/janitor_trials/test.json",
data: {
janitor_trial: {
user_name: $("#janitor_trial_user_name").val()
}
},
success: function(data) {
$("#test-results").html(data);
}
});
e.preventDefault();
});
}
})();
$(document).ready(function() {
Danbooru.JanitorTrials.initialize_all();
});

View File

@@ -37,4 +37,8 @@ class JanitorTrialsController < ApplicationController
format.js
end
end
def test
@tester = JanitorTrialTester.new(params[:janitor_trial][:user_name])
end
end

View File

@@ -0,0 +1,21 @@
class JanitorTrialTester
attr_reader :user
def initialize(user_name)
@user = User.find_by_name(user_name)
end
def test
if user.nil?
"User not found"
elsif user.created_at > 1.month.ago
"User signed up within the past month"
elsif user.favorites.count < 100
"User has fewer than 100 favorites"
elsif user.feedback.negative.count > 0
"User has negative feedback"
else
"No issues found"
end
end
end

View File

@@ -5,7 +5,10 @@
<%= simple_form_for(@janitor_trial) do |f| %>
<%= f.input :user_name %>
<%= f.button :submit, "Submit" %>
<%= f.button :submit, "Test" %>
<% end %>
<p id="test-results"></p>
</div>
</div>

View File

@@ -0,0 +1 @@
<%= raw @tester.test.to_json %>

View File

@@ -66,6 +66,9 @@ Danbooru::Application.routes.draw do
end
end
resources :janitor_trials do
collection do
get :test
end
member do
put :promote
put :demote