From 98403d0cb728b3f8383512693c2c7a2e86af1c6f Mon Sep 17 00:00:00 2001 From: albert Date: Sun, 17 Jul 2011 18:40:24 -0400 Subject: [PATCH] fix user feedback controller test --- ...roller.rb => user_feedbacks_controller.rb} | 15 +++-- app/models/user_feedback.rb | 15 ++++- .../user_feedback/_secondary_links.html.erb | 7 --- app/views/user_feedback/index.html.erb | 42 ------------- app/views/user_feedback/new.html.erb | 29 --------- .../user_feedbacks/_secondary_links.html.erb | 6 ++ .../edit.html.erb | 0 app/views/user_feedbacks/index.html.erb | 32 ++++++++++ app/views/user_feedbacks/new.html.erb | 17 ++++++ app/views/user_feedbacks/show.html.erb | 14 +++++ config/initializers/inflections.rb | 1 - config/routes.rb | 2 +- db/development_structure.sql | 2 +- .../20100215230642_create_user_feedback.rb | 2 +- test/factories/user_feedback.rb | 4 +- ...t.rb => user_feedbacks_controller_test.rb} | 6 +- .../user_maintenance_controller_test.rb | 60 ------------------- 17 files changed, 100 insertions(+), 154 deletions(-) rename app/controllers/{user_feedback_controller.rb => user_feedbacks_controller.rb} (74%) delete mode 100644 app/views/user_feedback/_secondary_links.html.erb delete mode 100644 app/views/user_feedback/index.html.erb delete mode 100644 app/views/user_feedback/new.html.erb create mode 100644 app/views/user_feedbacks/_secondary_links.html.erb rename app/views/{user_feedback => user_feedbacks}/edit.html.erb (100%) create mode 100644 app/views/user_feedbacks/index.html.erb create mode 100644 app/views/user_feedbacks/new.html.erb create mode 100644 app/views/user_feedbacks/show.html.erb rename test/functional/{user_feedback_controller_test.rb => user_feedbacks_controller_test.rb} (88%) delete mode 100644 test/functional/user_maintenance_controller_test.rb diff --git a/app/controllers/user_feedback_controller.rb b/app/controllers/user_feedbacks_controller.rb similarity index 74% rename from app/controllers/user_feedback_controller.rb rename to app/controllers/user_feedbacks_controller.rb index 8cbcd11f7..4f550f86e 100644 --- a/app/controllers/user_feedback_controller.rb +++ b/app/controllers/user_feedbacks_controller.rb @@ -1,10 +1,10 @@ -class UserFeedbackController < ApplicationController +class UserFeedbacksController < ApplicationController before_filter :privileged_only, :only => [:new, :edit, :create, :update, :destroy] respond_to :html, :xml, :json rescue_from User::PrivilegeError, :with => "static/access_denied" def new - @user_feedback = UserFeedback.new + @user_feedback = UserFeedback.new(params[:user_feedback]) respond_with(@user_feedback) end @@ -14,10 +14,15 @@ class UserFeedbackController < ApplicationController respond_with(@user_feedback) end + def show + @user_feedback = UserFeedback.find(params[:id]) + respond_with(@user_feedback) + end + def index @search = UserFeedback.search(params[:search]) - @user_feedback = @search.paginate(:page => params[:page]) - respond_with(@user_feedback) + @user_feedbacks = @search.paginate(params[:page]) + respond_with(@user_feedbacks) end def create @@ -29,7 +34,7 @@ class UserFeedbackController < ApplicationController @user_feedback = UserFeedback.find(params[:id]) check_privilege(@user_feedback) @user_feedback.destroy - respond_with(@user_feedback, :location => user_feedback_path) + respond_with(@user_feedback) end private diff --git a/app/models/user_feedback.rb b/app/models/user_feedback.rb index e47c0508f..e10cba48a 100644 --- a/app/models/user_feedback.rb +++ b/app/models/user_feedback.rb @@ -3,14 +3,25 @@ class UserFeedback < ActiveRecord::Base belongs_to :user belongs_to :creator, :class_name => "User" before_validation :initialize_creator, :on => :create - attr_accessible :body, :user_id, :is_positive, :user_name - validates_presence_of :user, :creator, :body + attr_accessible :body, :user_id, :category, :user_name + validates_presence_of :user, :creator, :body, :category validate :creator_is_privileged + scope :positive, where("category = ?", "positive") + scope :neutral, where("category = ?", "neutral") + scope :negative, where("category = ?", "negative") def initialize_creator self.creator_id = CurrentUser.id end + def user_name + if user + user.name + else + nil + end + end + def user_name=(name) self.user_id = User.name_to_id(name) end diff --git a/app/views/user_feedback/_secondary_links.html.erb b/app/views/user_feedback/_secondary_links.html.erb deleted file mode 100644 index 38ecc2771..000000000 --- a/app/views/user_feedback/_secondary_links.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<% if @user %> - <% content_for("subnavbar") do %> -
  • <%= link_to "Add", :action => "create", :user_id => @user.id %>
  • -
  • <%= link_to "List for user", :action => "index", :user_id => @user.id %>
  • -
  • <%= link_to "List for all", :action => "index", :user_id => nil %>
  • - <% end %> -<% end %> diff --git a/app/views/user_feedback/index.html.erb b/app/views/user_feedback/index.html.erb deleted file mode 100644 index c4dfa2b96..000000000 --- a/app/views/user_feedback/index.html.erb +++ /dev/null @@ -1,42 +0,0 @@ -
    -

    Record

    - - - - - - - - - - - - - <% @user_records.each do |rec| %> - - - - - - - - <% end %> - -
    UserReporterWhenBody
    - <% if @user %> - <%= link_to h(rec.user.pretty_name), :controller => "user", :action => "show", :id => rec.user_id %> - <% else %> - <%= link_to h(rec.user.pretty_name), :action => "index", :user_id => rec.user_id %> - <% end %> - <%= h(rec.reporter.pretty_name) %><%= time_ago_in_words(rec.created_at) %> ago<%= format_text(rec.body) %> - <% if @current_user.is_mod_or_higher? || @current_user.id == rec.reported_by %> - <%= link_to_function "Delete", "UserRecord.destroy(#{rec.id})" %> - <% end %> -
    - -
    - <%= will_paginate(@user_records) %> -
    - - <%= render :partial => "footer" %> -
    diff --git a/app/views/user_feedback/new.html.erb b/app/views/user_feedback/new.html.erb deleted file mode 100644 index 725c7462a..000000000 --- a/app/views/user_feedback/new.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -

    Add Record for <%= h(@user.pretty_name) %>

    - -
    -
    - -<% form_tag(:action => "create") do %> - <%= hidden_field_tag "user_id", @user.id %> - - - - - - - - - - - - - - - - -
    <%= check_box "user_record", "is_positive" %>
    <%= text_area "user_record", "body", :size => "20x8" %>
    - <%= submit_tag "Submit" %> - <%= submit_to_remote "preview", "Preview", :url => {:action => "preview"}, :update => "preview", :method => :get %> - <%= button_to_function "Cancel", "location.back()" %> -
    -<% end %> diff --git a/app/views/user_feedbacks/_secondary_links.html.erb b/app/views/user_feedbacks/_secondary_links.html.erb new file mode 100644 index 000000000..2ade74dbb --- /dev/null +++ b/app/views/user_feedbacks/_secondary_links.html.erb @@ -0,0 +1,6 @@ +<% content_for(:secondary_links) do %> + +
  • <%= link_to "New", new_user_feedback_path %>
  • +
  • <%= link_to "Listing", user_feedbacks_path %>
  • +
    +<% end %> diff --git a/app/views/user_feedback/edit.html.erb b/app/views/user_feedbacks/edit.html.erb similarity index 100% rename from app/views/user_feedback/edit.html.erb rename to app/views/user_feedbacks/edit.html.erb diff --git a/app/views/user_feedbacks/index.html.erb b/app/views/user_feedbacks/index.html.erb new file mode 100644 index 000000000..2a1ca3570 --- /dev/null +++ b/app/views/user_feedbacks/index.html.erb @@ -0,0 +1,32 @@ +
    +
    +

    User Feedback

    + + + + + + + + + + + + <% @user_feedbacks.each do |feedback| %> + + + + + + + <% end %> + +
    UserCreatorWhenMessage
    <%= link_to feedback.user_name, user_feedback_path(feedback.user_id) %><%= feedback.creator.name %><%= time_ago_in_words(feedback.created_at) %> ago<%= format_text(feedback.body) %>
    + +
    + <%= numbered_paginator(@user_feedbacks) %> +
    + + <%= render "secondary_links" %> +
    +
    diff --git a/app/views/user_feedbacks/new.html.erb b/app/views/user_feedbacks/new.html.erb new file mode 100644 index 000000000..3f77bac0c --- /dev/null +++ b/app/views/user_feedbacks/new.html.erb @@ -0,0 +1,17 @@ +
    +
    +

    New User Feedback

    + +
    +
    + + <%= simple_form_for(@user_feedback) do |f| %> + <%= f.input :user_name %> + <%= f.input :category, :collection => ["positive", "neutral", "negative"] %> + <%= f.input :body %> + <%= f.button :submit %> + <%= f.button :submit, :value => "Preview" %> + <% end %> +
    +
    + diff --git a/app/views/user_feedbacks/show.html.erb b/app/views/user_feedbacks/show.html.erb new file mode 100644 index 000000000..d9aad7e2e --- /dev/null +++ b/app/views/user_feedbacks/show.html.erb @@ -0,0 +1,14 @@ +
    +
    +

    User Feedback For <%= @user_feedback.user_name %>

    + +
      +
    • Creator <%= @user_feedback.creator.name %>
    • +
    • Date <%= @user_feedback.created_at %>
    • +
    • Category <%= @user_feedback.category %>
    • +
    • Message <%= format_text @user_feedback.body %>
    • +
    +
    +
    + +<%= render "secondary_links" %> \ No newline at end of file diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index e9c87618f..e1e6e8322 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -2,5 +2,4 @@ ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' - inflect.uncountable %w( user_feedback ) end diff --git a/config/routes.rb b/config/routes.rb index 84d5d407a..fc663637d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -90,7 +90,7 @@ Danbooru::Application.routes.draw do resources :tag_subscriptions resources :uploads resources :users - resources :user_feedback + resources :user_feedbacks resources :wiki_pages do member do put :revert diff --git a/db/development_structure.sql b/db/development_structure.sql index d52b2ef10..713d10cf3 100644 --- a/db/development_structure.sql +++ b/db/development_structure.sql @@ -2396,7 +2396,7 @@ CREATE TABLE user_feedback ( id integer NOT NULL, user_id integer NOT NULL, creator_id integer NOT NULL, - is_positive boolean NOT NULL, + category character varying(255) NOT NULL, body text NOT NULL, created_at timestamp without time zone, updated_at timestamp without time zone diff --git a/db/migrate/20100215230642_create_user_feedback.rb b/db/migrate/20100215230642_create_user_feedback.rb index 042691330..f61a5b7f4 100644 --- a/db/migrate/20100215230642_create_user_feedback.rb +++ b/db/migrate/20100215230642_create_user_feedback.rb @@ -3,7 +3,7 @@ class CreateUserFeedback < ActiveRecord::Migration create_table :user_feedback do |t| t.column :user_id, :integer, :null => false t.column :creator_id, :integer, :null => false - t.column :is_positive, :boolean, :null => false + t.column :category, :string, :null => false t.column :body, :text, :null => false t.timestamps end diff --git a/test/factories/user_feedback.rb b/test/factories/user_feedback.rb index b8636dd9c..78e19b114 100644 --- a/test/factories/user_feedback.rb +++ b/test/factories/user_feedback.rb @@ -1,5 +1,5 @@ Factory.define(:user_feedback) do |f| f.user {|x| x.association(:user)} - f.is_positive true - f.body {Faker::Lorem.words} + f.category "positive" + f.body {Faker::Lorem.words.join(" ")} end diff --git a/test/functional/user_feedback_controller_test.rb b/test/functional/user_feedbacks_controller_test.rb similarity index 88% rename from test/functional/user_feedback_controller_test.rb rename to test/functional/user_feedbacks_controller_test.rb index 3b036a182..b3aeff62f 100644 --- a/test/functional/user_feedback_controller_test.rb +++ b/test/functional/user_feedbacks_controller_test.rb @@ -1,7 +1,7 @@ require 'test_helper' -class UserFeedbackControllerTest < ActionController::TestCase - context "The user feedback controller" do +class UserFeedbacksControllerTest < ActionController::TestCase + context "The user feedbacks controller" do setup do @user = Factory.create(:user) @critic = Factory.create(:privileged_user) @@ -53,7 +53,7 @@ class UserFeedbackControllerTest < ActionController::TestCase context "create action" do should "create a new feedback" do assert_difference("UserFeedback.count", 1) do - post :create, {:user_feedback => {:is_positive => false, :user_name => @user.name, :body => "xxx"}}, {:user_id => @critic.id} + post :create, {:user_feedback => {:category => "positive", :user_name => @user.name, :body => "xxx"}}, {:user_id => @critic.id} assert_not_nil(assigns(:user_feedback)) assert_equal([], assigns(:user_feedback).errors.full_messages) end diff --git a/test/functional/user_maintenance_controller_test.rb b/test/functional/user_maintenance_controller_test.rb deleted file mode 100644 index 79bec9947..000000000 --- a/test/functional/user_maintenance_controller_test.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'test_helper' - -class UserMaintenanceControllerTest < ActionController::TestCase - context "The user maintenance controller" do - setup do - @user = Factory.create(:user) - @blank_email_user = Factory.create(:user, :email => "") - CurrentUser.user = nil - CurrentUser.ip_addr = "127.0.0.1" - ActionMailer::Base.deliveries.clear - end - - teardown do - CurrentUser.user = nil - CurrentUser.ip_addr = nil - end - - context "login_reminder action" do - should "deliver an email with the login to the user" do - post :login_reminder, {:user => {:email => @user.email}} - assert_equal(flash[:notice], "Email sent") - assert_equal(1, ActionMailer::Base.deliveries.size) - end - - context "for a user with a blank email" do - should "fail" do - post :login_reminder, {:user => {:email => ""}} - assert_equal("No matching user record found", flash[:notice]) - @blank_email_user.reload - assert_equal(@blank_email_user.created_at, @blank_email_user.updated_at) - assert_equal(0, ActionMailer::Base.deliveries.size) - end - end - end - - context "reset_password action" do - setup do - @old_password = @user.password_hash - end - - should "reset the user's password and deliver an email to the user" do - post :reset_password, {:user => {:email => @user.email, :name => @user.name}} - assert_equal("Email sent", flash[:notice]) - @user.reload - assert_not_equal(@old_password, @user.password) - assert_equal(1, ActionMailer::Base.deliveries.size) - end - - context "for a user with a blank email" do - should "fail" do - post :reset_password, {:user => {:email => "", :name => @blank_email_user.name}} - assert_equal("No matching user record found", flash[:notice]) - @blank_email_user.reload - assert_equal(@blank_email_user.created_at, @blank_email_user.updated_at) - assert_equal(0, ActionMailer::Base.deliveries.size) - end - end - end - end -end