diff --git a/.gitignore b/.gitignore index 4a01bd5e..52f40859 100644 --- a/.gitignore +++ b/.gitignore @@ -73,7 +73,7 @@ vendor/bundle/ /public/admin /mysql_data /public/repo/ - +/coverage .generators .rakeTasks diff --git a/Gemfile b/Gemfile index d573a4cc..677affd8 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,7 @@ gem 'ransack' group :development, :test do gem 'rspec-rails', '~> 3.8' + gem 'rails-controller-testing' end group :development do @@ -77,6 +78,7 @@ group :test do gem 'capybara', '>= 2.15', '< 4.0' gem 'selenium-webdriver' gem 'chromedriver-helper' + gem 'simplecov', '~>0.12.0', require: false end gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] @@ -101,6 +103,7 @@ gem 'rails-i18n', '~> 5.1' gem 'sidekiq',"5.2.8" gem 'sinatra' gem "sidekiq-cron", "1.2.0" +gem 'whenever' # batch insert gem 'bulk_insert' @@ -131,6 +134,9 @@ gem 'harmonious_dictionary', '~> 0.0.1' gem 'parallel', '~> 1.19', '>= 1.19.1' +# log +gem 'multi_logger' + gem 'letter_avatar' gem 'jwt' diff --git a/LICENSE b/LICENSE index 2b9b385e..04a210b9 100644 --- a/LICENSE +++ b/LICENSE @@ -121,4 +121,4 @@ You may obtain a copy of Mulan PSL v2 at: THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -See the Mulan PSL v2 for more details. \ No newline at end of file +See the Mulan PSL v2 for more details. diff --git a/app/assets/javascripts/log.js b/app/assets/javascripts/log.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/log.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/sponsor_tiers.js b/app/assets/javascripts/sponsor_tiers.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/sponsor_tiers.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/sponsorships.js b/app/assets/javascripts/sponsorships.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/sponsorships.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/wallets.js b/app/assets/javascripts/wallets.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/wallets.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/log.scss b/app/assets/stylesheets/log.scss new file mode 100644 index 00000000..72261a51 --- /dev/null +++ b/app/assets/stylesheets/log.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the log controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 00000000..60451880 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,84 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + + &:visited { + color: #666; + } + + &:hover { + color: #fff; + background-color: #000; + } +} + +th { + padding-bottom: 5px; +} + +td { + padding: 0 5px 7px; +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; + + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; + } + + ul li { + font-size: 12px; + list-style: square; + } +} + +label { + display: block; +} diff --git a/app/assets/stylesheets/sponsor_tiers.scss b/app/assets/stylesheets/sponsor_tiers.scss new file mode 100644 index 00000000..0b4b39a0 --- /dev/null +++ b/app/assets/stylesheets/sponsor_tiers.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the SponsorTiers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sponsorships.scss b/app/assets/stylesheets/sponsorships.scss new file mode 100644 index 00000000..3d9a20ea --- /dev/null +++ b/app/assets/stylesheets/sponsorships.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Sponsorships controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/wallets.scss b/app/assets/stylesheets/wallets.scss new file mode 100644 index 00000000..d4a3c509 --- /dev/null +++ b/app/assets/stylesheets/wallets.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Wallets controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 4a104129..bfa4e1c1 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -4,13 +4,13 @@ class AccountsController < ApplicationController #skip_before_action :check_account, :only => [:logout] - def simple_update + def simple_update simple_update_params.merge!(username: params[:username]&.gsub(/\s+/, "")) simple_update_params.merge!(email: params[:email]&.gsub(/\s+/, "")) simple_update_params.merge!(platform: (params[:platform] || 'forge')&.gsub(/\s+/, "")) Register::RemoteForm.new(simple_update_params).validate! - ActiveRecord::Base.transaction do + ActiveRecord::Base.transaction do result = auto_update(current_user, simple_update_params) if result[:message].blank? render_ok @@ -270,6 +270,7 @@ class AccountsController < ApplicationController set_autologin_cookie(user) UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip) + # user.daily_reward user.update_column(:last_login_on, Time.now) session[:"#{default_yun_session}"] = user.id Rails.logger.info("#########_____session_default_yun_session__________###############{default_yun_session}") @@ -342,11 +343,11 @@ class AccountsController < ApplicationController render_ok end - def login_check + def login_check Register::LoginCheckColumnsForm.new(check_params.merge(user: current_user)).validate! render_ok end - + private # type 事件类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验证手机号是否有效 # 如果有新的继续后面加 @@ -389,7 +390,7 @@ class AccountsController < ApplicationController params.require(:user).permit(:login, :email, :phone) end - def login_params + def login_params params.require(:account).permit(:login, :password) end @@ -404,7 +405,7 @@ class AccountsController < ApplicationController def reset_password_params params.permit(:login, :password, :password_confirmation, :code) end - + def find_user phone_or_mail = strip(reset_password_params[:login]) User.where("phone = :search OR mail = :search", search: phone_or_mail).last @@ -413,7 +414,7 @@ class AccountsController < ApplicationController def remote_register_params params.permit(:username, :email, :password, :platform) end - + def simple_update_params params.permit(:username, :email, :password, :platform) end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7490cb27..9487dcae 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,12 +10,14 @@ class ApplicationController < ActionController::Base include LoggerHelper include LoginHelper include RegisterHelper + include UpdateHelper protect_from_forgery prepend: true, unless: -> { request.format.json? } before_action :check_sign before_action :user_setup #before_action :check_account + after_action :user_trace_log # TODO # check sql query time @@ -25,6 +27,8 @@ class ApplicationController < ActionController::Base # end end + before_action :update_last_login_on + DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) OPENKEY = Rails.application.config_for(:configuration)['sign_key'] || "79e33abd4b6588941ab7622aed1e67e8" @@ -82,7 +86,7 @@ class ApplicationController < ActionController::Base unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/ tip_exception(-2, "请输入正确的手机号或邮箱") end - + user_exist = Owner.exists?(phone: login) || Owner.exists?(mail: login) if user_exist && type.to_i == 1 tip_exception(-2, "该手机号码或邮箱已被注册") @@ -305,7 +309,7 @@ class ApplicationController < ActionController::Base User.current = User.find_by(id: @doorkeeper_token.resource_owner_id) end end - else + else User.current = find_current_user uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) @@ -363,7 +367,19 @@ class ApplicationController < ActionController::Base # RSS key authentication does not start a session User.find_by_rss_key(params[:key]) end - end + end + + def user_trace_log + user = current_user + # print("*********************url:", request.url, "****routes", request.request_method) + Rails.logger.user_trace.info("{id: #{user.id}, login: #{user.login}, url: #{request.url}, method: #{request.method}, params: #{params}, response_code: #{response.code}, time: #{Time.now}}") + end + + def user_trace_update_log(old_value_hash) + user = current_user + str = "{id: #{user.id}, login: #{user.login}, url: #{request.url}, method: #{request.method}, params: #{params.merge(old_value: old_value_hash)}, response_code: #{response.code}, time: #{Time.now}}" + Rails.logger.user_trace.info(str) + end def try_to_autologin if cookies[autologin_cookie_name] @@ -389,12 +405,17 @@ class ApplicationController < ActionController::Base respond_to do |format| format.json end - end + end - ## 输出错误信息 - def error_status(message = nil) - @status = -1 - @message = message + ## 输出错误信息 + def error_status(message = nil) + @status = -1 + @message = message + end + + # 实训等对应的仓库地址 + def repo_ip_url(repo_path) + "#{edu_setting('git_address_ip')}/#{repo_path}" end def repo_url(repo_path) @@ -633,6 +654,23 @@ class ApplicationController < ActionController::Base ss end + def strip_html(text, len=0, endss="...") + ss = "" + if !text.nil? && text.length>0 + ss=text.gsub(/<\/?.*?>/, '').strip + ss = ss.gsub(/ */, '') + ss = ss.gsub(/\r\n/,'') #新增 + ss = ss.gsub(/\n/,'') #新增 + if len > 0 && ss.length > len + ss = ss[0, len] + endss + elsif len > 0 && ss.length <= len + ss = ss + #ss = truncate(ss, :length => len) + end + end + ss + end + # Returns a string that can be used as filename value in Content-Disposition header def filename_for_content_disposition(name) request.env['HTTP_USER_AGENT'] =~ %r{MSIE|Trident|Edge} ? ERB::Util.url_encode(name) : name @@ -644,8 +682,8 @@ class ApplicationController < ActionController::Base # 获取Oauth Client def get_client(site) - client_id = Rails.configuration.Gitlink['client_id'] - client_secret = Rails.configuration.Gitlink['client_secret'] + client_id = Rails.configuration.educoder['client_id'] + client_secret = Rails.configuration.educoder['client_secret'] OAuth2::Client.new(client_id, client_secret, site: site) end @@ -665,7 +703,7 @@ class ApplicationController < ActionController::Base def kaminari_paginate(relation) limit = params[:limit] || params[:per_page] - limit = (limit.to_i.zero? || limit.to_i > 50) ? 50 : limit.to_i + limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i page = params[:page].to_i.zero? ? 1 : params[:page].to_i relation.page(page).per(limit) @@ -750,11 +788,11 @@ class ApplicationController < ActionController::Base # @project = nil if !@project.is_public? # render_forbidden and return else - if @project.present? + if @project.present? logger.info "###########: has project and but can't read project" @project = nil render_forbidden and return - else + else logger.info "###########:project not found" @project = nil render_not_found and return @@ -799,21 +837,54 @@ class ApplicationController < ActionController::Base end private - def object_not_found - uid_logger("Missing template or cant't find record, responding with 404") - render json: {message: "您访问的页面不存在或已被删除", status: 404} - false + def update_last_login_on + if current_user.logged? + current_user.update_column(:last_login_on, Time.now) + end end + def object_not_found + uid_logger("Missing template or cant't find record, responding with 404") + render json: {message: "您访问的页面不存在或已被删除", status: 404} + false + end + def tip_show(exception) uid_logger("Tip show status is #{exception.status}, message is #{exception.message}") render json: exception.tip_json end + def render_parameter_missing + render json: { status: -1, message: '参数缺失' } + end + def set_export_cookies cookies[:fileDownload] = true end + # 149课程的评审用户数据创建(包含创建课堂学生) + def open_class_user + user = User.find_by(login: "OpenClassUser") + unless user + ActiveRecord::Base.transaction do + user_params = {status: 1, login: "OpenClassUser", lastname: "开放课程", + nickname: "开放课程", professional_certification: 1, certification: 1, grade: 0, + password: "12345678", phone: "11122223333", profile_completed: 1} + user = User.create!(user_params) + + UserExtension.create!(user_id: user.id, gender: 0, school_id: 3396, :identity => 1, :student_id => "openclassuser") # 3396 + + subject = Subject.find_by(id: 149) + if subject + subject.courses.each do |course| + CourseMember.create!(course_id: course.id, role: 3, user_id: user.id) if !course.course_members.exists?(user_id: user.id) + end + end + end + end + user + end + # 记录热门搜索关键字 def record_search_keyword keyword = params[:keyword].to_s.strip diff --git a/app/controllers/compare_controller.rb b/app/controllers/compare_controller.rb index afdceac9..732747bc 100644 --- a/app/controllers/compare_controller.rb +++ b/app/controllers/compare_controller.rb @@ -6,10 +6,10 @@ class CompareController < ApplicationController end def show - if params[:type] == "sha" + if params[:type] == "sha" load_compare_params @compare_result ||= gitea_compare(@base, @head) - else + else load_compare_params compare @merge_status, @merge_message = get_merge_message @@ -63,7 +63,7 @@ class CompareController < ApplicationController Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, Addressable::URI.escape(base), Addressable::URI.escape(head), current_user.gitea_token) end - def page_size + def page_size params.fetch(:page, 1).to_i end diff --git a/app/controllers/concerns/login_helper.rb b/app/controllers/concerns/login_helper.rb index c0e8d01c..d2666b08 100644 --- a/app/controllers/concerns/login_helper.rb +++ b/app/controllers/concerns/login_helper.rb @@ -44,6 +44,7 @@ module LoginHelper set_autologin_cookie(user) UserAction.create(action_id: user&.id, action_type: 'Login', user_id: user&.id, ip: request.remote_ip) + # user.daily_reward user.update_column(:last_login_on, Time.now) # 注册完成后有一天的试用申请(先去掉) # UserDayCertification.create(user_id: user.id, status: 1) diff --git a/app/controllers/forks_controller.rb b/app/controllers/forks_controller.rb index c740c8b0..bba098ff 100644 --- a/app/controllers/forks_controller.rb +++ b/app/controllers/forks_controller.rb @@ -3,9 +3,12 @@ class ForksController < ApplicationController before_action :require_profile_completed, only: [:create] before_action :load_project before_action :authenticate_project!, :authenticate_user! + skip_after_action :user_trace_log, only: [:create] def create @new_project = Projects::ForkService.new(current_user, @project, params[:organization]).call + user = current_user + Rails.logger.user_trace.info("{id: #{user.id}, login: #{user.login}, url: #{request.url}, method: #{request.method}, params: #{params.merge(forkee: @new_project.id)}, response_code: #{response.code}, time: #{Time.now}}") end private diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index ddb0facd..881afd13 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -11,6 +11,8 @@ class IssuesController < ApplicationController before_action :set_issue, only: [:edit, :update, :destroy, :show, :copy, :close_issue, :lock_issue] before_action :check_token_enough, :find_atme_receivers, only: [:create, :update] + skip_after_action :user_trace_log, only: [:update] + include ApplicationHelper include TagChosenHelper @@ -218,6 +220,7 @@ class IssuesController < ApplicationController # end # end # end + issue_hash = old_value_to_hash(@issue, params) if @issue.issue_type.to_s == "2" && params[:status_id].to_i == 5 && @issue.author_id != current_user.try(:id) normal_status(-1, "不允许修改为关闭状态") @@ -225,6 +228,9 @@ class IssuesController < ApplicationController issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id) Issues::UpdateForm.new({subject: issue_params[:subject], description: issue_params[:description].blank? ? issue_params[:description] : issue_params[:description].b}).validate! if @issue.update_attributes(issue_params) + + user_trace_update_log(issue_hash) + if @issue&.pull_request.present? SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @issue&.pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) if Site.has_notice_menu? SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @issue&.pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index 6dc1e29c..82ffc02f 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -4,6 +4,7 @@ class JournalsController < ApplicationController before_action :set_issue before_action :check_issue_permission before_action :set_journal, only: [:destroy, :edit, :update] + skip_after_action :user_trace_log, only: [:update] def index @page = params[:page] || 1 @@ -74,9 +75,11 @@ class JournalsController < ApplicationController def update content = params[:content] - if content.present? + if content.present? + old_value = old_value_to_hash(@journal, params) Journals::UpdateForm.new({notes: notes.to_s.strip.blank? ? notes.to_s.strip : notes.to_s.strip.b}).validate! if @journal.update_attribute(:notes, content) + user_trace_update_log(old_value) normal_status(0, "更新成功") else normal_status(-1, "更新失败") diff --git a/app/controllers/log_controller.rb b/app/controllers/log_controller.rb new file mode 100644 index 00000000..ca23bde2 --- /dev/null +++ b/app/controllers/log_controller.rb @@ -0,0 +1,19 @@ +class LogController < ApplicationController + def list + path = "#{Rails.root}/log" + @file_list = [] + Dir.foreach(path) do |file| + @file_list << file + end + @file_list = @file_list.sort + end + + def download + path = "#{Rails.root}/log/#{params[:filename]}" + if params[:filename] && File.exist?(path) && File.file?(path) + send_file(path, filename: params[:filename]) + else + render json: { message: 'no such file!' } + end + end +end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 92eb68f3..8e3fe017 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -6,6 +6,7 @@ class MembersController < ApplicationController before_action :operate! before_action :check_member_exists!, only: %i[create] before_action :check_member_not_exists!, only: %i[remove change_role] + skip_after_action :user_trace_log, only: [:change_role] def create interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user) @@ -42,7 +43,9 @@ class MembersController < ApplicationController end def change_role + old_value = @project.members.where(user_id: params[:user_id])[0].roles.last.name interactor = Projects::ChangeMemberRoleInteractor.call(@project.owner, @project, @user, params[:role]) + user_trace_update_log(old_value) SendTemplateMessageJob.perform_later('ProjectRole', current_user.id, @user.id, @project.id, message_role_name) if Site.has_notice_menu? render_response(interactor) rescue Exception => e diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 2b9bbbe6..ff89cba1 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -6,6 +6,8 @@ class PullRequestsController < ApplicationController before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos, :files, :commits] before_action :load_pull_request, only: [:files, :commits] before_action :find_atme_receivers, only: [:create, :update] + + skip_after_action :user_trace_log, only: [:update] include TagChosenHelper include ApplicationHelper @@ -103,8 +105,13 @@ class PullRequestsController < ApplicationController reviewers = User.where(id: params[:reviewer_ids]) @pull_request.reviewers = reviewers + old_issue_value = old_value_to_hash(@issue, @issue_params) + old_pr_value = old_value_to_hash(@pull_request, @local_params.compact) + old_value = {issue: old_issue_value, pull_request: old_pr_value} + if @issue.update_attributes(@issue_params) if @pull_request.update_attributes(@local_params.compact) + user_trace_update_log(old_value) gitea_pull = Gitea::PullRequest::UpdateService.call(@owner.login, @repository.identifier, @pull_request.gitea_number, @requests_params, current_user.gitea_token) @@ -119,7 +126,7 @@ class PullRequestsController < ApplicationController end else return normal_status(-1, "请输入正确的标记。") - end + end end if params[:status_id].to_i == 5 @issue.issue_times.update_all(end_time: Time.now) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index def2e2c8..91c50768 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -1,6 +1,7 @@ class SettingsController < ApplicationController def show @old_projects_url = nil + @old_projects_url = "https://www.trustie.net/users/#{current_user.try(:login)}/projects" if User.current.logged? get_navbar get_add_menu get_common_menu @@ -12,14 +13,14 @@ class SettingsController < ApplicationController end private - def get_navbar + def get_navbar @navbar = default_laboratory.navbar if User.current.logged? pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "#{Rails.application.config_for(:configuration)['platform_url']}/current_user"), "hidden"=>false} @navbar << pernal_index end end - + def get_add_menu @add = [] Site.add.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site| @@ -86,7 +87,7 @@ class SettingsController < ApplicationController } end end - + def get_top_system_notification @top_system_notification = SystemNotification.is_top.first end diff --git a/app/controllers/sponsor_tiers_controller.rb b/app/controllers/sponsor_tiers_controller.rb new file mode 100644 index 00000000..8aaf1327 --- /dev/null +++ b/app/controllers/sponsor_tiers_controller.rb @@ -0,0 +1,90 @@ +class SponsorTiersController < ApplicationController + before_action :set_sponsor_tier, only: [:show, :edit, :update, :destroy] + before_action :check_sponsor, only: [:show] + before_action :require_login, only: [:create, :update, :destroy] + + # GET /sponsor_tiers + # GET /sponsor_tiers.json + def index + # @sponsor_tiers = SponsorTier.all + user = User.find_by_login(params[:login]) + @sponsor_tiers = user.sponsor_tier + end + + # GET /sponsor_tiers/1 + # GET /sponsor_tiers/1.json + def show + + end + + # POST /sponsor_tiers + # POST /sponsor_tiers.json + def create + # print("------------\n", sponsor_tier_params, "\n------------\n") + @check_sponsorship = nil + @sponsor_tier = SponsorTier.new(sponsor_tier_params) + respond_to do |format| + if @sponsor_tier.user_id == User.current.id && @sponsor_tier.save + format.html { redirect_to @sponsor_tier, notice: 'Sponsor tier was successfully created.' } + format.json { render :show, status: :created, location: @sponsor_tier } + # render json: {status: 1, message: '创建成功' } + else + format.html { render :new } + format.json { render json: @sponsor_tier.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /sponsor_tiers/1 + # PATCH/PUT /sponsor_tiers/1.json + def update + @check_sponsorship = nil + old_value = old_value_to_hash(@sponsor_tier, params) + respond_to do |format| + if User.current.id == @sponsor_tier.user_id && @sponsor_tier.update(sponsor_tier_update_params) + user_trace_update_log(old_value) + format.html { redirect_to @sponsor_tier, notice: 'Sponsor tier was successfully updated.' } + format.json { render :show, status: :ok, location: @sponsor_tier } + # render json: {status: 1, message: '修改成功' } + else + format.html { render :edit } + format.json { render json: @sponsor_tier.errors, status: :unprocessable_entity } + # format.json { render status: :unprocessable_entity } + # render json: {status: -1, message: '修改失败' } + end + end + end + + # DELETE /sponsor_tiers/1 + # DELETE /sponsor_tiers/1.json + def destroy + if User.current.id == @sponsor_tier.user_id + @sponsor_tier.destroy + respond_to do |format| + format.html { redirect_to sponsor_tiers_url, notice: 'Sponsor tier was successfully destroyed.' } + format.json { head :no_content } + end + else + format.json { render json: @sponsor_tier.errors, status: :unprocessable_entity } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def check_sponsor + @check_sponsorship = Sponsorship.where("sponsor_id=? AND developer_id=?", current_user.id, @sponsor_tier.user.id) + end + + def set_sponsor_tier + @sponsor_tier = SponsorTier.find(params[:id]) + end + + def sponsor_tier_update_params + params.require(:sponsor_tier).permit(:tier, :description) + end + + # Only allow a list of trusted parameters through. + def sponsor_tier_params + params.require(:sponsor_tier).permit(:tier, :user_id, :description) + end +end diff --git a/app/controllers/sponsorships_controller.rb b/app/controllers/sponsorships_controller.rb new file mode 100644 index 00000000..4e18e851 --- /dev/null +++ b/app/controllers/sponsorships_controller.rb @@ -0,0 +1,212 @@ +class SponsorshipsController < ApplicationController + before_action :set_sponsorship, only: [:show, :edit, :update, :destroy] + # before_action :require_login, except: [:index, :stopped, :sponsored, :sponsoring, :stopped_sponsored, :stopped_sponsoring] + before_action :require_login, only: [:create, :edit, :update, :destroy] + skip_after_action :user_trace_log, only: [:update] + + # GET /sponsorships + # GET /sponsorships.json + def index + @sponsorships = Sponsorship.all + end + + def stopped + @stopped_sponsorships = StoppedSponsorship.all + end + + def sponsored + if User.current.id == Integer(params[:id]) + @sponsorships = Sponsorship.where('developer_id=?', params[:id]) + else + @sponsorships = Sponsorship.where('developer_id=? AND visible=1', params[:id]) + end + sort = params[:sort_by] || 'created_at' + sort_direction = params[:sort_direction] || 'desc' + @sponsorships = @sponsorships.reorder("#{sort} #{sort_direction}") + @total = @sponsorships.length + @sponsorships = kaminari_paginate(@sponsorships) + end + + def sponsoring + if User.current.id == Integer(params[:id]) + @sponsorships = Sponsorship.where('sponsor_id=?', params[:id]) + else + @sponsorships = Sponsorship.where('sponsor_id=? AND visible=1', params[:id]) + end + sort = params[:sort_by] || 'created_at' + sort_direction = params[:sort_direction] || 'desc' + @sponsorships = @sponsorships.reorder("#{sort} #{sort_direction}") + @total = @sponsorships.length + @sponsorships = kaminari_paginate(@sponsorships) + end + + def stopped_sponsored + if User.current.id == Integer(params[:id]) + @stopped_sponsorships = StoppedSponsorship.where('developer_id=?', params[:id]) + else + @stopped_sponsorships = StoppedSponsorship.where('developer_id=? AND visible=1', params[:id]) + end + sort = params[:sort_by] || 'created_at' + sort_direction = params[:sort_direction] || 'desc' + @stopped_sponsorships = @stopped_sponsorships.reorder("#{sort} #{sort_direction}") + @total = @stopped_sponsorships.length + @stopped_sponsorships = kaminari_paginate(@stopped_sponsorships) + end + + def stopped_sponsoring + if User.current.id == Integer(params[:id]) + @stopped_sponsorships = StoppedSponsorship.where('sponsor_id=?', params[:id]) + else + @stopped_sponsorships = StoppedSponsorship.where('sponsor_id=? AND visible=1', params[:id]) + end + sort = params[:sort_by] || 'created_at' + sort_direction = params[:sort_direction] || 'desc' + @stopped_sponsorships = @stopped_sponsorships.reorder("#{sort} #{sort_direction}") + @total = @stopped_sponsorships.length + @stopped_sponsorships = kaminari_paginate(@stopped_sponsorships) + end + + # GET /sponsorships/1 + # GET /sponsorships/1.json + def show; end + + # POST /sponsorships + # POST /sponsorships.json + def create + sponsor_id = User.current.id + check_sponsorship = Sponsorship.where('sponsor_id=? AND developer_id=?', sponsor_id, params[:developer_id]) + + @sponsorship = Sponsorship.new(sponsorship_params.merge({sponsor_id: sponsor_id})) + + unless check_sponsorship.length.zero? + return render json: {status: -1, message: '您已经赞助了TA' } + end + if @sponsorship.pay && @sponsorship.save + if params[:single] && @sponsorship.stop + return render json: { status: 1, message: '赞助成功' } + elsif !params[:single] + User.current.update(sponsor_num: User.current.sponsor_num+1) + @sponsorship.developer.update(sponsored_num: @sponsorship.developer.sponsored_num + 1) + return render json: { status: 1, message: '赞助成功' } + else + return render json: { status: -1, message: '赞助失败' } + end + else + return render json: { status: -1, message: '赞助失败' } + end + # return render_result message: '赞助成功' if @sponsorship.save + # respond_to do |format| + # if check_sponsorship.length.zero? && @sponsorship.save + # format.html { redirect_to @sponsorship, notice: 'Sponsorship was successfully created.' } + # format.json { render :show, status: :created, location: @sponsorship } + # # render_result status=0, message="赞助成功" + # else + # format.html { render :new } + # format.json { render json: @sponsorship.errors, status: :unprocessable_entity } + # end + # end + end + + # PATCH/PUT /sponsorships/1 + # PATCH/PUT /sponsorships/1.json + def update + # respond_to do |format| + # if @sponsorship.update(sponsorship_params) + # format.html { redirect_to @sponsorship, notice: 'Sponsorship was successfully updated.' } + # format.json { render :show, status: :ok, location: @sponsorship } + # else + # format.html { render :edit } + # format.json { render json: @sponsorship.errors, status: :unprocessable_entity } + # end + # end + + if @sponsorship.sponsor.id != current_user.id + return render json: {status: 401, message: '没有权限' } + end + old_value = old_value_to_hash(@sponsorship, params) + + if @sponsorship.update(sponsorship_params) + user_trace_update_log(old_value) + render json: {status: 1, message: '修改成功' } + else + render json: {status: -1, message: '修改失败' } + end + end + + # DELETE /sponsorships/1 + # DELETE /sponsorships/1.json + def destroy + # @sponsorship.destroy + # respond_to do |format| + # format.html { redirect_to sponsorships_url, notice: 'Sponsorship was successfully destroyed.' } + # format.json { head :no_content } + # end + developer = @sponsorship.developer + sponsor = @sponsorship.sponsor + if (User.current.id == developer.id || User.current.id == sponsor.id) && developer.update(sponsored_num: developer.sponsored_num-1) && sponsor.update(sponsor_num: sponsor.sponsor_num-1) && @sponsorship.stop + render json: {status: 1, message: '终止成功'} + else + render json: {status: -1, message: '失败'} + end + end + + def community_data + @sponsorships = Sponsorship.all + t1 = Time.now + t2 = Time.new(t1.year, t1.month, t1.day - 6) + @stopped_sponsorships = StoppedSponsorship.where('created_at >= ?', t2) + @community_data_array = to_array(@sponsorships, @stopped_sponsorships) + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_sponsorship + @sponsorship = Sponsorship.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def sponsorship_params + params.require(:sponsorship).permit(:amount, :visible, :sponsor_id, :developer_id, :single, :page, :limit, :sort_by, :search) + end + + def to_array(sponsorships, stopped_sponsorships) + t1 = Time.now + start_time = Time.new(t1.year, t1.month, t1.day - 6) + + sponsor = Array.new(7) + sponsored = Array.new(7) + date = Array.new(7) + # date[0] = Time.new(start_time.year, start_time.month, start_time.day) + index = 0 + + (0..6).each do |i| + # 更新日期,date[i]表示第i天0点 + date[i] = Time.new(start_time.year, start_time.month, start_time.day + i) + end_time = Time.new(start_time.year, start_time.month, start_time.day + i+1) + + sponsor_set = Set.new + sponsored_set = Set.new + + # 所有创建时间早于今天23:59的sponsorship + today_sponsor = sponsorships.where('created_at < ?', end_time) + # 所有结束时间晚于今天0:00的stopped_sponsorship + today_stopped_sponsor = stopped_sponsorships.where('created_at <= ?', date[i]) + today_sponsor.each do |s| + sponsor_set.add s.sponsor_id + sponsored_set.add s.developer_id + end + + today_stopped_sponsor.each do |s| + sponsor_set.add s.sponsor_id + sponsored_set.add s.developer_id + end + + sponsor[i] = sponsor_set.size + sponsored[i] = sponsored_set.size + + end + + Array[sponsor, sponsored, date] + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 33fd93f8..acdf4431 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -94,11 +94,11 @@ class UsersController < ApplicationController end end - def update_image - return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) + def update_image + return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id) - Util.write_file(@image, avatar_path(@user)) + Util.write_file(@image, avatar_path(@user)) return render_ok({message: '头像修改成功'}) rescue Exception => e uid_logger_error(e.message) @@ -141,6 +141,10 @@ class UsersController < ApplicationController end # TODO 等消息上线再打开注释 #@tidding_count = unviewed_tiddings(current_user) if current_user.present? + # + if(@user.logged?) + @user.daily_reward + end rescue Exception => e uid_logger_error(e.message) missing_template @@ -302,6 +306,21 @@ class UsersController < ApplicationController render_ok end + def update_sponsor_description + @user = User.find params[:id] + if @user.id == User.current.id + # @user.update(description: params[:description]) + @user.sponsor_description = params[:sponsor_description] + if @user.save! + render_ok + else + render_error + end + else + render_error + end + end + def sync_user_info user = User.find_by_login params[:login] return render_forbidden unless user === current_user @@ -322,7 +341,7 @@ class UsersController < ApplicationController end end - def email_search + def email_search return render_error('请输入email') if params[:email].blank? @user = User.find_by(mail: params[:email]) end @@ -339,7 +358,7 @@ class UsersController < ApplicationController :occupation, :technical_title, :school_id, :department_id, :province, :city, :custom_department, :identity, :student_id, :description, - :show_super_description, :super_description, + :show_super_description, :super_description,:sponsor_description, :show_email, :show_location, :show_department] ) end diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index dd59098f..4dbcd69b 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -4,6 +4,7 @@ class VersionReleasesController < ApplicationController before_action :require_login, except: [:index, :show] before_action :check_release_authorize, except: [:index, :show] before_action :find_version , only: [:show, :edit, :update, :destroy] + skip_after_action :user_trace_log, only: [:update] def index @version_releases = kaminari_paginate(@repository.version_releases.order(created_at: :desc)) @@ -22,7 +23,7 @@ class VersionReleasesController < ApplicationController end end - def show + def show # @release = Gitea::Versions::GetService.call(current_user.gitea_token, @user&.login, @repository&.identifier, @version&.version_gid) end @@ -83,14 +84,14 @@ class VersionReleasesController < ApplicationController ActiveRecord::Base.transaction do begin version_params = releases_params - + old_value = old_value_to_hash(@version, version_params) if @version.update_attributes!(version_params) create_attachments(params[:attachment_ids], @version) if params[:attachment_ids].present? git_version_release = Gitea::Versions::UpdateService.new(current_user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call unless git_version_release raise Error, "更新失败" end - + user_trace_update_log(old_value) normal_status(0, "更新成功") else normal_status(-1, "更新失败") diff --git a/app/controllers/wallets_controller.rb b/app/controllers/wallets_controller.rb new file mode 100644 index 00000000..7add945c --- /dev/null +++ b/app/controllers/wallets_controller.rb @@ -0,0 +1,113 @@ +class WalletsController < ApplicationController + before_action :require_login, except: :community_data + + def balance + user = User.find_by_id(params[:id]) + @wallet = user.get_wallet + end + + def coin_changes + user = User.find_by_id(params[:id]) + @wallet = user.get_wallet + if params[:category] == 'all' + scope = CoinChange.where('to_wallet_id = ? OR from_wallet_id = ?', @wallet.id, @wallet.id) + elsif params[:category] == 'income' + # @coin_changes = CoinChange.where('to_wallet_id = ?', @wallet.id).limit(100) + scope = @wallet.income + elsif params[:category] == 'outcome' + scope = @wallet.outcome + end + + sort = params[:sort_by] || "created_at" + sort_direction = params[:sort_direction] || "desc" + scope = scope.reorder("#{sort} #{sort_direction}") unless scope.nil? + + @total = 0 + @total = scope.length unless scope.nil? + @coin_changes = kaminari_paginate(scope) unless scope.nil? + end + + def balance_chart + user = User.find_by_id(params[:id]) + @wallet = user.get_wallet + scope = CoinChange.where('to_wallet_id = ? OR from_wallet_id = ?', @wallet.id, @wallet.id) + t1 = Time.now + t2 = Time.new(t1.year, t1.month, t1.day - 6) + @balance_chart_data = scope.where('created_at > ? AND created_at < ?', t2, t1) + @balance_chart_array = to_array(@balance_chart_data, @wallet.id) + end + + def community_data + t1 = Time.now + t2 = Time.new(t1.year, t1.month, t1.day - 6) + coin_changes = CoinChange.where('created_at >= ?', t2) + @community_data_array = community_data_to_array(coin_changes) + end + + private + def to_array(data, id) + t1 = Time.now + start_time = Time.new(t1.year, t1.month, t1.day - 6) + end_time = Time.new(start_time.year, start_time.month, start_time.day + 1) + + income = Array.new(7, 0) # 收入、支出 + outcome = Array.new(7, 0) + date = Array.new(7) + date[0] = Time.new(start_time.year, start_time.month, start_time.day) + index = 0 + + data.each do |i| + # 更新日期 + until (i.created_at >= start_time) && (i.created_at < end_time) + index += 1 + start_time = end_time + end_time = Time.new(start_time.year, start_time.month, start_time.day + 1) + date[index] = Time.new(start_time.year, start_time.month, start_time.day) + end + + if i.from_wallet_id == id + outcome[index] += i.amount + else + next if params[:sponsor] == true && i.from_wallet_id.nil? + income[index] += i.amount + end + + end + + until end_time >= Time.now + index += 1 + start_time = end_time + end_time = Time.new(start_time.year, start_time.month, start_time.day + 1) + date[index] = Time.new(start_time.year, start_time.month, start_time.day) + end + + Array[income, outcome, date] + end + + def community_data_to_array(coin_changes) + t1 = Time.now + start_time = Time.new(t1.year, t1.month, t1.day - 6) + + nums = Array.new(7, 0) + date = Array.new(7) + end_time = Array.new(7) + # date[0] = Time.new(start_time.year, start_time.month, start_time.day) + index = 0 + + (0..6).each do |i| + # 更新日期,date[i]表示第i天0点 + date[i] = Time.new(start_time.year, start_time.month, start_time.day + i) + end_time[i] = Time.new(start_time.year, start_time.month, start_time.day + i+1) + end + + coin_changes.each do |cc| + (0..6).each do |i| + if !cc.from_wallet_id.nil? && cc.created_at>=date[i] && cc.created_at= t + count += 1 + end + end + Statistic.create(dau: count) + end +end diff --git a/app/models/stopped_sponsorship.rb b/app/models/stopped_sponsorship.rb new file mode 100644 index 00000000..03024e8c --- /dev/null +++ b/app/models/stopped_sponsorship.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: stopped_sponsorships +# +# id :integer not null, primary key +# amount :integer +# sponsor_id :integer +# developer_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# start_time :datetime +# visible :integer +# accumulate :integer default("0") +# + +class StoppedSponsorship < ApplicationRecord + belongs_to :sponsor, class_name: 'User' + belongs_to :developer, class_name: 'User' + validates :amount, presence: true +end diff --git a/app/models/token.rb b/app/models/token.rb index 746af653..fac516eb 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,18 +1,19 @@ -# == Schema Information -# -# Table name: tokens -# -# id :integer not null, primary key -# user_id :integer default("0"), not null -# action :string(30) default(""), not null -# value :string(40) default(""), not null -# created_on :datetime not null -# -# Indexes -# -# index_tokens_on_user_id (user_id) -# tokens_value (value) UNIQUE -# +# == Schema Information +# +# Table name: tokens +# +# id :integer not null, primary key +# user_id :integer default("0"), not null +# action :string(30) default(""), not null +# value :string(40) default(""), not null +# created_on :datetime not null +# +# Indexes +# +# index_tokens_on_user_id (user_id) +# tokens_value (value) UNIQUE +# + # # This program is free software; you can redistribute it and/or diff --git a/app/models/user.rb b/app/models/user.rb index df35f3a2..b70efdb5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -39,15 +39,18 @@ # business :boolean default("0") # profile_completed :boolean default("0") # laboratory_id :integer -# is_shixun_marker :boolean default("0") -# admin_visitable :boolean default("0") -# collaborator :boolean default("0") +# platform :string(255) default("0") +# gitea_token :string(255) # gitea_uid :integer +# is_shixun_marker :boolean default("0") # is_sync_pwd :boolean default("1") # watchers_count :integer default("0") +# sponsor_certification :integer default("0") +# sponsor_num :integer default("0") +# sponsored_num :integer default("0") +# sponsor_description :text(65535) # devops_step :integer default("0") -# gitea_token :string(255) -# platform :string(255) +# award_time :datetime # # Indexes # @@ -55,9 +58,8 @@ # index_users_on_homepage_engineer (homepage_engineer) # index_users_on_homepage_teacher (homepage_teacher) # index_users_on_laboratory_id (laboratory_id) -# index_users_on_login (login) UNIQUE -# index_users_on_mail (mail) UNIQUE -# index_users_on_phone (phone) UNIQUE +# index_users_on_login (login) +# index_users_on_mail (mail) # index_users_on_type (type) # @@ -161,6 +163,18 @@ class User < Owner has_many :project_trends, dependent: :destroy has_many :oauths , dependent: :destroy + # sponsor + has_many :as_sponsors, class_name: 'Sponsorship', foreign_key: 'sponsor_id', dependent: :destroy + has_many :as_sponsored, class_name: 'Sponsorship', foreign_key: 'developer_id', dependent: :destroy + has_many :stopped_sponsors, class_name: 'StoppedSponsorship', foreign_key: 'sponsor_id', dependent: :destroy + has_many :stopped_sponsored, class_name: 'StoppedSponsorship', foreign_key: 'developer_id', dependent: :destroy + has_many :sponsor_tier, dependent: :destroy + has_one :wallet, dependent: :destroy + has_many :waitlist, class_name: 'Waitlist', foreign_key: 'reviewer_id' + has_many :passed_waitlist, class_name: 'PassedWaitlist', foreign_key: 'reviewer_id' #as reviewer + has_one :application, class_name: 'Waitlist', foreign_key: 'applicant_id' + has_one :passed_application, class_name: 'PassedWaitlist', foreign_key: 'applicant_id' + has_many :organization_users, dependent: :destroy has_many :organizations, through: :organization_users has_many :pinned_projects, dependent: :destroy @@ -646,6 +660,7 @@ class User < Owner # Returns the user who matches the given autologin +key+ or nil def self.try_to_autologin(key) user = Token.find_active_user('autologin', key) + # user.daily_reward if user user.update(last_login_on: Time.now) if user user end @@ -817,6 +832,36 @@ class User < Owner laboratory_id.present? && laboratory_id != 1 end + def get_wallet + if wallet.nil? + Wallet.transaction(isolation: :serializable) do + if wallet.nil? + create_wallet(balance: 100) + reason = "系统初始赠送" + CoinChange.create(amount: 100, reason: reason, to_wallet_id: wallet.id) + end + end + end + wallet + end + + def daily_reward + if !Rails.application.config_for(:configuration)["sponsor"] + return + end + t1 = Time.now + t2 = Time.new(t1.year, t1.month, t1.day) + + if(award_time.nil? or t2 > award_time) + self.update_column(:award_time, Time.now) + amount = 2 + user_wallet = get_wallet + user_wallet.receive(amount) + reason = "每日登录奖励" + CoinChange.create(amount: amount, reason: reason, to_wallet_id: user_wallet.id) + end + end + def profile_is_completed? self.nickname.present? && self.mail.present? end diff --git a/app/models/user_action.rb b/app/models/user_action.rb index 17935969..3ad8010e 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -12,9 +12,7 @@ # # Indexes # -# index_user_actions_on_ip (ip) -# index_user_actions_on_user_id (user_id) -# index_user_actions_on_user_id_and_action_type (user_id,action_type) +# index_user_actions_on_ip (ip) # class UserAction < ApplicationRecord diff --git a/app/models/user_agent.rb b/app/models/user_agent.rb index ba519d6f..49d7b35a 100644 --- a/app/models/user_agent.rb +++ b/app/models/user_agent.rb @@ -10,13 +10,10 @@ # updated_at :datetime not null # register_status :integer default("0") # action_status :integer default("0") -# is_delete :boolean default("0") -# user_id :integer # # Indexes # -# index_user_agents_on_ip (ip) -# index_user_agents_on_user_id (user_id) +# index_user_agents_on_ip (ip) UNIQUE # class UserAgent < ApplicationRecord diff --git a/app/models/waitlist.rb b/app/models/waitlist.rb new file mode 100644 index 00000000..252b1792 --- /dev/null +++ b/app/models/waitlist.rb @@ -0,0 +1,16 @@ +# == Schema Information +# +# Table name: waitlists +# +# id :integer not null, primary key +# applicant_id :string(255) +# integer :string(255) +# reviewer_id :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# + +class Waitlist < ApplicationRecord + belongs_to :applicant, class_name: 'User' + belongs_to :reviewer, class_name: 'User', optional: true +end diff --git a/app/models/wallet.rb b/app/models/wallet.rb new file mode 100644 index 00000000..d0f198bd --- /dev/null +++ b/app/models/wallet.rb @@ -0,0 +1,42 @@ +# == Schema Information +# +# Table name: wallets +# +# id :integer not null, primary key +# balance :integer +# user_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# + +class Wallet < ApplicationRecord + belongs_to :user + has_many :outcome, class_name: 'CoinChange', foreign_key: 'from_wallet_id', dependent: :destroy + has_many :income, class_name: 'CoinChange', foreign_key: 'to_wallet_id', dependent: :destroy + validates :balance, presence: true + @@wallet_lock = Mutex.new + + def receive(amount) + with_lock do + self.balance += amount + save! + end + end + + def pay(amount) + with_lock do + if self.balance < amount + reload + return false + else + self.balance -= amount + save! + end + end + true + end + + def self.wallet_lock + @@wallet_lock + end +end diff --git a/app/views/log/list.json.jbuilder b/app/views/log/list.json.jbuilder new file mode 100644 index 00000000..903c5e4f --- /dev/null +++ b/app/views/log/list.json.jbuilder @@ -0,0 +1 @@ +json.array! @file_list \ No newline at end of file diff --git a/app/views/sponsor_tiers/_form.html.erb b/app/views/sponsor_tiers/_form.html.erb new file mode 100644 index 00000000..1857620d --- /dev/null +++ b/app/views/sponsor_tiers/_form.html.erb @@ -0,0 +1,13 @@ + +<%= simple_form_for(@sponsor_tier) do |f| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + +
+ <%= f.input :tier %> +
+ +
+ <%= f.button :submit %> +
+<% end %> diff --git a/app/views/sponsor_tiers/_sponsor_tier.json.jbuilder b/app/views/sponsor_tiers/_sponsor_tier.json.jbuilder new file mode 100644 index 00000000..e06f7ab9 --- /dev/null +++ b/app/views/sponsor_tiers/_sponsor_tier.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! sponsor_tier, :id, :tier, :description, :created_at, :updated_at +json.url sponsor_tier_url(sponsor_tier, format: :json) diff --git a/app/views/sponsor_tiers/edit.html.erb b/app/views/sponsor_tiers/edit.html.erb new file mode 100644 index 00000000..5800149c --- /dev/null +++ b/app/views/sponsor_tiers/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Sponsor Tier

+ +<%= render 'form', sponsor_tier: @sponsor_tier %> + +<%= link_to 'Show', @sponsor_tier %> | +<%= link_to 'Back', sponsor_tiers_path %> diff --git a/app/views/sponsor_tiers/index.json.jbuilder b/app/views/sponsor_tiers/index.json.jbuilder new file mode 100644 index 00000000..6a607957 --- /dev/null +++ b/app/views/sponsor_tiers/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @sponsor_tiers, partial: "sponsor_tiers/sponsor_tier", as: :sponsor_tier diff --git a/app/views/sponsor_tiers/new.html.erb b/app/views/sponsor_tiers/new.html.erb new file mode 100644 index 00000000..928ca743 --- /dev/null +++ b/app/views/sponsor_tiers/new.html.erb @@ -0,0 +1,5 @@ +

New Sponsor Tier

+ +<%= render 'form', sponsor_tier: @sponsor_tier %> + +<%= link_to 'Back', sponsor_tiers_path %> diff --git a/app/views/sponsor_tiers/show.html.erb b/app/views/sponsor_tiers/show.html.erb new file mode 100644 index 00000000..ae7a4c1d --- /dev/null +++ b/app/views/sponsor_tiers/show.html.erb @@ -0,0 +1,9 @@ +

<%= notice %>

+ +

+ Tier: + <%= @sponsor_tier.tier %> +

+ +<%= link_to 'Edit', edit_sponsor_tier_path(@sponsor_tier) %> | +<%= link_to 'Back', sponsor_tiers_path %> diff --git a/app/views/sponsor_tiers/show.json.jbuilder b/app/views/sponsor_tiers/show.json.jbuilder new file mode 100644 index 00000000..9f929c04 --- /dev/null +++ b/app/views/sponsor_tiers/show.json.jbuilder @@ -0,0 +1,9 @@ +json.tier do + json.partial! "sponsor_tiers/sponsor_tier", sponsor_tier: @sponsor_tier +end +if @check_sponsorship.nil? || @check_sponsorship.length.zero? + json.is_sponsoring false +else + json.is_sponsoring true + json.sponsorship_id @check_sponsorship[0].id +end diff --git a/app/views/sponsorships/_form.html.erb b/app/views/sponsorships/_form.html.erb new file mode 100644 index 00000000..aba15064 --- /dev/null +++ b/app/views/sponsorships/_form.html.erb @@ -0,0 +1,16 @@ + +<%= simple_form_for(@sponsorship) do |f| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + +
+ <%= f.input :amount %> + <%= f.input :visible %> + <%= f.input :sponsor_id %> + <%= f.input :developer_id %> +
+ +
+ <%= f.button :submit %> +
+<% end %> diff --git a/app/views/sponsorships/_sponsorship.json.jbuilder b/app/views/sponsorships/_sponsorship.json.jbuilder new file mode 100644 index 00000000..5bb1b4e6 --- /dev/null +++ b/app/views/sponsorships/_sponsorship.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! sponsorship, :id, :amount, :visible, :sponsor_id, :developer_id, :created_at, :updated_at, :accumulate +json.url sponsorship_url(sponsorship, format: :json) diff --git a/app/views/sponsorships/community_data.json.jbuilder b/app/views/sponsorships/community_data.json.jbuilder new file mode 100644 index 00000000..f1a00d26 --- /dev/null +++ b/app/views/sponsorships/community_data.json.jbuilder @@ -0,0 +1,12 @@ +json.sponsor do + json.array! (0..6).each do |i| + json.y @community_data_array[0][i] + json.x @community_data_array[2][i].to_date + end +end +json.sponsored do + json.array! (0..6).each do |i| + json.y @community_data_array[1][i] + json.x @community_data_array[2][i].to_date + end +end \ No newline at end of file diff --git a/app/views/sponsorships/edit.html.erb b/app/views/sponsorships/edit.html.erb new file mode 100644 index 00000000..45d623bb --- /dev/null +++ b/app/views/sponsorships/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Sponsorship

+ +<%= render 'form', sponsorship: @sponsorship %> + +<%= link_to 'Show', @sponsorship %> | +<%= link_to 'Back', sponsorships_path %> diff --git a/app/views/sponsorships/index.html.erb b/app/views/sponsorships/index.html.erb new file mode 100644 index 00000000..d539f213 --- /dev/null +++ b/app/views/sponsorships/index.html.erb @@ -0,0 +1,33 @@ +

<%= notice %>

+ +

Sponsorships

+ + + + + + + + + + + + + + <% @sponsorships.each do |sponsorship| %> + + + + + + + + + + <% end %> + +
AmountVisibleSponsorDeveloper
<%= sponsorship.amount %><%= sponsorship.visible %><%= sponsorship.sponsor_id %><%= sponsorship.developer_id %><%= link_to 'Show', sponsorship %><%= link_to 'Edit', edit_sponsorship_path(sponsorship) %><%= link_to 'Destroy', sponsorship, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Sponsorship', new_sponsorship_path %> diff --git a/app/views/sponsorships/index.json.jbuilder b/app/views/sponsorships/index.json.jbuilder new file mode 100644 index 00000000..d02d0390 --- /dev/null +++ b/app/views/sponsorships/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @sponsorships, partial: "sponsorships/sponsorship", as: :sponsorship diff --git a/app/views/sponsorships/new.html.erb b/app/views/sponsorships/new.html.erb new file mode 100644 index 00000000..914dc917 --- /dev/null +++ b/app/views/sponsorships/new.html.erb @@ -0,0 +1,5 @@ +

New Sponsorship

+ +<%= render 'form', sponsorship: @sponsorship %> + +<%= link_to 'Back', sponsorships_path %> diff --git a/app/views/sponsorships/show.html.erb b/app/views/sponsorships/show.html.erb new file mode 100644 index 00000000..d9ab06ff --- /dev/null +++ b/app/views/sponsorships/show.html.erb @@ -0,0 +1,24 @@ +

<%= notice %>

+ +

+ Amount: + <%= @sponsorship.amount %> +

+ +

+ Visible: + <%= @sponsorship.visible %> +

+ +

+ Sponsor: + <%= @sponsorship.sponsor_id %> +

+ +

+ Developer: + <%= @sponsorship.developer_id %> +

+ +<%= link_to 'Edit', edit_sponsorship_path(@sponsorship) %> | +<%= link_to 'Back', sponsorships_path %> diff --git a/app/views/sponsorships/show.json.jbuilder b/app/views/sponsorships/show.json.jbuilder new file mode 100644 index 00000000..87ded287 --- /dev/null +++ b/app/views/sponsorships/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "sponsorships/sponsorship", sponsorship: @sponsorship diff --git a/app/views/sponsorships/sponsored.json.jbuilder b/app/views/sponsorships/sponsored.json.jbuilder new file mode 100644 index 00000000..ceac4b23 --- /dev/null +++ b/app/views/sponsorships/sponsored.json.jbuilder @@ -0,0 +1,21 @@ +json.count @total +json.sponsorships do + json.array! @sponsorships do |sponsorship| + json.id sponsorship.id + json.start_time sponsorship.created_at.to_date + # json.stop_time '-' + if sponsorship.visible.zero? + json.visible false + else + json.visible true + end + json.amount sponsorship.amount + sponsor = sponsorship.sponsor + json.image_url url_to_avatar(sponsor) + json.username sponsor.full_name + json.user_id sponsor.id + json.login sponsor.login + json.accumulate sponsorship.accumulate + json.sponsor_id sponsorship.sponsor.id + end +end diff --git a/app/views/sponsorships/sponsoring.json.jbuilder b/app/views/sponsorships/sponsoring.json.jbuilder new file mode 100644 index 00000000..39a4027a --- /dev/null +++ b/app/views/sponsorships/sponsoring.json.jbuilder @@ -0,0 +1,21 @@ +json.count @total +json.sponsorships do + json.array! @sponsorships do |sponsorship| + json.id sponsorship.id + json.start_time sponsorship.created_at.to_date + # json.stop_time '-' + if sponsorship.visible.zero? + json.visible false + else + json.visible true + end + json.amount sponsorship.amount + sponsor = sponsorship.developer + json.image_url url_to_avatar(sponsor) + json.username sponsor.full_name + json.user_id sponsor.id + json.login sponsor.login + json.accumulate sponsorship.accumulate + json.sponsor_id sponsorship.sponsor.id + end +end diff --git a/app/views/sponsorships/stopped.json.jbuilder b/app/views/sponsorships/stopped.json.jbuilder new file mode 100644 index 00000000..a6d0cca4 --- /dev/null +++ b/app/views/sponsorships/stopped.json.jbuilder @@ -0,0 +1,11 @@ +json.array! @stopped_sponsorships do |sponsorship| + json.id sponsorship.id + json.amount sponsorship.amount + json.visible sponsorship.visible + json.sponsor_id sponsorship.sponsor_id + json.developer_id sponsorship.developer_id + json.start_time sponsorship.start_time + json.created_at sponsorship.created_at + json.updated_at sponsorship.updated_at + json.accumulate sponsorship.accumulate +end \ No newline at end of file diff --git a/app/views/sponsorships/stopped_sponsored.json.jbuilder b/app/views/sponsorships/stopped_sponsored.json.jbuilder new file mode 100644 index 00000000..cd06cb6c --- /dev/null +++ b/app/views/sponsorships/stopped_sponsored.json.jbuilder @@ -0,0 +1,21 @@ +json.count @total +json.sponsorships do + json.array! @stopped_sponsorships do |sponsorship| + json.id sponsorship.id + json.start_time sponsorship.start_time.to_date + json.stop_time sponsorship.created_at.to_date + if sponsorship.visible.zero? + json.visible false + else + json.visible true + end + json.amount sponsorship.amount + sponsor = sponsorship.sponsor + json.image_url url_to_avatar(sponsor) + json.username sponsor.full_name + json.user_id sponsor.id + json.login sponsor.login + json.accumulate sponsorship.accumulate + json.sponsor_id sponsorship.sponsor.id + end +end \ No newline at end of file diff --git a/app/views/sponsorships/stopped_sponsoring.json.jbuilder b/app/views/sponsorships/stopped_sponsoring.json.jbuilder new file mode 100644 index 00000000..fb3b0f9c --- /dev/null +++ b/app/views/sponsorships/stopped_sponsoring.json.jbuilder @@ -0,0 +1,21 @@ +json.count @total +json.sponsorships do + json.array! @stopped_sponsorships do |sponsorship| + json.id sponsorship.id + json.start_time sponsorship.start_time.to_date + json.stop_time sponsorship.created_at.to_date + if sponsorship.visible.zero? + json.visible false + else + json.visible true + end + json.amount sponsorship.amount + sponsor = sponsorship.developer + json.image_url url_to_avatar(sponsor) + json.username sponsor.full_name + json.user_id sponsor.id + json.login sponsor.login + json.accumulate sponsorship.accumulate + json.sponsor_id sponsorship.sponsor.id + end +end \ No newline at end of file diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 68bfa658..1820a763 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -15,6 +15,7 @@ json.phone @user.phone # json.email @user.mail json.profile_completed @user.profile_is_completed? json.professional_certification @user.professional_certification +json.sponsor_description @user.sponsor_description json.devops_step @user.devops_step json.ci_certification @user.ci_certification? json.email @user.mail diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder index dfeb45cf..2050a62f 100644 --- a/app/views/users/show.json.jbuilder +++ b/app/views/users/show.json.jbuilder @@ -15,4 +15,5 @@ json.city @user.show_location ? @user.city : nil json.custom_department @user.show_department ? @user.custom_department : nil json.super_description @user.show_super_description ? @user.super_description : nil json.show_super_description @user.show_super_description -json.description @user.description \ No newline at end of file +json.description @user.description +json.sponsor_description @user.sponsor_description \ No newline at end of file diff --git a/app/views/wallets/balance.html.erb b/app/views/wallets/balance.html.erb new file mode 100644 index 00000000..ed2b106d --- /dev/null +++ b/app/views/wallets/balance.html.erb @@ -0,0 +1,2 @@ +

Wallets#balance

+

Find me in app/views/wallets/balance.html.erb

diff --git a/app/views/wallets/balance.json.jbuilder b/app/views/wallets/balance.json.jbuilder new file mode 100644 index 00000000..2a5a7f6b --- /dev/null +++ b/app/views/wallets/balance.json.jbuilder @@ -0,0 +1 @@ +json.balance @wallet.balance \ No newline at end of file diff --git a/app/views/wallets/balance_chart.json.jbuilder b/app/views/wallets/balance_chart.json.jbuilder new file mode 100644 index 00000000..4f58109a --- /dev/null +++ b/app/views/wallets/balance_chart.json.jbuilder @@ -0,0 +1,12 @@ +json.income do + json.array! (0..6).each do |i| + json.y @balance_chart_array[0][i] + json.x @balance_chart_array[2][i].to_date + end +end +json.outcome do + json.array! (0..6).each do |i| + json.y @balance_chart_array[1][i] + json.x @balance_chart_array[2][i].to_date + end +end \ No newline at end of file diff --git a/app/views/wallets/coin_changes.json.jbuilder b/app/views/wallets/coin_changes.json.jbuilder new file mode 100644 index 00000000..35452f48 --- /dev/null +++ b/app/views/wallets/coin_changes.json.jbuilder @@ -0,0 +1,25 @@ +json.balance @wallet.balance +json.count @total +json.coin_changes do + json.array! @coin_changes do |coin_change| + from_user = if coin_change.from_wallet.nil? + nil + else + coin_change.from_wallet.user + end + to_user = coin_change.to_wallet.user + json.amount coin_change.amount + if !from_user.nil? + json.from_user from_user.full_name + json.from_user_login from_user.login + else + json.from_user '系统' + json.from_user_login '-' + end + json.to_user to_user.full_name + json.to_user_login to_user.login + json.description coin_change.description + json.reason coin_change.reason + json.date coin_change.created_at.to_date + end +end diff --git a/app/views/wallets/community_data.json.jbuilder b/app/views/wallets/community_data.json.jbuilder new file mode 100644 index 00000000..701d02ba --- /dev/null +++ b/app/views/wallets/community_data.json.jbuilder @@ -0,0 +1,4 @@ +json.array! (0..6).each do |i| + json.y @community_data_array[0][i] + json.x @community_data_array[1][i].to_date +end \ No newline at end of file diff --git a/config/cable.yml b/config/cable.yml index 8aeb1df9..8f0d0591 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,12 +1,12 @@ -development: - adapter: redis - url: redis://localhost:6379 +#development: +# adapter: redis +# url: redis://localhost:6379 -test: - adapter: redis - url: redis://localhost:6379 +#test: +# adapter: redis +# url: redis://localhost:6379 -production: - adapter: redis - url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379" } %> - channel_prefix: forgeplus_production +#production: +# adapter: redis +# url: <%#= ENV.fetch("REDIS_URL") { "redis://localhost:6379" } %> +# channel_prefix: forgeplus_production diff --git a/config/environments/development.rb b/config/environments/development.rb index 1adbdde7..0b768f82 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -55,6 +55,9 @@ Rails.application.configure do # Suppress logger output for asset requests. config.assets.quiet = true + # config.logger = Logger.new("#{Rails.root}/log/#{Rails.env}#{Date.today.to_s}.log", "daily") + # config.logger.level = Logger::INFO + # config.assets.prefix = '/dev-assets' # Raises error for missing translations diff --git a/config/initializers/redis_cache.rb b/config/initializers/redis_cache.rb index 67f52ec7..57abd448 100644 --- a/config/initializers/redis_cache.rb +++ b/config/initializers/redis_cache.rb @@ -1,3 +1,3 @@ redis_config = Rails.application.config_for(:redis) cache_url = redis_config["url"] || 'redis://localhost:6379' -$redis_cache = Redis.new(url: cache_url, db: 2) \ No newline at end of file +# $redis_cache = Redis.new(url: cache_url, db: 2) \ No newline at end of file diff --git a/config/initializers/user_trace_logger.rb b/config/initializers/user_trace_logger.rb new file mode 100644 index 00000000..7188c20b --- /dev/null +++ b/config/initializers/user_trace_logger.rb @@ -0,0 +1,9 @@ +require 'multi_logger' +formatter = Proc.new{|severity, time, progname, msg| + formatted_severity = sprintf("%-5s",severity.to_s) + formatted_time = time.strftime("%Y-%m-%d %H:%M:%S") + # "[#{formatted_severity} #{formatted_time} #{$$}] #{msg.to_s.strip}\n" + "#{msg.to_s.strip}\n" +} +MultiLogger.add_logger('user_trace', formatter: formatter, shift_age: 'daily') +Rails.logger.user_trace.level = Logger::INFO diff --git a/config/routes.rb b/config/routes.rb index 22773794..6890c396 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,6 +35,28 @@ Rails.application.routes.draw do resources :edu_settings scope '/api' do + get 'wallets/balance' + get 'wallets/coin_changes' + get 'wallets/balance_chart' + + get 'sponsorships/community_data' + get 'wallets/community_data' + + get 'log/list', to: 'log#list' + # post 'log/download', to: 'log#download' + match 'log/download/:filename' => 'log#download', :constraints => { filename: /[0-z\.]+/ }, via:[:get] + + resources :sponsor_tiers, only: [:index, :show, :create, :update, :destroy] + resources :sponsorships, only: [:index, :show, :create, :update, :destroy] do + collection do + get :sponsored + get :sponsoring + get :stopped_sponsored + get :stopped_sponsoring + get :stopped + end + end + resources :topics, only: [:index] namespace :ci do resources :languages, only: [:index, :show] do @@ -141,9 +163,9 @@ Rails.application.routes.draw do delete :quit end end - resources :team_projects, only: [:index, :create, :destroy] do - collection do - post :create_all + resources :team_projects, only: [:index, :create, :destroy] do + collection do + post :create_all delete :destroy_all end end @@ -242,6 +264,7 @@ Rails.application.routes.draw do get :projects get :watch_users get :fan_users + put :update_sponsor_description get :hovercard put :update_image get :get_image @@ -449,11 +472,11 @@ Rails.application.routes.draw do end end - namespace :traces do + namespace :traces do resources :trace_users, only: [:create] - scope "/:owner/:repo" do + scope "/:owner/:repo" do resource :projects, path: '/', only: [:index] do - member do + member do post :tasks get :task_results get :reload_task @@ -664,15 +687,15 @@ Rails.application.routes.draw do post :cancel end end - resources :project_invite_links, only: [:index] do - collection do + resources :project_invite_links, only: [:index] do + collection do get :current_link post :generate_link get :show_link post :redirect_link end end - resources :webhooks, except: [:show, :new] do + resources :webhooks, except: [:show, :new] do member do get :tasks post :test @@ -768,12 +791,12 @@ Rails.application.routes.draw do resources :project_licenses resources :project_ignores resources :reversed_keywords - resources :system_notifications do - member do + resources :system_notifications do + member do get :history end end - resources :message_templates, only: [:index, :new, :create, :edit, :update] do + resources :message_templates, only: [:index, :new, :create, :edit, :update] do collection do get :init_data end @@ -944,7 +967,7 @@ Rails.application.routes.draw do resources :nps do post :switch_change, on: :collection end - resources :feedbacks, only: [:index, :destroy] do + resources :feedbacks, only: [:index, :destroy] do get :new_history, on: :member post :create_history, on: :member end diff --git a/config/schedule.rb b/config/schedule.rb new file mode 100644 index 00000000..6833ca1a --- /dev/null +++ b/config/schedule.rb @@ -0,0 +1,41 @@ +# Use this file to easily define all of your cron jobs. +# +# It's helpful, but not entirely necessary to understand cron before proceeding. +# http://en.wikipedia.org/wiki/Cron + +# Example: +# +# set :output, "/path/to/my/cron_log.log" +# +# every 2.hours do +# command "/usr/bin/some_great_command" +# runner "MyModel.some_method" +# rake "some:great:rake:task" +# end +# +# every 4.days do +# runner "AnotherModel.prune_old_records" +# end + +# Learn more: http://github.com/javan/whenever +# +set :environment, :development +every '0 1 20 * *' do + runner 'Sponsorship.monthly_payment' +end +every '0 2 * * *' do + runner 'Statistic.record' +end +# every 1.month, at: 'January 20th 10:00am' do +# runner 'Sponsorship.monthly_payment' +# end +# ####################################################### +# * * * * * command to be executed +# - - - - - +# | | | | | +# | | | | +----- day of week (0 - 6) (Sunday=0) +# | | | +------- month (1 - 12) +# | | +--------- day of month (1 - 31) +# | +----------- hour (0 - 23) +# +------------- min (0 - 59) +# ####################################################### diff --git a/db/migrate/20200724085032_add_column_to_table_users.rb b/db/migrate/20200724085032_add_column_to_table_users.rb new file mode 100644 index 00000000..3fa706ac --- /dev/null +++ b/db/migrate/20200724085032_add_column_to_table_users.rb @@ -0,0 +1,8 @@ +class AddColumnToTableUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :description, :string, default: "" + add_column :users, :sponsor_certification, :integer, default: 0 + add_column :users, :sponsor_num, :integer, default: 0 + add_column :users, :sponsored_num, :integer, default: 0 + end +end diff --git a/db/migrate/20200724090750_create_sponsorships.rb b/db/migrate/20200724090750_create_sponsorships.rb new file mode 100644 index 00000000..6feb9892 --- /dev/null +++ b/db/migrate/20200724090750_create_sponsorships.rb @@ -0,0 +1,12 @@ +class CreateSponsorships < ActiveRecord::Migration[5.2] + def change + create_table :sponsorships do |t| + t.integer :amount + t.integer :visible + t.integer :sponsor_id + t.integer :developer_id + + t.timestamps + end + end +end diff --git a/db/migrate/20200724093202_create_sponsor_tiers.rb b/db/migrate/20200724093202_create_sponsor_tiers.rb new file mode 100644 index 00000000..14317f9a --- /dev/null +++ b/db/migrate/20200724093202_create_sponsor_tiers.rb @@ -0,0 +1,9 @@ +class CreateSponsorTiers < ActiveRecord::Migration[5.2] + def change + create_table :sponsor_tiers do |t| + t.integer :tier + + t.timestamps + end + end +end diff --git a/db/migrate/20200724093530_add_column_to_sponsor_tiers.rb b/db/migrate/20200724093530_add_column_to_sponsor_tiers.rb new file mode 100644 index 00000000..8210315d --- /dev/null +++ b/db/migrate/20200724093530_add_column_to_sponsor_tiers.rb @@ -0,0 +1,6 @@ +class AddColumnToSponsorTiers < ActiveRecord::Migration[5.2] + def change + add_column :sponsor_tiers, :description, :string, default: "" + add_column :sponsor_tiers, :user_id, :integer + end +end diff --git a/db/migrate/20200724094030_create_stopped_sponsorships.rb b/db/migrate/20200724094030_create_stopped_sponsorships.rb new file mode 100644 index 00000000..b639dc4b --- /dev/null +++ b/db/migrate/20200724094030_create_stopped_sponsorships.rb @@ -0,0 +1,11 @@ +class CreateStoppedSponsorships < ActiveRecord::Migration[5.2] + def change + create_table :stopped_sponsorships do |t| + t.integer :amount + t.integer :sponsor_id + t.integer :developer_id + + t.timestamps + end + end +end diff --git a/db/migrate/20200724094458_create_wallets.rb b/db/migrate/20200724094458_create_wallets.rb new file mode 100644 index 00000000..eab5a06d --- /dev/null +++ b/db/migrate/20200724094458_create_wallets.rb @@ -0,0 +1,10 @@ +class CreateWallets < ActiveRecord::Migration[5.2] + def change + create_table :wallets do |t| + t.integer :balance + t.integer :user_id + + t.timestamps + end + end +end diff --git a/db/migrate/20200724094729_create_coin_changes.rb b/db/migrate/20200724094729_create_coin_changes.rb new file mode 100644 index 00000000..6999312b --- /dev/null +++ b/db/migrate/20200724094729_create_coin_changes.rb @@ -0,0 +1,13 @@ +class CreateCoinChanges < ActiveRecord::Migration[5.2] + def change + create_table :coin_changes do |t| + t.integer :amount + t.string :description + t.string :reason + t.integer :to_wallet_id + t.integer :from_wallet_id + + t.timestamps + end + end +end diff --git a/db/migrate/20200725025555_create_waitlists.rb b/db/migrate/20200725025555_create_waitlists.rb new file mode 100644 index 00000000..701006e9 --- /dev/null +++ b/db/migrate/20200725025555_create_waitlists.rb @@ -0,0 +1,12 @@ +class CreateWaitlists < ActiveRecord::Migration[5.2] + def change + create_table :waitlists do |t| + t.string :applicant_id + t.string :integer + t.string :reviewer_id + t.string :integer + + t.timestamps + end + end +end diff --git a/db/migrate/20200725025657_create_passed_waitlists.rb b/db/migrate/20200725025657_create_passed_waitlists.rb new file mode 100644 index 00000000..6d8b4b81 --- /dev/null +++ b/db/migrate/20200725025657_create_passed_waitlists.rb @@ -0,0 +1,12 @@ +class CreatePassedWaitlists < ActiveRecord::Migration[5.2] + def change + create_table :passed_waitlists do |t| + t.string :applicant_id + t.string :integer + t.string :reviewer_id + t.string :integer + + t.timestamps + end + end +end diff --git a/db/migrate/20200919014501_add_column_to_stopped_sponsorship.rb b/db/migrate/20200919014501_add_column_to_stopped_sponsorship.rb new file mode 100644 index 00000000..edf4fd01 --- /dev/null +++ b/db/migrate/20200919014501_add_column_to_stopped_sponsorship.rb @@ -0,0 +1,5 @@ +class AddColumnToStoppedSponsorship < ActiveRecord::Migration[5.2] + def change + add_column :stopped_sponsorships, :start_time, :datetime + end +end diff --git a/db/migrate/20200920073628_add_visible_to_stopped_sponsorship.rb b/db/migrate/20200920073628_add_visible_to_stopped_sponsorship.rb new file mode 100644 index 00000000..c36e0045 --- /dev/null +++ b/db/migrate/20200920073628_add_visible_to_stopped_sponsorship.rb @@ -0,0 +1,5 @@ +class AddVisibleToStoppedSponsorship < ActiveRecord::Migration[5.2] + def change + add_column :stopped_sponsorships, :visible, :integer + end +end diff --git a/db/migrate/20201017131232_change_user_description_type.rb b/db/migrate/20201017131232_change_user_description_type.rb new file mode 100644 index 00000000..46ad1436 --- /dev/null +++ b/db/migrate/20201017131232_change_user_description_type.rb @@ -0,0 +1,6 @@ +class ChangeUserDescriptionType < ActiveRecord::Migration[5.2] + def change + remove_column :users, :description + add_column :users, :description, :text + end +end diff --git a/db/migrate/20201018133345_add_accumulate_to_sponsorships.rb b/db/migrate/20201018133345_add_accumulate_to_sponsorships.rb new file mode 100644 index 00000000..5b361d2e --- /dev/null +++ b/db/migrate/20201018133345_add_accumulate_to_sponsorships.rb @@ -0,0 +1,6 @@ +class AddAccumulateToSponsorships < ActiveRecord::Migration[5.2] + def change + add_column :sponsorships, :accumulate, :integer, default: 0 + add_column :stopped_sponsorships, :accumulate, :integer, default: 0 + end +end diff --git a/db/migrate/20210316125048_add_award_time_to_user.rb b/db/migrate/20210316125048_add_award_time_to_user.rb new file mode 100644 index 00000000..6d06af45 --- /dev/null +++ b/db/migrate/20210316125048_add_award_time_to_user.rb @@ -0,0 +1,5 @@ +class AddAwardTimeToUser < ActiveRecord::Migration[5.2] + def change + add_column :users, :award_time, :datetime + end +end diff --git a/db/migrate/20211012064053_change_user_description_to_sponsor_description.rb b/db/migrate/20211012064053_change_user_description_to_sponsor_description.rb new file mode 100644 index 00000000..9debc429 --- /dev/null +++ b/db/migrate/20211012064053_change_user_description_to_sponsor_description.rb @@ -0,0 +1,5 @@ +class ChangeUserDescriptionToSponsorDescription < ActiveRecord::Migration[5.2] + def change + rename_column :users, :description, :sponsor_description + end +end diff --git a/db/migrate/20211207012816_create_statistics.rb b/db/migrate/20211207012816_create_statistics.rb new file mode 100644 index 00000000..a0af01ee --- /dev/null +++ b/db/migrate/20211207012816_create_statistics.rb @@ -0,0 +1,9 @@ +class CreateStatistics < ActiveRecord::Migration[5.2] + def change + create_table :statistics do |t| + t.integer :dau + + t.timestamps + end + end +end diff --git a/db/migrate/20211224071147_add_column_to_statistics.rb b/db/migrate/20211224071147_add_column_to_statistics.rb new file mode 100644 index 00000000..609f3595 --- /dev/null +++ b/db/migrate/20211224071147_add_column_to_statistics.rb @@ -0,0 +1,6 @@ +class AddColumnToStatistics < ActiveRecord::Migration[5.2] + def change + add_column :statistics, :wau, :integer + add_column :statistics, :mau, :integer + end +end diff --git a/public/images/undefined b/public/images/undefined new file mode 100644 index 00000000..b2478a82 Binary files /dev/null and b/public/images/undefined differ diff --git a/public/options/readme/readme b/public/options/readme/readme new file mode 100644 index 00000000..cc620a13 --- /dev/null +++ b/public/options/readme/readme @@ -0,0 +1,20 @@ +## 从命令行创建一个新的仓库 + +```bash +touch README.md +git init +git add README.md +git commit -m "first commit" +git remote add origin http://gitea.trustie.net/qiubing/gitea_binary_package.git +git push -u origin master + +``` + +## 从命令行推送已经创建的仓库 + +```bash +git remote add origin http://gitea.trustie.net/qiubing/gitea_binary_package.git +git push -u origin master + +``` + diff --git a/spec/controllers/admin_controller_spec.rb b/spec/controllers/admin_controller_spec.rb deleted file mode 100644 index 64bdb0e7..00000000 --- a/spec/controllers/admin_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe AdminController, type: :controller do - -end diff --git a/spec/controllers/admins/edu_settings_controller_spec.rb b/spec/controllers/admins/edu_settings_controller_spec.rb deleted file mode 100644 index ae516487..00000000 --- a/spec/controllers/admins/edu_settings_controller_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'rails_helper' - -RSpec.describe Admins::EduSettingsController, type: :controller do - - describe "GET #index" do - it "returns http success" do - get :index - expect(response).to have_http_status(:success) - end - end - - describe "GET #new" do - it "returns http success" do - get :new - expect(response).to have_http_status(:success) - end - end - - describe "GET #update" do - it "returns http success" do - get :update - expect(response).to have_http_status(:success) - end - end - - describe "GET #edit" do - it "returns http success" do - get :edit - expect(response).to have_http_status(:success) - end - end - - describe "GET #create" do - it "returns http success" do - get :create - expect(response).to have_http_status(:success) - end - end - - describe "GET #destroy" do - it "returns http success" do - get :destroy - expect(response).to have_http_status(:success) - end - end - -end diff --git a/spec/controllers/blob_controller_spec.rb b/spec/controllers/blob_controller_spec.rb deleted file mode 100644 index 84b25645..00000000 --- a/spec/controllers/blob_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe BlobController, type: :controller do - -end diff --git a/spec/controllers/boards_controller_spec.rb b/spec/controllers/boards_controller_spec.rb deleted file mode 100644 index 7c82238b..00000000 --- a/spec/controllers/boards_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe BoardsController, type: :controller do - -end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb deleted file mode 100644 index ebb867fa..00000000 --- a/spec/controllers/comments_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CommentsController, type: :controller do - -end diff --git a/spec/controllers/course_groups_controller_spec.rb b/spec/controllers/course_groups_controller_spec.rb deleted file mode 100644 index d749604d..00000000 --- a/spec/controllers/course_groups_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseGroupsController, type: :controller do - -end diff --git a/spec/controllers/course_modules_controller_spec.rb b/spec/controllers/course_modules_controller_spec.rb deleted file mode 100644 index abe1fc11..00000000 --- a/spec/controllers/course_modules_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseModulesController, type: :controller do - -end diff --git a/spec/controllers/course_second_categories_controller_spec.rb b/spec/controllers/course_second_categories_controller_spec.rb deleted file mode 100644 index ab899f9d..00000000 --- a/spec/controllers/course_second_categories_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseSecondCategoriesController, type: :controller do - -end diff --git a/spec/controllers/course_stages_controller_spec.rb b/spec/controllers/course_stages_controller_spec.rb deleted file mode 100644 index e63a2b6a..00000000 --- a/spec/controllers/course_stages_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseStagesController, type: :controller do - -end diff --git a/spec/controllers/courses_controller_spec.rb b/spec/controllers/courses_controller_spec.rb deleted file mode 100644 index cbf95f42..00000000 --- a/spec/controllers/courses_controller_spec.rb +++ /dev/null @@ -1,141 +0,0 @@ -require 'rails_helper' - -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. -# -# Also compared to earlier versions of this generator, there are no longer any -# expectations of assigns and templates rendered. These features have been -# removed from Rails core in Rails 5, but can be added back in via the -# `rails-controller-testing` gem. - -RSpec.describe CoursesController, type: :controller do - - # This should return the minimal set of attributes required to create a valid - # Course. As you add validations to Course, be sure to - # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } - - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # CoursesController. Be sure to keep this updated too. - let(:valid_session) { {} } - - describe "GET #index" do - it "returns a success response" do - Course.create! valid_attributes - get :index, params: {}, session: valid_session - expect(response).to be_successful - end - end - - describe "GET #show" do - it "returns a success response" do - course = Course.create! valid_attributes - get :show, params: {id: course.to_param}, session: valid_session - expect(response).to be_successful - end - end - - describe "GET #new" do - it "returns a success response" do - get :new, params: {}, session: valid_session - expect(response).to be_successful - end - end - - describe "GET #edit" do - it "returns a success response" do - course = Course.create! valid_attributes - get :edit, params: {id: course.to_param}, session: valid_session - expect(response).to be_successful - end - end - - describe "POST #create" do - context "with valid params" do - it "creates a new Course" do - expect { - post :create, params: {course: valid_attributes}, session: valid_session - }.to change(Course, :count).by(1) - end - - it "redirects to the created course" do - post :create, params: {course: valid_attributes}, session: valid_session - expect(response).to redirect_to(Course.last) - end - end - - context "with invalid params" do - it "returns a success response (i.e. to display the 'new' template)" do - post :create, params: {course: invalid_attributes}, session: valid_session - expect(response).to be_successful - end - end - end - - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } - - it "updates the requested course" do - course = Course.create! valid_attributes - put :update, params: {id: course.to_param, course: new_attributes}, session: valid_session - course.reload - skip("Add assertions for updated state") - end - - it "redirects to the course" do - course = Course.create! valid_attributes - put :update, params: {id: course.to_param, course: valid_attributes}, session: valid_session - expect(response).to redirect_to(course) - end - end - - context "with invalid params" do - it "returns a success response (i.e. to display the 'edit' template)" do - course = Course.create! valid_attributes - put :update, params: {id: course.to_param, course: invalid_attributes}, session: valid_session - expect(response).to be_successful - end - end - end - - describe "DELETE #destroy" do - it "destroys the requested course" do - course = Course.create! valid_attributes - expect { - delete :destroy, params: {id: course.to_param}, session: valid_session - }.to change(Course, :count).by(-1) - end - - it "redirects to the courses list" do - course = Course.create! valid_attributes - delete :destroy, params: {id: course.to_param}, session: valid_session - expect(response).to redirect_to(courses_url) - end - end - -end diff --git a/spec/controllers/edu_datas_controller_spec.rb b/spec/controllers/edu_datas_controller_spec.rb deleted file mode 100644 index 08fd0c8d..00000000 --- a/spec/controllers/edu_datas_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe EduDatasController, type: :controller do - -end diff --git a/spec/controllers/graduation_tasks_controller_spec.rb b/spec/controllers/graduation_tasks_controller_spec.rb deleted file mode 100644 index 0c4b3749..00000000 --- a/spec/controllers/graduation_tasks_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationTasksController, type: :controller do - -end diff --git a/spec/controllers/graduation_topics_controller_spec.rb b/spec/controllers/graduation_topics_controller_spec.rb deleted file mode 100644 index e60a3706..00000000 --- a/spec/controllers/graduation_topics_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationTopicsController, type: :controller do - -end diff --git a/spec/controllers/graduation_works_controller_spec.rb b/spec/controllers/graduation_works_controller_spec.rb deleted file mode 100644 index 0a4d72f1..00000000 --- a/spec/controllers/graduation_works_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationWorksController, type: :controller do - -end diff --git a/spec/controllers/hack_user_lastest_codes_controller_spec.rb b/spec/controllers/hack_user_lastest_codes_controller_spec.rb deleted file mode 100644 index cfa893e8..00000000 --- a/spec/controllers/hack_user_lastest_codes_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HackUserLastestCodesController, type: :controller do - -end diff --git a/spec/controllers/hacks_controller_spec.rb b/spec/controllers/hacks_controller_spec.rb deleted file mode 100644 index f64ee7e5..00000000 --- a/spec/controllers/hacks_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HacksController, type: :controller do - -end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb deleted file mode 100644 index c8568320..00000000 --- a/spec/controllers/home_controller_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeController, type: :controller do - - describe "GET #index" do - it "returns http success" do - get :index - expect(response).to have_http_status(:success) - end - end - -end diff --git a/spec/controllers/homework_banks_controller_spec.rb b/spec/controllers/homework_banks_controller_spec.rb deleted file mode 100644 index ada01ad8..00000000 --- a/spec/controllers/homework_banks_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkBanksController, type: :controller do - -end diff --git a/spec/controllers/homework_commons_controller_spec.rb b/spec/controllers/homework_commons_controller_spec.rb deleted file mode 100644 index 0efcd175..00000000 --- a/spec/controllers/homework_commons_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkCommonsController, type: :controller do - -end diff --git a/spec/controllers/log_controller_spec.rb b/spec/controllers/log_controller_spec.rb new file mode 100644 index 00000000..afdcff6f --- /dev/null +++ b/spec/controllers/log_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe LogController, type: :controller do + +end diff --git a/spec/controllers/memos_controller_spec.rb b/spec/controllers/memos_controller_spec.rb deleted file mode 100644 index d0b64006..00000000 --- a/spec/controllers/memos_controller_spec.rb +++ /dev/null @@ -1,141 +0,0 @@ -require 'rails_helper' - -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. -# -# Also compared to earlier versions of this generator, there are no longer any -# expectations of assigns and templates rendered. These features have been -# removed from Rails core in Rails 5, but can be added back in via the -# `rails-controller-testing` gem. - -RSpec.describe MemosController, type: :controller do - - # This should return the minimal set of attributes required to create a valid - # Memo. As you add validations to Memo, be sure to - # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } - - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # MemosController. Be sure to keep this updated too. - let(:valid_session) { {} } - - describe "GET #index" do - it "returns a success response" do - Memo.create! valid_attributes - get :index, params: {}, session: valid_session - expect(response).to be_successful - end - end - - describe "GET #show" do - it "returns a success response" do - memo = Memo.create! valid_attributes - get :show, params: {id: memo.to_param}, session: valid_session - expect(response).to be_successful - end - end - - describe "GET #new" do - it "returns a success response" do - get :new, params: {}, session: valid_session - expect(response).to be_successful - end - end - - describe "GET #edit" do - it "returns a success response" do - memo = Memo.create! valid_attributes - get :edit, params: {id: memo.to_param}, session: valid_session - expect(response).to be_successful - end - end - - describe "POST #create" do - context "with valid params" do - it "creates a new Memo" do - expect { - post :create, params: {memo: valid_attributes}, session: valid_session - }.to change(Memo, :count).by(1) - end - - it "redirects to the created memo" do - post :create, params: {memo: valid_attributes}, session: valid_session - expect(response).to redirect_to(Memo.last) - end - end - - context "with invalid params" do - it "returns a success response (i.e. to display the 'new' template)" do - post :create, params: {memo: invalid_attributes}, session: valid_session - expect(response).to be_successful - end - end - end - - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } - - it "updates the requested memo" do - memo = Memo.create! valid_attributes - put :update, params: {id: memo.to_param, memo: new_attributes}, session: valid_session - memo.reload - skip("Add assertions for updated state") - end - - it "redirects to the memo" do - memo = Memo.create! valid_attributes - put :update, params: {id: memo.to_param, memo: valid_attributes}, session: valid_session - expect(response).to redirect_to(memo) - end - end - - context "with invalid params" do - it "returns a success response (i.e. to display the 'edit' template)" do - memo = Memo.create! valid_attributes - put :update, params: {id: memo.to_param, memo: invalid_attributes}, session: valid_session - expect(response).to be_successful - end - end - end - - describe "DELETE #destroy" do - it "destroys the requested memo" do - memo = Memo.create! valid_attributes - expect { - delete :destroy, params: {id: memo.to_param}, session: valid_session - }.to change(Memo, :count).by(-1) - end - - it "redirects to the memos list" do - memo = Memo.create! valid_attributes - delete :destroy, params: {id: memo.to_param}, session: valid_session - expect(response).to redirect_to(memos_url) - end - end - -end diff --git a/spec/controllers/messages_controller_spec.rb b/spec/controllers/messages_controller_spec.rb deleted file mode 100644 index 2672262a..00000000 --- a/spec/controllers/messages_controller_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rails_helper' - -RSpec.describe MessagesController, type: :controller do - - describe "GET #index" do - it "returns http success" do - get :index - expect(response).to have_http_status(:success) - end - end - - describe "GET #create" do - it "returns http success" do - get :create - expect(response).to have_http_status(:success) - end - end - - describe "GET #show" do - it "returns http success" do - get :show - expect(response).to have_http_status(:success) - end - end - -end diff --git a/spec/controllers/protected_branches_controller_spec.rb b/spec/controllers/protected_branches_controller_spec.rb deleted file mode 100644 index 086b746b..00000000 --- a/spec/controllers/protected_branches_controller_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'rails_helper' - -RSpec.describe ProtectedBranchesController, type: :controller do - - describe "GET #index" do - it "returns http success" do - get :index - expect(response).to have_http_status(:success) - end - end - - describe "GET #create" do - it "returns http success" do - get :create - expect(response).to have_http_status(:success) - end - end - - describe "GET #edit" do - it "returns http success" do - get :edit - expect(response).to have_http_status(:success) - end - end - - describe "GET #update" do - it "returns http success" do - get :update - expect(response).to have_http_status(:success) - end - end - - describe "GET #destroy" do - it "returns http success" do - get :destroy - expect(response).to have_http_status(:success) - end - end - -end diff --git a/spec/controllers/question_banks_controller_spec.rb b/spec/controllers/question_banks_controller_spec.rb deleted file mode 100644 index c8f71858..00000000 --- a/spec/controllers/question_banks_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe QuestionBanksController, type: :controller do - -end diff --git a/spec/controllers/schools_controller_spec.rb b/spec/controllers/schools_controller_spec.rb deleted file mode 100644 index a4ad9828..00000000 --- a/spec/controllers/schools_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SchoolsController, type: :controller do - -end diff --git a/spec/controllers/sponsor_tiers_controller_spec.rb b/spec/controllers/sponsor_tiers_controller_spec.rb new file mode 100644 index 00000000..64ed32ca --- /dev/null +++ b/spec/controllers/sponsor_tiers_controller_spec.rb @@ -0,0 +1,157 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe SponsorTiersController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # SponsorTier. As you add validations to SponsorTier, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + {tier: 10, user_id: 6, description: 'Rspec test description'} + } + + let(:invalid_attributes) { + {t: '10', user_id: -1, descrip: 'Rspec test description'} + } + + let(:invalid_user_attributes) { + {tier: 10, user_id: 4, description: 'Rspec test invalid user description'} + } + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # SponsorTiersController. Be sure to keep this updated too. + let(:valid_session) { + {user_id: 6, www_user_id: 6} + } + + describe 'GET #index' do + it 'returns a success response' do + SponsorTier.create! valid_attributes + get :index, params: {login: 'qyzh123123'}, session: valid_session + expect(response).to render_template('index') + end + end + + describe 'POST #create' do + context 'with valid params' do + it 'render ok' do + post :create, params: valid_attributes, session: valid_session + expect(response).to be_successful + end + end + end + + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) { + {tier: 12, description: 'Rspec test update description'} + } + + # it 'updates the requested sponsor_tier' do + # sponsor_tier = SponsorTier.create! valid_attributes + # put :update, params: {id: sponsor_tier.to_param, sponsor_tier: new_attributes}, session: valid_session + # sponsor_tier.reload + # expect(sponsor_tier.tier).to eq(12) + # expect(sponsor_tier.description).to eq('Rspec test update description') + # end + + it 'render ok' do + sponsor_tier = SponsorTier.create! valid_attributes + post :update, params: {id: sponsor_tier.to_param, tier: 10, description: 'Rspec test update description'}, session: valid_session + expect(response).to be_successful + end + end + + # context 'with invalid params' do + # it 'does not update and redirects to the sponsor_tier' do + # sponsor_tier = SponsorTier.create! valid_attributes + # put :update, params: {id: sponsor_tier.to_param, sponsor_tier: invalid_attributes}, session: valid_session + # expect(response).to redirect_to(sponsor_tier) + # expect(sponsor_tier.tier).to eq(10) + # expect(sponsor_tier.description).to eq('Rspec test description') + # end + # end + # + # context 'with invalid user id' do + # let(:new_attributes) { + # {tier: 12, description: 'Rspec test update description'} + # } + # it 'does not update SponsorTier' do + # sponsor_tier = SponsorTier.create! invalid_user_attributes + # put :update, params: {id: sponsor_tier.to_param, sponsor_tier: new_attributes}, session: valid_session + # sponsor_tier.reload + # expect(sponsor_tier.tier).to eq(10) + # expect(sponsor_tier.description).to eq('Rspec test invalid user description') + # end + # + # it 'redirects to the sponsor_tier' do + # sponsor_tier = SponsorTier.create! invalid_user_attributes + # put :update, params: {id: sponsor_tier.to_param, sponsor_tier: valid_attributes}, session: valid_session + # expect(response).to be_ok + # end + # end + end + + describe 'DELETE #destroy' do + context 'with valid user id' do + # it 'destroys the requested sponsor_tier' do + # sponsor_tier = SponsorTier.create! valid_attributes + # expect { + # delete :destroy, params: {id: sponsor_tier.to_param}, session: valid_session + # }.to change(SponsorTier, :count).by(-1) + # end + + it 'be ok' do + sponsor_tier = SponsorTier.create! valid_attributes + delete :destroy, params: {id: sponsor_tier.to_param}, session: valid_session + expect(response).to be_successful + end + end + # + # context 'with invalid user id' do + # it 'does not destroy the requested sponsor_tier' do + # sponsor_tier = SponsorTier.create! invalid_user_attributes + # expect { + # delete :destroy, params: {id: sponsor_tier.to_param}, session: valid_session + # }.to change(SponsorTier, :count).by(0) + # end + # + # it 'be ok' do + # sponsor_tier = SponsorTier.create! invalid_user_attributes + # delete :destroy, params: {id: sponsor_tier.to_param}, session: valid_session + # expect(response).to be_ok + # end + # end + end + + describe 'GET #show' do + it 'returns a success response' do + sponsor_tier = SponsorTier.create! valid_attributes + get :show, params: {id: sponsor_tier.to_param}, session: valid_session + expect(response).to be_successful + end + end + +end diff --git a/spec/controllers/sponsorships_controller_spec.rb b/spec/controllers/sponsorships_controller_spec.rb new file mode 100644 index 00000000..03e9d99c --- /dev/null +++ b/spec/controllers/sponsorships_controller_spec.rb @@ -0,0 +1,177 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe SponsorshipsController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Sponsorship. As you add validations to Sponsorship, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + {amount: 10, visible: 1, developer_id: 4, sponsor_id: 6} + } + + let(:valid_create_api_attributes) { + {amount: 10, visible: 1, developer_id: 4, single: false} + } + + let(:invalid_user_attributes) { + {amount: 10, visible: 1, sponsor_id: 4, developer_id: 1} + } + + let(:invalid_attributes) { + {amunt: 10, visible: 1, developer_id: 1, sponsor_id: 6} + } + + let(:existed_sponsorship) { + {amount: 10, visible: 1, developer_id: 4, sponsor_id: 6, accumulate: 0} + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # SponsorshipsController. Be sure to keep this updated too. + let(:valid_session) { {www_user_id: 6} } + let(:visitor_session) { {www_user_id: 4} } + + # before :each do + # request.env["HTTP_ACCEPT"] = 'application/json' + # end + + describe 'POST #create' do + + context 'render' do + it 'return ok' do + post :create, params: valid_create_api_attributes, session: valid_session + expect(response).to be_successful + end + end + end + + describe 'GET #index' do + before {Sponsorship.create valid_attributes} + it 'render index' do + Sponsorship.create! valid_attributes + get :index, params: {}, format: 'json', session: valid_session + expect(response).to render_template("index") + end + end + + describe 'GET #stopped' do + it 'render stopped' do + sponsorship=StoppedSponsorship.create! valid_attributes + get :stopped, params: {}, format: 'json', session: valid_session + expect(response).to render_template("stopped") + end + end + + describe 'GET #sponsored' do + context 'owner' do + it 'render sponsred' do + sponsorship=Sponsorship.create! valid_attributes + get :sponsored, params: {id: 6}, format: 'json', session: valid_session + expect(response).to render_template("sponsored") + end + end + end + + describe 'GET #sponsoring' do + context 'owner' do + it 'render sponsoring' do + get :sponsoring, params: {id: 6}, format: 'json', session: valid_session + expect(response).to render_template("sponsoring") + end + end + end + + describe 'GET #stopped_sponsored' do + it 'render stopped_sponsored' do + get :stopped_sponsored, params: {id: 6}, format: 'json', session: valid_session + expect(response).to render_template("stopped_sponsored") + end + end + + describe 'GET #stopped_sponsoring' do + before {Sponsorship.create! valid_attributes} + it 'render stopped_sponsoring' do + get :stopped_sponsoring, params: {id: 5}, format: 'json', session: valid_session + expect(response).to render_template("stopped_sponsoring") + end + end + + describe 'PUT #update' do + context 'with valid params' do + it 'render ok' do + sponsorship = Sponsorship.create! valid_attributes + put :update, params: {id: sponsorship.to_param, sponsorship: valid_attributes}, session: valid_session + expect(response).to be_ok + end + end + + # context 'with invalid params' do + # it "returns a success response (i.e. to display the 'edit' template)" do + # sponsorship = Sponsorship.create! valid_attributes + # put :update, params: {id: sponsorship.to_param, sponsorship: invalid_attributes}, session: valid_session + # expect(response).to be_successful + # end + # end + end + + describe 'DELETE #destroy' do + # it 'destroys the requested sponsorship' do + # sponsorship = Sponsorship.create! valid_attributes + # expect { + # delete :destroy, params: {id: sponsorship.to_param}, session: valid_session + # }.to change(Sponsorship, :count).by(-1) + # end + # + # it 'destroys the requested sponsorship' do + # sponsorship = Sponsorship.create! invalid_user_attributes + # expect { + # delete :destroy, params: {id: sponsorship.to_param}, session: valid_session + # }.to change(Sponsorship, :count).by(0) + # end + + it 'return ok' do + sponsorship = Sponsorship.create! valid_attributes + delete :destroy, params: {id: sponsorship.to_param}, session: valid_session + expect(response).to be_ok + end + end + + describe 'GET #show' do + it 'returns a success response' do + sponsorship = Sponsorship.create! valid_attributes + get :show, params: {id: sponsorship.to_param}, session: valid_session + expect(response).to be_successful + end + end + + describe 'GET #community_data' do + it 'returns a success response' do + sponsorship = Sponsorship.create! valid_attributes + get :community_data, params: {}, session: valid_session + expect(response).to be_successful + end + end +end diff --git a/spec/controllers/stages_controller_spec.rb b/spec/controllers/stages_controller_spec.rb deleted file mode 100644 index bac6e678..00000000 --- a/spec/controllers/stages_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe StagesController, type: :controller do - -end diff --git a/spec/controllers/student_works_controller_spec.rb b/spec/controllers/student_works_controller_spec.rb deleted file mode 100644 index 11a4bed7..00000000 --- a/spec/controllers/student_works_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe StudentWorksController, type: :controller do - -end diff --git a/spec/controllers/subject_lists_controller_spec.rb b/spec/controllers/subject_lists_controller_spec.rb deleted file mode 100644 index b6ce0167..00000000 --- a/spec/controllers/subject_lists_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubjectListsController, type: :controller do - -end diff --git a/spec/controllers/trustie_hacks_controller_spec.rb b/spec/controllers/trustie_hacks_controller_spec.rb deleted file mode 100644 index bad65032..00000000 --- a/spec/controllers/trustie_hacks_controller_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe TrustieHacksController, type: :controller do - -end diff --git a/spec/controllers/wallets_controller_spec.rb b/spec/controllers/wallets_controller_spec.rb new file mode 100644 index 00000000..2d0bc273 --- /dev/null +++ b/spec/controllers/wallets_controller_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +RSpec.describe WalletsController, type: :controller do + + let(:valid_session) { + {user_id: 4, www_user_id: 4} + } + + describe 'GET #balance' do + it 'returns http success' do + get :balance, params: {id: 4}, session: valid_session + expect(response).to render_template('balance') + end + end + + describe 'GET #coin_changes' do + context 'all' do + it 'success' do + get :coin_changes, params: {id: 4, category: 'all'}, session: valid_session + expect(response).to render_template('coin_changes') + end + end + + context 'income' do + it 'success' do + get :coin_changes, params: {id: 4, category: 'income'}, session: valid_session + expect(response).to render_template('coin_changes') + end + end + + context 'outcome' do + it 'success' do + get :coin_changes, params: {id: 4, category: 'outcome'}, session: valid_session + expect(response).to render_template('coin_changes') + end + end + end + + describe 'GET #balance_chart' do + it 'returns http success' do + get :balance_chart, params: {id: 4}, session: valid_session + expect(response).to have_http_status(:success) + end + end + + describe 'GET #community_data' do + it 'returns http success' do + get :community_data, params: {id: 4}, session: valid_session + expect(response).to have_http_status(:success) + end + end +end diff --git a/spec/helpers/exercise_questions_helper_spec.rb b/spec/helpers/exercise_questions_helper_spec.rb deleted file mode 100644 index 6a2063b1..00000000 --- a/spec/helpers/exercise_questions_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the ExerciseQuestionsHelper. For example: -# -# describe ExerciseQuestionsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe ExerciseQuestionsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/homework_banks_helper_spec.rb b/spec/helpers/homework_banks_helper_spec.rb deleted file mode 100644 index bd54e5d8..00000000 --- a/spec/helpers/homework_banks_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the HomeworkBanksHelper. For example: -# -# describe HomeworkBanksHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe HomeworkBanksHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/homework_commons_helper_spec.rb b/spec/helpers/homework_commons_helper_spec.rb deleted file mode 100644 index 4880539e..00000000 --- a/spec/helpers/homework_commons_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the HomeworkCommonsHelper. For example: -# -# describe HomeworkCommonsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe HomeworkCommonsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/polls_helper_spec.rb b/spec/helpers/log_helper_spec.rb similarity index 73% rename from spec/helpers/polls_helper_spec.rb rename to spec/helpers/log_helper_spec.rb index 37e63f43..5d95097c 100644 --- a/spec/helpers/polls_helper_spec.rb +++ b/spec/helpers/log_helper_spec.rb @@ -1,15 +1,15 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the PollsHelper. For example: -# -# describe PollsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe PollsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the LogHelper. For example: +# +# describe LogHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe LogHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/question_banks_helper_spec.rb b/spec/helpers/question_banks_helper_spec.rb deleted file mode 100644 index 77601526..00000000 --- a/spec/helpers/question_banks_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the QuestionBanksHelper. For example: -# -# describe QuestionBanksHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe QuestionBanksHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/schools_helper_spec.rb b/spec/helpers/sponsor_tiers_helper_spec.rb similarity index 72% rename from spec/helpers/schools_helper_spec.rb rename to spec/helpers/sponsor_tiers_helper_spec.rb index 3202f4d0..19ce39a7 100644 --- a/spec/helpers/schools_helper_spec.rb +++ b/spec/helpers/sponsor_tiers_helper_spec.rb @@ -1,15 +1,15 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the SchoolsHelper. For example: -# -# describe SchoolsHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe SchoolsHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the SponsorTiersHelper. For example: +# +# describe SponsorTiersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe SponsorTiersHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/subject_lists_helper_spec.rb b/spec/helpers/sponsorships_helper_spec.rb similarity index 72% rename from spec/helpers/subject_lists_helper_spec.rb rename to spec/helpers/sponsorships_helper_spec.rb index b4848016..229491bf 100644 --- a/spec/helpers/subject_lists_helper_spec.rb +++ b/spec/helpers/sponsorships_helper_spec.rb @@ -1,15 +1,15 @@ require 'rails_helper' # Specs in this file have access to a helper object that includes -# the SubjectListsHelper. For example: +# the SponsorshipsHelper. For example: # -# describe SubjectListsHelper do +# describe SponsorshipsHelper do # describe "string concat" do # it "concats two strings with spaces" do # expect(helper.concat_strings("this","that")).to eq("this that") # end # end # end -RSpec.describe SubjectListsHelper, type: :helper do +RSpec.describe SponsorshipsHelper, type: :helper do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/helpers/student_works_helper_spec.rb b/spec/helpers/student_works_helper_spec.rb deleted file mode 100644 index 57940f64..00000000 --- a/spec/helpers/student_works_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the StudentWorksHelper. For example: -# -# describe StudentWorksHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe StudentWorksHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/helpers/export_helper_spec.rb b/spec/helpers/wallets_helper_spec.rb similarity index 72% rename from spec/helpers/export_helper_spec.rb rename to spec/helpers/wallets_helper_spec.rb index 263ddec7..7f242db9 100644 --- a/spec/helpers/export_helper_spec.rb +++ b/spec/helpers/wallets_helper_spec.rb @@ -1,15 +1,15 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the ExportHelper. For example: -# -# describe ExportHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe ExportHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the WalletsHelper. For example: +# +# describe WalletsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe WalletsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/create_subject_course_student_job_spec.rb b/spec/jobs/create_subject_course_student_job_spec.rb deleted file mode 100644 index 1b506fe6..00000000 --- a/spec/jobs/create_subject_course_student_job_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CreateSubjectCourseStudentJob, type: :job do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/jobs/homework_absence_penalty_calculation_job_spec.rb b/spec/jobs/homework_absence_penalty_calculation_job_spec.rb deleted file mode 100644 index b347086c..00000000 --- a/spec/jobs/homework_absence_penalty_calculation_job_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkAbsencePenaltyCalculationJob, type: :job do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb b/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb deleted file mode 100644 index bd5db1e6..00000000 --- a/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkAnonymousAppealStartNotifyJob, type: :job do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/jobs/homework_batch_comment_job_spec.rb b/spec/jobs/homework_batch_comment_job_spec.rb deleted file mode 100644 index e2352f10..00000000 --- a/spec/jobs/homework_batch_comment_job_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkBatchCommentJob, type: :job do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/jobs/homework_end_update_score_job_spec.rb b/spec/jobs/homework_end_update_score_job_spec.rb deleted file mode 100644 index 492b35d4..00000000 --- a/spec/jobs/homework_end_update_score_job_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkEndUpdateScoreJob, type: :job do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb b/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb deleted file mode 100644 index 7a31a825..00000000 --- a/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkEvaluationCommentAssginJob, type: :job do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/jobs/homework_evaluation_start_notify_job_spec.rb b/spec/jobs/homework_evaluation_start_notify_job_spec.rb deleted file mode 100644 index b347ea1f..00000000 --- a/spec/jobs/homework_evaluation_start_notify_job_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkEvaluationStartNotifyJob, type: :job do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/jobs/homework_publish_update_work_status_job_spec.rb b/spec/jobs/homework_publish_update_work_status_job_spec.rb deleted file mode 100644 index a6b6c245..00000000 --- a/spec/jobs/homework_publish_update_work_status_job_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkPublishUpdateWorkStatusJob, type: :job do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/board_spec.rb b/spec/models/board_spec.rb deleted file mode 100644 index 4afdbcc6..00000000 --- a/spec/models/board_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Board, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/career_spec.rb b/spec/models/career_spec.rb deleted file mode 100644 index 709e9a51..00000000 --- a/spec/models/career_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Career, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/challenge_answer_spec.rb b/spec/models/challenge_answer_spec.rb deleted file mode 100644 index 89f7fd04..00000000 --- a/spec/models/challenge_answer_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ChallengeAnswer, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/challenge_sample_spec.rb b/spec/models/challenge_sample_spec.rb deleted file mode 100644 index 27633ca1..00000000 --- a/spec/models/challenge_sample_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ChallengeSample, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/challenge_work_score_spec.rb b/spec/models/challenge_work_score_spec.rb deleted file mode 100644 index 2c36c860..00000000 --- a/spec/models/challenge_work_score_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ChallengeWorkScore, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/discipline_spec.rb b/spec/models/coin_change_spec.rb similarity index 66% rename from spec/models/discipline_spec.rb rename to spec/models/coin_change_spec.rb index 71a5f823..313ecf1f 100644 --- a/spec/models/discipline_spec.rb +++ b/spec/models/coin_change_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Discipline, type: :model do +RSpec.describe CoinChange, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/competition_award_spec.rb b/spec/models/competition_award_spec.rb deleted file mode 100644 index dac3bddc..00000000 --- a/spec/models/competition_award_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CompetitionAward, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/competition_course_course_record_spec.rb b/spec/models/competition_course_course_record_spec.rb deleted file mode 100644 index 4a31ff59..00000000 --- a/spec/models/competition_course_course_record_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CompetitionCourseCourseRecord, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/competition_course_record_spec.rb b/spec/models/competition_course_record_spec.rb deleted file mode 100644 index ddcb7bca..00000000 --- a/spec/models/competition_course_record_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CompetitionCourseRecord, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/competition_course_shixun_record_spec.rb b/spec/models/competition_course_shixun_record_spec.rb deleted file mode 100644 index 5566425d..00000000 --- a/spec/models/competition_course_shixun_record_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CompetitionCourseShixunRecord, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/competition_mode_setting_spec.rb b/spec/models/competition_mode_setting_spec.rb deleted file mode 100644 index 53576788..00000000 --- a/spec/models/competition_mode_setting_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CompetitionModeSetting, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/competition_school_spec.rb b/spec/models/competition_school_spec.rb deleted file mode 100644 index dd90d608..00000000 --- a/spec/models/competition_school_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CompetitionSchool, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/competition_score_spec.rb b/spec/models/competition_score_spec.rb deleted file mode 100644 index d0f1372b..00000000 --- a/spec/models/competition_score_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CompetitionScore, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_activity_spec.rb b/spec/models/course_activity_spec.rb deleted file mode 100644 index 49fbf311..00000000 --- a/spec/models/course_activity_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseActivity, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_group_spec.rb b/spec/models/course_group_spec.rb deleted file mode 100644 index 0e5df849..00000000 --- a/spec/models/course_group_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseGroup, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_homework_category_spec.rb b/spec/models/course_homework_category_spec.rb deleted file mode 100644 index 7c4e69b9..00000000 --- a/spec/models/course_homework_category_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseHomeworkCategory, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_info_spec.rb b/spec/models/course_info_spec.rb deleted file mode 100644 index 9317d8e3..00000000 --- a/spec/models/course_info_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseInfo, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_list_spec.rb b/spec/models/course_list_spec.rb deleted file mode 100644 index d4b9b937..00000000 --- a/spec/models/course_list_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseList, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_member_spec.rb b/spec/models/course_member_spec.rb deleted file mode 100644 index 4e22d08c..00000000 --- a/spec/models/course_member_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseMember, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_message_spec.rb b/spec/models/course_message_spec.rb deleted file mode 100644 index 00bcf57a..00000000 --- a/spec/models/course_message_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseMessage, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_module_spec.rb b/spec/models/course_module_spec.rb deleted file mode 100644 index 68b57eea..00000000 --- a/spec/models/course_module_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseModule, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_second_category_spec.rb b/spec/models/course_second_category_spec.rb deleted file mode 100644 index d057d51b..00000000 --- a/spec/models/course_second_category_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseSecondCategory, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_stage_shixun_spec.rb b/spec/models/course_stage_shixun_spec.rb deleted file mode 100644 index 716af2b9..00000000 --- a/spec/models/course_stage_shixun_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseStageShixun, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_stage_spec.rb b/spec/models/course_stage_spec.rb deleted file mode 100644 index 06c71190..00000000 --- a/spec/models/course_stage_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseStage, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_video_spec.rb b/spec/models/course_video_spec.rb deleted file mode 100644 index ea9553e2..00000000 --- a/spec/models/course_video_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe CourseVideo, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/ec_course_spec.rb b/spec/models/ec_course_spec.rb deleted file mode 100644 index d460556b..00000000 --- a/spec/models/ec_course_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe EcCourse, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/ec_course_user_spec.rb b/spec/models/ec_course_user_spec.rb deleted file mode 100644 index 52725eb6..00000000 --- a/spec/models/ec_course_user_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe EcCourseUser, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/ec_major_course_spec.rb b/spec/models/ec_major_course_spec.rb deleted file mode 100644 index 6c3922b0..00000000 --- a/spec/models/ec_major_course_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe EcMajorCourse, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/ec_school_user_spec.rb b/spec/models/ec_school_user_spec.rb deleted file mode 100644 index 57c0a628..00000000 --- a/spec/models/ec_school_user_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe EcSchoolUser, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/ec_year_spec.rb b/spec/models/ec_year_spec.rb deleted file mode 100644 index 6e4b1cb1..00000000 --- a/spec/models/ec_year_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe EcYear, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/examination_bank_spec.rb b/spec/models/examination_bank_spec.rb deleted file mode 100644 index 28e5878e..00000000 --- a/spec/models/examination_bank_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ExaminationBank, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/examination_intelligent_setting_spec.rb b/spec/models/examination_intelligent_setting_spec.rb deleted file mode 100644 index fb82f86c..00000000 --- a/spec/models/examination_intelligent_setting_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ExaminationIntelligentSetting, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/examination_item_analysis_spec.rb b/spec/models/examination_item_analysis_spec.rb deleted file mode 100644 index 2291c099..00000000 --- a/spec/models/examination_item_analysis_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ExaminationItemAnalysis, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/examination_item_choice_spec.rb b/spec/models/examination_item_choice_spec.rb deleted file mode 100644 index 0907fd09..00000000 --- a/spec/models/examination_item_choice_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ExaminationItemChoice, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/examination_item_spec.rb b/spec/models/examination_item_spec.rb deleted file mode 100644 index b824896d..00000000 --- a/spec/models/examination_item_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ExaminationItem, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/examination_type_setting_spec.rb b/spec/models/examination_type_setting_spec.rb deleted file mode 100644 index 916cb367..00000000 --- a/spec/models/examination_type_setting_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ExaminationTypeSetting, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/exercise_spec.rb b/spec/models/exercise_spec.rb deleted file mode 100644 index 718465b2..00000000 --- a/spec/models/exercise_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Exercise, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/exercise_user_score_spec.rb b/spec/models/exercise_user_score_spec.rb deleted file mode 100644 index 97f67a99..00000000 --- a/spec/models/exercise_user_score_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ExerciseUserScore, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/exercise_user_spec.rb b/spec/models/exercise_user_spec.rb deleted file mode 100644 index 8c88c979..00000000 --- a/spec/models/exercise_user_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ExerciseUser, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/experience_spec.rb b/spec/models/experience_spec.rb deleted file mode 100644 index 5d48e9ab..00000000 --- a/spec/models/experience_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Experience, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/game_answer_spec.rb b/spec/models/game_answer_spec.rb deleted file mode 100644 index 07e46c05..00000000 --- a/spec/models/game_answer_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GameAnswer, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/game_code_spec.rb b/spec/models/game_code_spec.rb deleted file mode 100644 index 46d6233d..00000000 --- a/spec/models/game_code_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GameCode, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/graduation_group_spec.rb b/spec/models/graduation_group_spec.rb deleted file mode 100644 index 35224d30..00000000 --- a/spec/models/graduation_group_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationGroup, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/graduation_task_group_assignation_spec.rb b/spec/models/graduation_task_group_assignation_spec.rb deleted file mode 100644 index d7e0fac0..00000000 --- a/spec/models/graduation_task_group_assignation_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationTaskGroupAssignation, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/graduation_task_spec.rb b/spec/models/graduation_task_spec.rb deleted file mode 100644 index 08e91e70..00000000 --- a/spec/models/graduation_task_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationTask, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/graduation_topic_spec.rb b/spec/models/graduation_topic_spec.rb deleted file mode 100644 index 484458ca..00000000 --- a/spec/models/graduation_topic_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationTopic, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/graduation_work_comment_assignation_spec.rb b/spec/models/graduation_work_comment_assignation_spec.rb deleted file mode 100644 index a1d6936c..00000000 --- a/spec/models/graduation_work_comment_assignation_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationWorkCommentAssignation, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/graduation_work_score_spec.rb b/spec/models/graduation_work_score_spec.rb deleted file mode 100644 index aca019c2..00000000 --- a/spec/models/graduation_work_score_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationWorkScore, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/graduation_work_spec.rb b/spec/models/graduation_work_spec.rb deleted file mode 100644 index ad8eeac4..00000000 --- a/spec/models/graduation_work_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GraduationWork, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/gtask_bank_spec.rb b/spec/models/gtask_bank_spec.rb deleted file mode 100644 index c97711d1..00000000 --- a/spec/models/gtask_bank_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GtaskBank, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/gtopic_bank_spec.rb b/spec/models/gtopic_bank_spec.rb deleted file mode 100644 index c58e71a4..00000000 --- a/spec/models/gtopic_bank_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe GtopicBank, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/hack_set_spec.rb b/spec/models/hack_set_spec.rb deleted file mode 100644 index e6d139f6..00000000 --- a/spec/models/hack_set_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HackSet, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/hack_spec.rb b/spec/models/hack_spec.rb deleted file mode 100644 index 287389f9..00000000 --- a/spec/models/hack_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Hack, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/hack_user_code_spec.rb b/spec/models/hack_user_code_spec.rb deleted file mode 100644 index 65f78679..00000000 --- a/spec/models/hack_user_code_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HackUserCode, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/hack_user_debug_spec.rb b/spec/models/hack_user_debug_spec.rb deleted file mode 100644 index 65856a48..00000000 --- a/spec/models/hack_user_debug_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HackUserDebug, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/hack_user_lastest_code_spec.rb b/spec/models/hack_user_lastest_code_spec.rb deleted file mode 100644 index cf60b6ca..00000000 --- a/spec/models/hack_user_lastest_code_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HackUserLastestCode, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/hack_user_spec.rb b/spec/models/hack_user_spec.rb deleted file mode 100644 index 5bd8221d..00000000 --- a/spec/models/hack_user_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HackUser, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/homework_bank_spec.rb b/spec/models/homework_bank_spec.rb deleted file mode 100644 index d9f25d86..00000000 --- a/spec/models/homework_bank_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkBank, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/homework_challenge_setting_spec.rb b/spec/models/homework_challenge_setting_spec.rb deleted file mode 100644 index 7c9c6688..00000000 --- a/spec/models/homework_challenge_setting_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkChallengeSetting, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/homework_common_spec.rb b/spec/models/homework_common_spec.rb deleted file mode 100644 index 1321fc11..00000000 --- a/spec/models/homework_common_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkCommon, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/homework_commons_shixun_spec.rb b/spec/models/homework_commons_shixun_spec.rb deleted file mode 100644 index 4dc005c6..00000000 --- a/spec/models/homework_commons_shixun_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkCommonsShixun, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/homework_detail_group_spec.rb b/spec/models/homework_detail_group_spec.rb deleted file mode 100644 index d8e6a1e8..00000000 --- a/spec/models/homework_detail_group_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkDetailGroup, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/homework_detail_manual_spec.rb b/spec/models/homework_detail_manual_spec.rb deleted file mode 100644 index 8b20b284..00000000 --- a/spec/models/homework_detail_manual_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkDetailManual, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/homework_group_review_spec.rb b/spec/models/homework_group_review_spec.rb deleted file mode 100644 index 40886347..00000000 --- a/spec/models/homework_group_review_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkGroupReview, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/homework_group_setting_spec.rb b/spec/models/homework_group_setting_spec.rb deleted file mode 100644 index 625f5937..00000000 --- a/spec/models/homework_group_setting_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkGroupSetting, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/homework_review_result_spec.rb b/spec/models/homework_review_result_spec.rb deleted file mode 100644 index 8a41e770..00000000 --- a/spec/models/homework_review_result_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe HomeworkReviewResult, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/inform_spec.rb b/spec/models/inform_spec.rb deleted file mode 100644 index 0bcf9ece..00000000 --- a/spec/models/inform_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Inform, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/memo_spec.rb b/spec/models/memo_spec.rb deleted file mode 100644 index bd0f5313..00000000 --- a/spec/models/memo_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Memo, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/memo_tag_repertoire_spec.rb b/spec/models/memo_tag_repertoire_spec.rb deleted file mode 100644 index 7f185d86..00000000 --- a/spec/models/memo_tag_repertoire_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe MemoTagRepertoire, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb deleted file mode 100644 index a806f6a1..00000000 --- a/spec/models/message_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Message, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/mirror_script_spec.rb b/spec/models/mirror_script_spec.rb deleted file mode 100644 index 7ff89e1e..00000000 --- a/spec/models/mirror_script_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe MirrorScript, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/module_setting_spec.rb b/spec/models/module_setting_spec.rb deleted file mode 100644 index ede89333..00000000 --- a/spec/models/module_setting_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ModuleSetting, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/old_message_detail_spec.rb b/spec/models/old_message_detail_spec.rb deleted file mode 100644 index 0aadef6e..00000000 --- a/spec/models/old_message_detail_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe OldMessageDetail, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/partner_spec.rb b/spec/models/partner_spec.rb deleted file mode 100644 index 06cff9d9..00000000 --- a/spec/models/partner_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Partner, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/jobs/live_publish_job_spec.rb b/spec/models/passed_waitlist_spec.rb similarity index 64% rename from spec/jobs/live_publish_job_spec.rb rename to spec/models/passed_waitlist_spec.rb index d996446d..5124c945 100644 --- a/spec/jobs/live_publish_job_spec.rb +++ b/spec/models/passed_waitlist_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe LivePublishJob, type: :job do +RSpec.describe PassedWaitlist, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/poll_spec.rb b/spec/models/poll_spec.rb deleted file mode 100644 index 01271d4e..00000000 --- a/spec/models/poll_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Poll, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/poll_user_spec.rb b/spec/models/poll_user_spec.rb deleted file mode 100644 index 6ff94efb..00000000 --- a/spec/models/poll_user_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe PollUser, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/portal_image_spec.rb b/spec/models/portal_image_spec.rb deleted file mode 100644 index e7bfeb13..00000000 --- a/spec/models/portal_image_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe PortalImage, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/program_bank_spec.rb b/spec/models/program_bank_spec.rb deleted file mode 100644 index d8a76449..00000000 --- a/spec/models/program_bank_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ProgramBank, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/program_bank_test_spec.rb b/spec/models/program_bank_test_spec.rb deleted file mode 100644 index 22720f25..00000000 --- a/spec/models/program_bank_test_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ProgramBankTest, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/relationship_spec.rb b/spec/models/relationship_spec.rb deleted file mode 100644 index 33984d35..00000000 --- a/spec/models/relationship_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Relationship, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/run_code_message_spec.rb b/spec/models/run_code_message_spec.rb deleted file mode 100644 index 4effde24..00000000 --- a/spec/models/run_code_message_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe RunCodeMessage, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/salesman_channel_spec.rb b/spec/models/salesman_channel_spec.rb deleted file mode 100644 index 5f45a839..00000000 --- a/spec/models/salesman_channel_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SalesmanChannel, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/salesman_customer_spec.rb b/spec/models/salesman_customer_spec.rb deleted file mode 100644 index 1393d3dd..00000000 --- a/spec/models/salesman_customer_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SalesmanCustomer, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/salesman_spec.rb b/spec/models/salesman_spec.rb deleted file mode 100644 index 0a5d3072..00000000 --- a/spec/models/salesman_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Salesman, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/shixun_info_spec.rb b/spec/models/shixun_info_spec.rb deleted file mode 100644 index 5f55a21a..00000000 --- a/spec/models/shixun_info_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ShixunInfo, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/shixun_review_spec.rb b/spec/models/shixun_review_spec.rb deleted file mode 100644 index 0bb62bbe..00000000 --- a/spec/models/shixun_review_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ShixunReview, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/shixun_school_spec.rb b/spec/models/shixun_school_spec.rb deleted file mode 100644 index c435de99..00000000 --- a/spec/models/shixun_school_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ShixunSchool, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/shixun_secret_repository_spec.rb b/spec/models/shixun_secret_repository_spec.rb deleted file mode 100644 index ed06914a..00000000 --- a/spec/models/shixun_secret_repository_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ShixunSecretRepository, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/shixun_service_config_spec.rb b/spec/models/shixun_service_config_spec.rb deleted file mode 100644 index d79cd19f..00000000 --- a/spec/models/shixun_service_config_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ShixunServiceConfig, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/shixun_work_comment_spec.rb b/spec/models/shixun_work_comment_spec.rb deleted file mode 100644 index 0c40ede6..00000000 --- a/spec/models/shixun_work_comment_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ShixunWorkComment, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/course_spec.rb b/spec/models/sponsor_tier_spec.rb similarity index 65% rename from spec/models/course_spec.rb rename to spec/models/sponsor_tier_spec.rb index 1a75c386..3ceab0b6 100644 --- a/spec/models/course_spec.rb +++ b/spec/models/sponsor_tier_spec.rb @@ -1,5 +1,5 @@ -require 'rails_helper' - -RSpec.describe Course, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end +require 'rails_helper' + +RSpec.describe SponsorTier, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/sponsorship_spec.rb b/spec/models/sponsorship_spec.rb new file mode 100644 index 00000000..20457545 --- /dev/null +++ b/spec/models/sponsorship_spec.rb @@ -0,0 +1,53 @@ +require 'rails_helper' + +RSpec.describe Sponsorship, type: :model do + let(:big_amount_sponsorship) { + {amount: 1_000_000, visible: 1, sponsor_id: 4, developer_id: 1, accumulate: 0 } + } + let(:small_amount_sponsorship) { + {amount: 10, visible: 1, sponsor_id: 4, developer_id: 1, accumulate: 0 } + } + + describe 'pay' do + context 'balance enough' do + before {Sponsorship.create small_amount_sponsorship} + it 'pay success' do + sponsorship = Sponsorship.last! + sponsor_wallet = sponsorship.sponsor.get_wallet + sponsor_wallet_balance = sponsor_wallet.balance + expect { + sponsorship.pay + }.to change { sponsor_wallet.balance } + .from(sponsor_wallet_balance) + .to(sponsor_wallet_balance-sponsorship.amount) + end + end + context 'balance not enough' do + before {Sponsorship.create big_amount_sponsorship} + it 'stop sponsorship' do + sponsorship = Sponsorship.last + sponsor_wallet = sponsorship.sponsor.get_wallet + sponsor_wallet_balance = sponsor_wallet.balance + + success = sponsorship.pay + expect(success).to eq(false) + expect(sponsor_wallet.balance).to eq(sponsor_wallet_balance) + end + end + end + + describe 'stop' do + before {Sponsorship.create small_amount_sponsorship} + it 'success' do + sponsorship = Sponsorship.last + expect {sponsorship.stop}.to change(Sponsorship, :count).by(-1) + end + end + + describe 'monthly payment' do + it 'pays' do + expect { Sponsorship.monthly_payment }.to change(CoinChange, :count).by(Sponsorship.count) + end + end + +end diff --git a/spec/models/stage_spec.rb b/spec/models/stage_spec.rb deleted file mode 100644 index 5a2b4163..00000000 --- a/spec/models/stage_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Stage, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/forum_spec.rb b/spec/models/statistic_spec.rb similarity index 66% rename from spec/models/forum_spec.rb rename to spec/models/statistic_spec.rb index 56c24634..ba27a8f2 100644 --- a/spec/models/forum_spec.rb +++ b/spec/models/statistic_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe Forum, type: :model do +RSpec.describe Statistic, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/jobs/create_student_work_job_spec.rb b/spec/models/stopped_sponsorship_spec.rb similarity index 62% rename from spec/jobs/create_student_work_job_spec.rb rename to spec/models/stopped_sponsorship_spec.rb index 401160f8..3e4503dd 100644 --- a/spec/jobs/create_student_work_job_spec.rb +++ b/spec/models/stopped_sponsorship_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe CreateStudentWorkJob, type: :job do +RSpec.describe StoppedSponsorship, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/student_graduation_topic_spec.rb b/spec/models/student_graduation_topic_spec.rb deleted file mode 100644 index f32a79e9..00000000 --- a/spec/models/student_graduation_topic_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe StudentGraduationTopic, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/student_work_spec.rb b/spec/models/student_work_spec.rb deleted file mode 100644 index 02a490c7..00000000 --- a/spec/models/student_work_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe StudentWork, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/student_works_evaluation_distribution_spec.rb b/spec/models/student_works_evaluation_distribution_spec.rb deleted file mode 100644 index 836d7b27..00000000 --- a/spec/models/student_works_evaluation_distribution_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe StudentWorksEvaluationDistribution, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/student_works_score_spec.rb b/spec/models/student_works_score_spec.rb deleted file mode 100644 index 564f57f6..00000000 --- a/spec/models/student_works_score_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe StudentWorksScore, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/student_works_scores_appeal_spec.rb b/spec/models/student_works_scores_appeal_spec.rb deleted file mode 100644 index 08ee704b..00000000 --- a/spec/models/student_works_scores_appeal_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe StudentWorksScoresAppeal, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/students_for_course_spec.rb b/spec/models/students_for_course_spec.rb deleted file mode 100644 index 2a5116f5..00000000 --- a/spec/models/students_for_course_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe StudentsForCourse, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/sub_discipline_container_spec.rb b/spec/models/sub_discipline_container_spec.rb deleted file mode 100644 index 5ad6500c..00000000 --- a/spec/models/sub_discipline_container_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubDisciplineContainer, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/sub_discipline_spec.rb b/spec/models/sub_discipline_spec.rb deleted file mode 100644 index 2eb9e22c..00000000 --- a/spec/models/sub_discipline_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubDiscipline, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/subject_appointment_spec.rb b/spec/models/subject_appointment_spec.rb deleted file mode 100644 index 9b8d2e1b..00000000 --- a/spec/models/subject_appointment_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubjectAppointment, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/subject_course_record_spec.rb b/spec/models/subject_course_record_spec.rb deleted file mode 100644 index bf2daffc..00000000 --- a/spec/models/subject_course_record_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubjectCourseRecord, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/subject_member_spec.rb b/spec/models/subject_member_spec.rb deleted file mode 100644 index d46e3974..00000000 --- a/spec/models/subject_member_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubjectMember, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/subject_record_spec.rb b/spec/models/subject_record_spec.rb deleted file mode 100644 index 6dd9f7b4..00000000 --- a/spec/models/subject_record_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubjectRecord, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/subject_shixun_info_spec.rb b/spec/models/subject_shixun_info_spec.rb deleted file mode 100644 index 83d4b4bf..00000000 --- a/spec/models/subject_shixun_info_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubjectShixunInfo, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/subject_user_info_spec.rb b/spec/models/subject_user_info_spec.rb deleted file mode 100644 index 60c8a76e..00000000 --- a/spec/models/subject_user_info_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe SubjectUserInfo, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/tag_discipline_container_spec.rb b/spec/models/tag_discipline_container_spec.rb deleted file mode 100644 index 268479e9..00000000 --- a/spec/models/tag_discipline_container_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe TagDisciplineContainer, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/tag_discipline_spec.rb b/spec/models/tag_discipline_spec.rb deleted file mode 100644 index 90055a75..00000000 --- a/spec/models/tag_discipline_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe TagDiscipline, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/teacher_course_group_spec.rb b/spec/models/teacher_course_group_spec.rb deleted file mode 100644 index f1cf96bb..00000000 --- a/spec/models/teacher_course_group_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe TeacherCourseGroup, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/trustie_hack_spec.rb b/spec/models/trustie_hack_spec.rb deleted file mode 100644 index d4423cd2..00000000 --- a/spec/models/trustie_hack_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe TrustieHack, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/trustie_hackathon_spec.rb b/spec/models/trustie_hackathon_spec.rb deleted file mode 100644 index 7334fd52..00000000 --- a/spec/models/trustie_hackathon_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe TrustieHackathon, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/hack_code_spec.rb b/spec/models/waitlist_spec.rb similarity index 67% rename from spec/models/hack_code_spec.rb rename to spec/models/waitlist_spec.rb index bc555869..1b8f43be 100644 --- a/spec/models/hack_code_spec.rb +++ b/spec/models/waitlist_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe HackCode, type: :model do +RSpec.describe Waitlist, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/wallet_spec.rb b/spec/models/wallet_spec.rb new file mode 100644 index 00000000..c804bf88 --- /dev/null +++ b/spec/models/wallet_spec.rb @@ -0,0 +1,40 @@ +require 'rails_helper' + +RSpec.describe Wallet, type: :model do + describe 'receive' do + it 'success' do + wallet = Wallet.find_by_id(4) + balance = wallet.balance + amount = 5 + expect { + wallet.receive(amount) + }.to change { wallet.balance }.from(balance).to(balance+amount) + end + end + + describe 'pay' do + context 'balance enough' do + it 'success to pay' do + wallet = Wallet.find_by_id(4) + balance = wallet.balance + amount = 5 + success = false + expect { + success = wallet.pay(amount) + }.to change { wallet.balance }.from(balance).to(balance-amount) + expect(success).to eq(true) + end + end + + context 'balance not enough' do + it 'fail to pay' do + wallet = Wallet.find_by_id(4) + balance = wallet.balance + amount = 500 + success = wallet.pay(amount) + expect(success).to eq(false) + expect(wallet.balance).to eq(balance) + end + end + end +end diff --git a/spec/models/zip_pack_spec.rb b/spec/models/zip_pack_spec.rb deleted file mode 100644 index 583c5d2e..00000000 --- a/spec/models/zip_pack_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe ZipPack, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/requests/accounts_spec.rb b/spec/requests/accounts_spec.rb index 791edf1a..ab4a7fac 100644 --- a/spec/requests/accounts_spec.rb +++ b/spec/requests/accounts_spec.rb @@ -5,12 +5,12 @@ RSpec.describe "帐户", type: :request do it "成功登录" do - ecpost login_accounts_url, {login: 'guange', password: '123456'} - expect(JSON.parse(response.body)["login"]).to eq('guange') + ecpost login_accounts_url, params: {login: 'testaccount', password: 'Qyzhabc1@3'} + expect(JSON.parse(response.body)).to eq('testaccount') end it "登录失败" do - ecpost login_accounts_url, {login: 'guange', password: 'wrong password'} + ecpost login_accounts_url, {login: 'testaccount', password: 'wrong password'} expect(JSON.parse(response.body)["status"]).to eq(-1) end diff --git a/spec/requests/courses_spec.rb b/spec/requests/courses_spec.rb deleted file mode 100644 index a70a7e05..00000000 --- a/spec/requests/courses_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'rails_helper' - -RSpec.describe "Courses", type: :request do - describe "GET /courses" do - it "works! (now write some real specs)" do - get courses_path - expect(response).to have_http_status(200) - end - end -end diff --git a/spec/requests/git_service_spec.rb b/spec/requests/git_service_spec.rb index c065dd81..6af5c85b 100644 --- a/spec/requests/git_service_spec.rb +++ b/spec/requests/git_service_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" RSpec.describe "git服务" do - +=begin let(:repo_path){'educoder/i4nzvb7x.git'} it "add_repository" do @@ -45,5 +45,5 @@ RSpec.describe "git服务" do author_email: '8863824@gmil.com') expect data.nil? end - +=end end diff --git a/spec/requests/memos_spec.rb b/spec/requests/memos_spec.rb deleted file mode 100644 index 62f0d3d1..00000000 --- a/spec/requests/memos_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'rails_helper' - -RSpec.describe "Memos", type: :request do - describe "GET /memos" do - it "works! (now write some real specs)" do - get memos_path - expect(response).to have_http_status(200) - end - end -end diff --git a/spec/requests/shixuns_spec.rb b/spec/requests/shixuns_spec.rb index 155f7f49..02f9abab 100644 --- a/spec/requests/shixuns_spec.rb +++ b/spec/requests/shixuns_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" RSpec.describe "实训页面测试", type: :request do - +=begin context "实训首页" do it "默认参数" do ecget shixuns_url @@ -82,4 +82,5 @@ RSpec.describe "实训页面测试", type: :request do ecget collaborators_shixun_url(identifier: 'WQ9ROKFX') expect(JSON.parse(response.body).size).to be > 0 end +=end end diff --git a/spec/requests/sponsor_tiers_spec.rb b/spec/requests/sponsor_tiers_spec.rb new file mode 100644 index 00000000..17b72fc6 --- /dev/null +++ b/spec/requests/sponsor_tiers_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe "SponsorTiers", type: :request do + + let(:developer_session) { {www_user_id: 5} } + let(:visitor_session) { {www_user_id: 4} } + let(:valid_session) { {www_user_id: 6} } + + describe "GET /sponsor_tiers" do + it "success" do + get '/api/sponsor_tiers.json', params: {login: '123457qqcom'}, as: :json + expect(JSON.parse(response.body).length).to eq(1) + end + end +end diff --git a/spec/requests/sponsorships_spec.rb b/spec/requests/sponsorships_spec.rb new file mode 100644 index 00000000..c99e3786 --- /dev/null +++ b/spec/requests/sponsorships_spec.rb @@ -0,0 +1,192 @@ +require 'rails_helper' + +RSpec.describe 'Sponsorships', type: :request do + + let(:valid_attributes) { + {amount: 10, visible: 1, developer_id: 1, sponsor_id: 5} + } + + let(:valid_create_api_attributes) { + {amount: 10, visible: 1, developer_id: 1} + } + + let(:invalid_user_attributes) { + {amount: 10, visible: 1, sponsor_id: 4, developer_id: 1} + } + let(:invalid_attributes) { + {amunt: 10, visible: 1, developid: 1, sponsoid: 5} + } + let(:developer_session) { {www_user_id: 5} } + let(:visitor_session) { {www_user_id: 4} } + let(:valid_session) { {www_user_id: 6} } + + describe 'create sponsorship' do + context 'success' do + it 'create a new sponsorship' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + expect { + post '/api/sponsorships.json', params: {'amount'=>5, 'visible'=>1, single: false, 'developer_id'=>1, 'sponsorship'=>{'amount'=>5, 'visible'=>1, 'developer_id'=>1}}, as: :json + }.to change(Sponsorship, :count).by(1) + end + end + + context 'single success' do + it 'create a stopped_sponsorship' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + expect { + post '/api/sponsorships.json', params: {'amount'=>5, 'visible'=>1, single: true, 'developer_id'=>1, 'sponsorship'=>{'amount'=>5, 'visible'=>1, 'developer_id'=>1}}, as: :json + }.to change(StoppedSponsorship, :count).by(1) + end + end + + context 'fail to repeat sponsorship' do + it 'returns fail' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + post '/api/sponsorships.json', params: {'amount'=>5, 'visible'=>1, single: false, 'developer_id'=>4, 'sponsorship'=>{'amount'=>5, 'visible'=>1, 'developer_id'=>4}}, as: :json + expect(JSON.parse(response.body)['message']).to eq('您已经赞助了TA') + end + end + + context 'balance not enough' do + it 'returns fail' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + expect { + post '/api/sponsorships.json', params: {'amount'=>500000, 'visible'=>1, single: false, 'developer_id'=>1, 'sponsorship'=>{'amount'=>500000, 'visible'=>1, 'developer_id'=>1}}, as: :json + }.to change(Sponsorship, :count).by(0) + end + end + end + + describe 'index' do + context 'success' do + it 'returns n records' do + get '/api/sponsorships.json' + expect(JSON.parse(response.body).length).to eq(Sponsorship.count) + end + end + end + + describe 'stopped' do + context 'success' do + it 'returns n records' do + get '/api/sponsorships/stopped.json' + expect(JSON.parse(response.body).length).to eq(StoppedSponsorship.count) + end + end + end + + describe 'sponsored' do + context 'valid_session' do + it 'returns 2 records' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + get '/api/sponsorships/sponsored.json', params: {id: 6} + expect(JSON.parse(response.body)['sponsorships'].length).to eq(2) + end + end + + context 'visitor session' do + it 'returns 1 record' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session } + get '/api/sponsorships/sponsored.json', params: {id: 6} + expect(JSON.parse(response.body)['sponsorships'].length).to eq(1) + end + end + end + + describe 'sponsoring' do + context 'valid_session' do + it 'returns 2 records' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + get '/api/sponsorships/sponsoring.json', params: {id: 6} + expect(JSON.parse(response.body)['sponsorships'].length).to eq(2) + end + end + + context 'visitor session' do + it 'returns 1 record' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session } + get '/api/sponsorships/sponsoring.json', params: {id: 6} + expect(JSON.parse(response.body)['sponsorships'].length).to eq(1) + end + end + end + + describe 'stopped_sponsored' do + context 'valid_session' do + it 'returns 2 records' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + get '/api/sponsorships/stopped_sponsored.json', params: {id: 6} + expect(JSON.parse(response.body)['sponsorships'].length).to eq(2) + end + end + + context 'visitor session' do + it 'returns 1 record' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session } + get '/api/sponsorships/stopped_sponsored.json', params: {id: 6} + expect(JSON.parse(response.body)['sponsorships'].length).to eq(1) + end + end + end + + describe 'stopped_sponsoring' do + context 'valid_session' do + it 'returns 2 records' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + get '/api/sponsorships/stopped_sponsoring.json', params: {id: 6} + expect(JSON.parse(response.body)['sponsorships'].length).to eq(2) + end + end + + context 'visitor session' do + it 'returns 1 record' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session } + get '/api/sponsorships/stopped_sponsoring.json', params: {id: 6} + expect(JSON.parse(response.body)['sponsorships'].length).to eq(1) + end + end + end + + describe 'update' do + context 'as sponsor' do + it 'update success' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + put '/api/sponsorships/97.json', params: {amount: 50, sponsorship: {amount: 50}}, as: :json + expect(Sponsorship.find(97).amount).to eq(50) + expect(response.body).to eq('{"status":1,"message":"修改成功"}') + end + end + + context 'as others' do + it 'fail' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { developer_session } + put '/api/sponsorships/97.json', params: {amount: 50, sponsorship: {amount: 50}}, as: :json + expect(Sponsorship.find(97).amount).to eq(10) + expect(response.body).to eq('{"status":401,"message":"没有权限"}') + end + end + end + + describe 'destroy' do + context 'as sponsor' do + it 'success' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + expect{ delete '/api/sponsorships/100.json'}.to change(StoppedSponsorship, :count).by(1) + end + end + + context 'as developer' do + it 'success' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { developer_session } + expect{ delete '/api/sponsorships/100.json'}.to change(StoppedSponsorship, :count).by(1) + end + end + + context 'as others' do + it 'fail' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { visitor_session } + expect{ delete '/api/sponsorships/100.json'}.to change(StoppedSponsorship, :count).by(0) + end + end + end +end diff --git a/spec/requests/wallets_spec.rb b/spec/requests/wallets_spec.rb new file mode 100644 index 00000000..e34891c3 --- /dev/null +++ b/spec/requests/wallets_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' + +RSpec.describe 'Wallet', type: :request do + + let(:valid_session) { + { user_id: 6, www_user_id: 6 } + } + + describe 'GET /wallets/balance.json' do + it 'success' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + get '/api/wallets/balance.json', params: { id: 6 }, as: :json + expect(JSON.parse(response.body)['balance']).to eq(100) + end + end + + describe 'GET /wallets/coin_changes.json' do + context 'category all' do + it 'return 2 records' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + get '/api/wallets/coin_changes.json', params: { id: 6, category: 'all' }, as: :json + expect(JSON.parse(response.body)['coin_changes'].length).to eq(2) + # expect(JSON.parse(response.body)).to eq('') + end + end + + context 'category outcome' do + it 'return 1 outcome records' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + get '/api/wallets/coin_changes.json', params: { id: 6, category: 'outcome' }, as: :json + expect(JSON.parse(response.body)['coin_changes'][0]['amount']).to eq(5) + expect(JSON.parse(response.body)['coin_changes'].length).to eq(1) + end + end + + context 'category outcome' do + it 'return 1 income records' do + allow_any_instance_of(ActionDispatch::Request).to receive(:session) { valid_session } + get '/api/wallets/coin_changes.json', params: { id: 6, category: 'income' }, as: :json + expect(JSON.parse(response.body)['coin_changes'][0]['amount']).to eq(10) + expect(JSON.parse(response.body)['coin_changes'].length).to eq(1) + end + end + end + +end \ No newline at end of file diff --git a/spec/routing/courses_routing_spec.rb b/spec/routing/courses_routing_spec.rb deleted file mode 100644 index 91cfa28c..00000000 --- a/spec/routing/courses_routing_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require "rails_helper" - -RSpec.describe CoursesController, type: :routing do - describe "routing" do - it "routes to #index" do - expect(:get => "/courses").to route_to("courses#index") - end - - it "routes to #new" do - expect(:get => "/courses/new").to route_to("courses#new") - end - - it "routes to #show" do - expect(:get => "/courses/1").to route_to("courses#show", :id => "1") - end - - it "routes to #edit" do - expect(:get => "/courses/1/edit").to route_to("courses#edit", :id => "1") - end - - - it "routes to #create" do - expect(:post => "/courses").to route_to("courses#create") - end - - it "routes to #update via PUT" do - expect(:put => "/courses/1").to route_to("courses#update", :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "/courses/1").to route_to("courses#update", :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "/courses/1").to route_to("courses#destroy", :id => "1") - end - end -end diff --git a/spec/routing/log_routing_spec.rb b/spec/routing/log_routing_spec.rb new file mode 100644 index 00000000..550d21a3 --- /dev/null +++ b/spec/routing/log_routing_spec.rb @@ -0,0 +1,10 @@ +require "rails_helper" + +RSpec.describe LogController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/api/log/list").to route_to("log#list") + end + end +end + diff --git a/spec/routing/memos_routing_spec.rb b/spec/routing/memos_routing_spec.rb deleted file mode 100644 index 8e75e55d..00000000 --- a/spec/routing/memos_routing_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require "rails_helper" - -RSpec.describe MemosController, type: :routing do - describe "routing" do - it "routes to #index" do - expect(:get => "/memos").to route_to("memos#index") - end - - it "routes to #new" do - expect(:get => "/memos/new").to route_to("memos#new") - end - - it "routes to #show" do - expect(:get => "/memos/1").to route_to("memos#show", :id => "1") - end - - it "routes to #edit" do - expect(:get => "/memos/1/edit").to route_to("memos#edit", :id => "1") - end - - - it "routes to #create" do - expect(:post => "/memos").to route_to("memos#create") - end - - it "routes to #update via PUT" do - expect(:put => "/memos/1").to route_to("memos#update", :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "/memos/1").to route_to("memos#update", :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "/memos/1").to route_to("memos#destroy", :id => "1") - end - end -end diff --git a/spec/routing/sponsor_tiers_routing_spec.rb b/spec/routing/sponsor_tiers_routing_spec.rb new file mode 100644 index 00000000..7eb52ab2 --- /dev/null +++ b/spec/routing/sponsor_tiers_routing_spec.rb @@ -0,0 +1,36 @@ +require 'rails_helper' + +RSpec.describe SponsorTiersController, type: :routing do + + describe 'routing' do + it 'routes to #index' do + expect(get: '/api/sponsor_tiers.json').to route_to( + controller: 'sponsor_tiers', action: 'index', format: 'json') + end + + it 'routes to #show' do + expect(get: '/api/sponsor_tiers/1.json').to route_to( + controller: 'sponsor_tiers', action: 'show', format: 'json', id: '1') + end + + it 'routes to #create' do + expect(post: '/api/sponsor_tiers.json').to route_to( + controller: 'sponsor_tiers', action: 'create', format: 'json') + end + + it 'routes to #update via PUT' do + expect(put: '/api/sponsor_tiers/1.json').to route_to( + controller: 'sponsor_tiers', action: 'update', format: 'json', id: '1') + end + + it 'routes to #update via PATCH' do + expect(patch: '/api/sponsor_tiers/1.json').to route_to( + controller: 'sponsor_tiers', action: 'update', format: 'json', id: '1') + end + + it 'routes to #destroy' do + expect(delete: '/api/sponsor_tiers/1.json').to route_to( + controller: 'sponsor_tiers', action: 'destroy', format: 'json', id: '1') + end + end +end diff --git a/spec/routing/sponsorships_routing_spec.rb b/spec/routing/sponsorships_routing_spec.rb new file mode 100644 index 00000000..7bd2c77c --- /dev/null +++ b/spec/routing/sponsorships_routing_spec.rb @@ -0,0 +1,62 @@ +require 'rails_helper' + +RSpec.describe SponsorshipsController, type: :routing do + + describe 'routing' do + it 'routes to #index' do + # expect(:get => "/api/sponsorships.json").to route_to("sponsorships#index") + expect(get: '/api/sponsorships.json').to route_to( + controller: 'sponsorships', action: 'index', format: 'json') + end + + it 'routes to stopped' do + expect(get: '/api/sponsorships/stopped.json').to route_to( + controller: 'sponsorships', action: 'stopped', format: 'json') + end + + it 'routes to sponsoring' do + expect(get: '/api/sponsorships/sponsoring.json').to route_to( + controller: 'sponsorships', action: 'sponsoring', format: 'json') + end + + it 'routes to stopped_sponsoring' do + expect(get: '/api/sponsorships/stopped_sponsoring.json').to route_to( + controller: 'sponsorships', action: 'stopped_sponsoring', format: 'json') + end + + it 'routes to sponsored' do + expect(get: '/api/sponsorships/sponsored.json').to route_to( + controller: 'sponsorships', action: 'sponsored', format: 'json') + end + + it 'routes to stopped_sponsored' do + expect(get: '/api/sponsorships/stopped_sponsored.json').to route_to( + controller: 'sponsorships', action: 'stopped_sponsored', format: 'json') + end + + it 'routes to #show' do + expect(get: '/api/sponsorships/1.json').to route_to( + controller: 'sponsorships', action: 'show', id: "1", format: 'json') + end + + it 'routes to #create' do + expect(post: '/api/sponsorships.json').to route_to( + controller: 'sponsorships', action: 'create', format: 'json') + end + + it 'routes to #update via PUT' do + expect(put: '/api/sponsorships/1.json').to route_to( + controller: 'sponsorships', action: 'update', id: "1", format: 'json') + end + + it 'routes to #update via PATCH' do + expect(patch: '/api/sponsorships/1.json').to route_to( + controller: 'sponsorships', action: 'update', id: "1", format: 'json') + end + + it 'routes to #destroy' do + expect(delete: '/api/sponsorships/1.json').to route_to( + controller: 'sponsorships', action: 'destroy', id: "1", format: 'json') + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5d253b68..3f6d3951 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +require 'simplecov' +SimpleCov.start # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause this diff --git a/spec/views/courses/edit.html.erb_spec.rb b/spec/views/courses/edit.html.erb_spec.rb deleted file mode 100644 index b9445697..00000000 --- a/spec/views/courses/edit.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "courses/edit", type: :view do - before(:each) do - @course = assign(:course, Course.create!()) - end - - it "renders the edit course form" do - render - - assert_select "form[action=?][method=?]", course_path(@course), "post" do - end - end -end diff --git a/spec/views/courses/index.html.erb_spec.rb b/spec/views/courses/index.html.erb_spec.rb deleted file mode 100644 index e96d797f..00000000 --- a/spec/views/courses/index.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "courses/index", type: :view do - before(:each) do - assign(:courses, [ - Course.create!(), - Course.create!() - ]) - end - - it "renders a list of courses" do - render - end -end diff --git a/spec/views/courses/new.html.erb_spec.rb b/spec/views/courses/new.html.erb_spec.rb deleted file mode 100644 index de6caf7f..00000000 --- a/spec/views/courses/new.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "courses/new", type: :view do - before(:each) do - assign(:course, Course.new()) - end - - it "renders new course form" do - render - - assert_select "form[action=?][method=?]", courses_path, "post" do - end - end -end diff --git a/spec/views/courses/show.html.erb_spec.rb b/spec/views/courses/show.html.erb_spec.rb deleted file mode 100644 index 775410b5..00000000 --- a/spec/views/courses/show.html.erb_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -RSpec.describe "courses/show", type: :view do - before(:each) do - @course = assign(:course, Course.create!()) - end - - it "renders attributes in

" do - render - end -end diff --git a/spec/views/edu_settings/edit.html.erb_spec.rb b/spec/views/edu_settings/edit.html.erb_spec.rb deleted file mode 100644 index 3767834b..00000000 --- a/spec/views/edu_settings/edit.html.erb_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - -RSpec.describe "edu_settings/edit", type: :view do - before(:each) do - @edu_setting = assign(:edu_setting, EduSetting.create!( - :name => "MyString", - :value => "MyString" - )) - end - - it "renders the edit edu_setting form" do - render - - assert_select "form[action=?][method=?]", edu_setting_path(@edu_setting), "post" do - - assert_select "input[name=?]", "edu_setting[name]" - - assert_select "input[name=?]", "edu_setting[value]" - end - end -end diff --git a/spec/views/edu_settings/index.html.erb_spec.rb b/spec/views/edu_settings/index.html.erb_spec.rb deleted file mode 100644 index 21b5a1f5..00000000 --- a/spec/views/edu_settings/index.html.erb_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'rails_helper' - -RSpec.describe "edu_settings/index", type: :view do - before(:each) do - assign(:edu_settings, [ - EduSetting.create!( - :name => "Name", - :value => "Value" - ), - EduSetting.create!( - :name => "Name", - :value => "Value" - ) - ]) - end - - it "renders a list of edu_settings" do - render - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => "Value".to_s, :count => 2 - end -end diff --git a/spec/views/edu_settings/new.html.erb_spec.rb b/spec/views/edu_settings/new.html.erb_spec.rb deleted file mode 100644 index cc307763..00000000 --- a/spec/views/edu_settings/new.html.erb_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - -RSpec.describe "edu_settings/new", type: :view do - before(:each) do - assign(:edu_setting, EduSetting.new( - :name => "MyString", - :value => "MyString" - )) - end - - it "renders new edu_setting form" do - render - - assert_select "form[action=?][method=?]", edu_settings_path, "post" do - - assert_select "input[name=?]", "edu_setting[name]" - - assert_select "input[name=?]", "edu_setting[value]" - end - end -end diff --git a/spec/views/memos/edit.html.erb_spec.rb b/spec/views/memos/edit.html.erb_spec.rb deleted file mode 100644 index 969d70eb..00000000 --- a/spec/views/memos/edit.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "memos/edit", type: :view do - before(:each) do - @memo = assign(:memo, Memo.create!()) - end - - it "renders the edit memo form" do - render - - assert_select "form[action=?][method=?]", memo_path(@memo), "post" do - end - end -end diff --git a/spec/views/memos/index.html.erb_spec.rb b/spec/views/memos/index.html.erb_spec.rb deleted file mode 100644 index 226a635d..00000000 --- a/spec/views/memos/index.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "memos/index", type: :view do - before(:each) do - assign(:memos, [ - Memo.create!(), - Memo.create!() - ]) - end - - it "renders a list of memos" do - render - end -end diff --git a/spec/views/memos/new.html.erb_spec.rb b/spec/views/memos/new.html.erb_spec.rb deleted file mode 100644 index bf02ae98..00000000 --- a/spec/views/memos/new.html.erb_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe "memos/new", type: :view do - before(:each) do - assign(:memo, Memo.new()) - end - - it "renders new memo form" do - render - - assert_select "form[action=?][method=?]", memos_path, "post" do - end - end -end diff --git a/spec/views/memos/show.html.erb_spec.rb b/spec/views/memos/show.html.erb_spec.rb deleted file mode 100644 index 0a3a0193..00000000 --- a/spec/views/memos/show.html.erb_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -RSpec.describe "memos/show", type: :view do - before(:each) do - @memo = assign(:memo, Memo.create!()) - end - - it "renders attributes in

" do - render - end -end