From 02a03f7c541e97594e061c80816e74cc28d2051a Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 17 Feb 2014 15:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E8=88=AA=E6=A0=8F=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E6=84=8F=E5=A4=96http=E5=8F=82=E6=95=B0=E4=B8=8D=E5=85=A8?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 -- app/controllers/users_controller.rb | 16 ++++++------ app/views/layouts/base.html.erb | 1 + test/fixtures/.gitkeep | 0 test/fixtures/memos.yml | 23 ++++++++++++++++++ test/fixtures/user_extensions.yml | 20 +++++++++++++++ test/fixtures/users.yml | 20 +++++++++++++++ test/functional/.gitkeep | 0 test/functional/memos_controller_test.rb | 11 +++++++++ test/functional/test_controller_test.rb | 13 ++++++++++ test/functional/users_controller_test.rb | 31 ++++++++++++++++++++++++ test/integration/.gitkeep | 0 test/performance/browsing_test.rb | 12 +++++++++ test/test_helper.rb | 13 ++++++++++ test/unit/.gitkeep | 0 test/unit/helpers/courses_helper_test.rb | 12 +++++++++ test/unit/helpers/memos_helper_test.rb | 4 +++ test/unit/helpers/stores_helper_test.rb | 4 +++ test/unit/helpers/test_helper_test.rb | 4 +++ test/unit/memo_test.rb | 16 ++++++++++++ 20 files changed, 192 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/.gitkeep create mode 100644 test/fixtures/memos.yml create mode 100644 test/fixtures/user_extensions.yml create mode 100644 test/fixtures/users.yml create mode 100644 test/functional/.gitkeep create mode 100644 test/functional/memos_controller_test.rb create mode 100644 test/functional/test_controller_test.rb create mode 100644 test/functional/users_controller_test.rb create mode 100644 test/integration/.gitkeep create mode 100644 test/performance/browsing_test.rb create mode 100644 test/test_helper.rb create mode 100644 test/unit/.gitkeep create mode 100644 test/unit/helpers/courses_helper_test.rb create mode 100644 test/unit/helpers/memos_helper_test.rb create mode 100644 test/unit/helpers/stores_helper_test.rb create mode 100644 test/unit/helpers/test_helper_test.rb create mode 100644 test/unit/memo_test.rb diff --git a/.gitignore b/.gitignore index d6b5ecb82..daa8b3ace 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,8 @@ /config/database.yml /files/* /log/* -/test/* /tmp/* .gitignore -/config/database.yml /public/images/avatars/* /Gemfile /Gemfile.lock diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5db2d0cf5..2a825e303 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -166,6 +166,14 @@ class UsersController < ApplicationController end def user_courses + + unless User.current.admin? + if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?) + render_404 + return + end + end + membership = @user.memberships.all(:conditions => Project.visible_condition(User.current)) membership.sort! {|older, newer| newer.created_on <=> older.created_on } @memberships = [] @@ -184,14 +192,6 @@ class UsersController < ApplicationController @memberships_done.push e end } - - unless User.current.admin? - if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?) - render_404 - return - end - end - # respond_to do |format| # format.html # format.api diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index ff02ca08e..a6b00aee0 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -1,4 +1,5 @@ <% + request.headers['REQUEST_URI'] = "" if request.headers['REQUEST_URI'].nil? if (request.headers['REQUEST_URI'].match(/course/)) @nav_dispaly_course_label = 1 elsif (request.headers['REQUEST_URI'].match(/projects/)) diff --git a/test/fixtures/.gitkeep b/test/fixtures/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/memos.yml b/test/fixtures/memos.yml new file mode 100644 index 000000000..c9148080a --- /dev/null +++ b/test/fixtures/memos.yml @@ -0,0 +1,23 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + parent_id: 1 + forum_id: 1 + subject: MyString + content: MyText + author_id: 1 + replies_count: 1 + last_reply_id: 1 + lock: false + sticky: false + +two: + parent_id: 1 + forum_id: 1 + subject: MyString + content: MyText + author_id: 1 + replies_count: 1 + last_reply_id: 1 + lock: false + sticky: false diff --git a/test/fixtures/user_extensions.yml b/test/fixtures/user_extensions.yml new file mode 100644 index 000000000..4121ad653 --- /dev/null +++ b/test/fixtures/user_extensions.yml @@ -0,0 +1,20 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +person_one_extra: + id: 44 + user_id: 29 + birthday: "2013-09-30 21:19:25" + brief_introduction: nil + gender: 1 + location: "江苏" + occupation: "" + work_experience: nil + zip_code: nil + created_at: "2013-09-30 21:19:25" + updated_at: "2013-10-09 19:00:06" + technical_title: nil + identity: 2 + student_id: nil + teacher_realname: nil + student_realname: nil + location_city: "南京" diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 000000000..6e371c4b2 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,20 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +person_one: + id: 29 + login: "yanxd" + hashed_password: "432257ccaebe6b33158a88b2db2135796505762b" + firstname: "Inc." + lastname: "yan" + mail: "test@hotmail.com" + admin: 0 + status: 1 + last_login_on: "2014-02-17 08:27:52" + language: "zh" + auth_source_id: nil + created_on: "2013-07-11 08:33:38" + updated_on: "2013-10-25 09:37:40" + type: "User" + identity_url: nil + mail_notification: "only_my_events" + salt: "84dc6508506671255b120d28e348f3ad" diff --git a/test/functional/.gitkeep b/test/functional/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/test/functional/memos_controller_test.rb b/test/functional/memos_controller_test.rb new file mode 100644 index 000000000..76c0e3748 --- /dev/null +++ b/test/functional/memos_controller_test.rb @@ -0,0 +1,11 @@ +require 'test_helper' + +class MemosControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end + def test_memo_create_fail + memo = Memo.create(:subject => nil) + assert true + end +end diff --git a/test/functional/test_controller_test.rb b/test/functional/test_controller_test.rb new file mode 100644 index 000000000..c262ffe53 --- /dev/null +++ b/test/functional/test_controller_test.rb @@ -0,0 +1,13 @@ +require 'test_helper' + +class TestControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end + test "get test index error" do + @request.env["REQUEST_URI"] = "" + get :index + assert_template :index + # assert_template layout: "layouts/base", partial: ["layouts/base_header","_base_header", 'layouts/base_footer', "_base_footer",] + end +end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb new file mode 100644 index 000000000..e51f7600a --- /dev/null +++ b/test/functional/users_controller_test.rb @@ -0,0 +1,31 @@ +require 'test_helper' + +class UsersControllerTest < ActionController::TestCase + def setup + initial_user_controller + end + def teardown + teardown_user_controller + end + + test "test user valid" do + assert @user.valid?, "user valid." + end + + test "get user_courses page" do + get :user_courses, {:id => @user.id} + assert_response :success + end + + private + + def initial_user_controller + @user = users(:person_one) + # @user_extra = user_extensions(:person_one_extra) + end + + def teardown_user_controller + @user = nil + # @user_extra = nil + end +end diff --git a/test/integration/.gitkeep b/test/integration/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb new file mode 100644 index 000000000..3fea27b91 --- /dev/null +++ b/test/performance/browsing_test.rb @@ -0,0 +1,12 @@ +require 'test_helper' +require 'rails/performance_test_help' + +class BrowsingTest < ActionDispatch::PerformanceTest + # Refer to the documentation for all available options + # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory] + # :output => 'tmp/performance', :formats => [:flat] } + + def test_homepage + get '/' + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 000000000..8bf1192ff --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,13 @@ +ENV["RAILS_ENV"] = "test" +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. + # + # Note: You'll currently still have to declare fixtures explicitly in integration tests + # -- they do not yet inherit this setting + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/test/unit/.gitkeep b/test/unit/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/test/unit/helpers/courses_helper_test.rb b/test/unit/helpers/courses_helper_test.rb new file mode 100644 index 000000000..829ae701e --- /dev/null +++ b/test/unit/helpers/courses_helper_test.rb @@ -0,0 +1,12 @@ +require File.expand_path('../../../test_helper', __FILE__) + +class CoursesHelperTest < ActionView::TestCase + include CoursesHelper + # test "test truth" do + # @project = Project.find_by_id 6834 + # teacherNum = teacherCount @project + # studentNum = studentCount @project + # assert_equal 1, teacherNum + # assert_equal 5, studentNum + # end +end diff --git a/test/unit/helpers/memos_helper_test.rb b/test/unit/helpers/memos_helper_test.rb new file mode 100644 index 000000000..44a7038ef --- /dev/null +++ b/test/unit/helpers/memos_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class MemosHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/stores_helper_test.rb b/test/unit/helpers/stores_helper_test.rb new file mode 100644 index 000000000..01b1643a7 --- /dev/null +++ b/test/unit/helpers/stores_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class StoresHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/test_helper_test.rb b/test/unit/helpers/test_helper_test.rb new file mode 100644 index 000000000..158276d03 --- /dev/null +++ b/test/unit/helpers/test_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class TestHelperTest < ActionView::TestCase +end diff --git a/test/unit/memo_test.rb b/test/unit/memo_test.rb new file mode 100644 index 000000000..c77e1ec79 --- /dev/null +++ b/test/unit/memo_test.rb @@ -0,0 +1,16 @@ +require 'test_helper' + +class MemoTest < ActiveSupport::TestCase + test "the truth" do + assert true + end + + def test_the_truth + assert true + end + + test "should not save memo without content" do + memo = Memo.new + assert !memo.save, "assert, save memo without content." + end +end