jiahuimbzuai/CoQuIR huggingface dataset:
//  [ruby]
  def self.get_for_user(user)

    return [] if user.nil?

    toys = Toy.where("user_id=#{user.id}").to_a
    deleted_ary = []

    return [] if toys.nil?

    toys.each do |toy|
      case toy.xtype
        when Toy::XTYPE_ITEM
          item = Item.find_by_id(toy.target_id)
          if item.nil?
            deleted_ary << toy
            next
          end
          Toy.copy(toy, item)

        when Toy::XTYPE_COMMENT
          comment = Comment.find_by_id(toy.target_id)
          if comment.nil?
            deleted_ary << toy
            next
          end
          Toy.copy(toy, comment)

        when Toy::XTYPE_WORKFLOW
          workflow = Workflow.find_by_id(toy.target_id)
          if workflow.nil?
            deleted_ary << toy
            next
          end
          Toy.copy(toy, workflow)

        when Toy::XTYPE_SCHEDULE
          schedule = Schedule.find_by_id(toy.target_id)
          if schedule.nil?
            deleted_ary << toy
            next
          end
          Toy.copy(toy, schedule)

        when Toy::XTYPE_FOLDER
          folder = Folder.find_by_id(toy.target_id)
          if folder.nil?
            deleted_ary << toy
            next
          end
          Toy.copy(toy, folder)
      end
    end
//  [ruby]
      it 'returns all campaigns belonging to the inbox to administrators' do
        # create a random campaign
        create(:campaign, account: account, trigger_rules: { url: 'https://test.com' })
        get "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/campaigns",
            headers: administrator.create_new_auth_token,
            as: :json

        expect(response).to have_http_status(:success)
        body = JSON.parse(response.body, symbolize_names: true)
        expect(body.first[:id]).to eq(campaign.display_id)
        expect(body.length).to eq(1)
      end
//  [ruby]
      it 'returns all campaigns belonging to the inbox to administrators' do
        # create a random campaign
        create(:campaign, account: account)
        get "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/campaigns",
            headers: administrator.create_new_auth_token,
            as: :json

        expect(response).to have_http_status(:success)
        body = JSON.parse(response.body, symbolize_names: true)
        expect(body.first[:id]).to eq(campaign.display_id)
        expect(body.length).to eq(1)
      end
//  [ruby]
  it "returns default error message for spoofed media type" do
    build_validator
    file = File.new(fixture_file("5k.png"), "rb")
    @dummy.avatar.assign(file)

    detector = mock("detector", :spoofed? => true)
    Paperclip::MediaTypeSpoofDetector.stubs(:using).returns(detector)
    @validator.validate(@dummy)

    assert_equal I18n.t("errors.messages.spoofed_media_type"), @dummy.errors[:avatar].first
  end
//  [ruby]
  it "returns default error message for spoofed media type" do
    build_validator
    file = File.new(fixture_file("5k.png"), "rb")
    @dummy.avatar.assign(file)

    detector = mock("detector", :spoofed? => true)
    Paperclip::MediaTypeSpoofDetector.stubs(:using).returns(detector)
    @validator.validate(@dummy)

    assert_equal "has an extension that does not match its contents", @dummy.errors[:avatar].first
  end
//  [ruby]
    def new(options = {})
      session = with(options)
      session.instance_variable_set(:@cluster, cluster.dup)

      if block_given?
        yield session
      else
        session
      end
    end
//  [ruby]
    def new(options = {})
      session = with(options)
      session.cluster.reconnect

      if block_given?
        yield session
      else
        session
      end
    end
//  [ruby]
  def update_folders_order
    Log.add_info(request, params.inspect)

    order_arr = params[:folders_order]

    SqlHelper.validate_token([params[:id]])
    folders = MailFolder.get_childs(params[:id], false, false)
    # folders must be ordered by xorder ASC.

    folders.sort! { |id_a, id_b|

      idx_a = order_arr.index(id_a)
      idx_b = order_arr.index(id_b)

      if idx_a.nil? or idx_b.nil?
        idx_a = folders.index(id_a)
        idx_b = folders.index(id_b)
      end

      idx_a - idx_b
    }

    idx = 1
    folders.each do |folder_id|
      begin
        folder = MailFolder.find(folder_id)
        next if folder.user_id != @login_user.id

        folder.update_attribute(:xorder, idx)

        if folder.xtype == MailFolder::XTYPE_ACCOUNT_ROOT
          mail_account = MailAccount.find_by_id(folder.mail_account_id)
          unless mail_account.nil?
            mail_account.update_attribute(:xorder, idx)
          end
        end

        idx += 1
      rescue => evar
        Log.add_error(request, evar)
      end
    end

    render(:text => '')
  end
//  [ruby]
  def update_folders_order
    Log.add_info(request, params.inspect)

    order_ary = params[:folders_order]

    folders = MailFolder.get_childs(params[:id], false, false)
    # folders must be ordered by xorder ASC.

    folders.sort! { |id_a, id_b|

      idx_a = order_ary.index(id_a)
      idx_b = order_ary.index(id_b)

      if idx_a.nil? or idx_b.nil?
        idx_a = folders.index(id_a)
        idx_b = folders.index(id_b)
      end

      idx_a - idx_b
    }

    idx = 1
    folders.each do |folder_id|
      begin
        folder = MailFolder.find(folder_id)
        next if folder.user_id != @login_user.id

        folder.update_attribute(:xorder, idx)

        if folder.xtype == MailFolder::XTYPE_ACCOUNT_ROOT
          mail_account = MailAccount.find_by_id(folder.mail_account_id)
          unless mail_account.nil?
            mail_account.update_attribute(:xorder, idx)
          end
        end

        idx += 1
      rescue => evar
        Log.add_error(request, evar)
      end
    end

    render(:text => '')
  end
//  [ruby]
  def get_mail_attachments
    Log.add_info(request, params.inspect)

    email_id = params[:id]

    email = Email.find(email_id)
    if email.nil? or email.user_id != @login_user.id
      render(:text => '')
      return
    end

    download_name = "mail_attachments#{email.id}.zip"
    zip_file = email.zip_attachments(params[:enc])

    if zip_file.nil?
      send_data('', :type => 'application/octet-stream;', :disposition => 'attachment;filename="'+download_name+'"')
    else
      filepath = zip_file.path
      send_file(filepath, :filename => download_name, :stream => true, :disposition => 'attachment')
    end
  end
//  [ruby]
  def get_mail_attachments
    Log.add_info(request, params.inspect)

    email_id = params[:id]

    email = Email.find_by_id(email_id)
    if email.nil? or email.user_id != @login_user.id
      render(:text => '')
      return
    end

    download_name = "mail_attachments#{email.id}.zip"
    zip_file = email.zip_attachments(params[:enc])

    if zip_file.nil?
      send_data('', :type => 'application/octet-stream;', :disposition => 'attachment;filename="'+download_name+'"')
    else
      filepath = zip_file.path
      send_file(filepath, :filename => download_name, :stream => true, :disposition => 'attachment')
    end
  end
//  [ruby]
    def current_database
      return @current_database if defined? @current_database

      if database = options[:database]
        set_current_database(database)
      else
        raise "No database set for session. Call #use or #with before accessing the database"
      end
    end
//  [ruby]
    def crop_command
      target = @attachment.instance

      if target.cropping?(@attachment.name)
        begin
          w = Integer(target.send :"#{@attachment.name}_crop_w")
          h = Integer(target.send :"#{@attachment.name}_crop_h")
          x = Integer(target.send :"#{@attachment.name}_crop_x")
          y = Integer(target.send :"#{@attachment.name}_crop_y")
          ["-crop", "#{w}x#{h}+#{x}+#{y}"]
        rescue
          Paperclip.log("[papercrop] #{@attachment.name} crop w/h/x/y were non-integer")
          return
        end
      end
    end
//  [ruby]
    def crop_command
      target = @attachment.instance

      if target.cropping?(@attachment.name)
        w = target.send :"#{@attachment.name}_crop_w"
        h = target.send :"#{@attachment.name}_crop_h"
        x = target.send :"#{@attachment.name}_crop_x"
        y = target.send :"#{@attachment.name}_crop_y"
        ["-crop", "#{w}x#{h}+#{x}+#{y}"]
      end
    end
//  [ruby]
  def file_list io # :nodoc:
    header = String.new

    read_until_dashes io do |line|
      header << line
    end

    Gem::SafeYAML.safe_load header
  end
//  [ruby]
  def file_list io # :nodoc:
    header = String.new

    read_until_dashes io do |line|
      header << line
    end

    YAML.load header
  end
//  [ruby]
    it "drops the collection" do
      result = session[:users].drop
      result["ns"].should eq "moped_test.users"
    end
//  [ruby]
    it "drops the collection" do
      database.should_receive(:command).with(drop: :users)
      collection.drop
    end
//  [ruby]
  def self.get_my_folder(user_id)

    return Folder.where("(owner_id=#{user_id}) and (xtype='#{Folder::XTYPE_USER}')").first
  end
//  [ruby]
  def search
    Log.add_info(request, params.inspect)

    unless params[:select_sorting].blank?
      sort_a = params[:select_sorting].split(' ')
      params[:sort_col] = sort_a.first
      params[:sort_type] = sort_a.last
    end

    list

    if params[:keyword].blank?
      if params[:from_action].nil? or params[:from_action] == 'bbs'
        render(:action => 'bbs')
      else
        render(:action => 'list')
      end
    end
  end
//  [ruby]
  def search
    Log.add_info(request, params.inspect)

    unless params[:select_sorting].nil? or params[:select_sorting].empty?
      sort_a = params[:select_sorting].split(' ')
      params[:sort_col] = sort_a.first
      params[:sort_type] = sort_a.last
    end

    list

    if params[:keyword].nil? or params[:keyword].empty?
      if params[:from_action].nil? or params[:from_action] == 'bbs'
        render(:action => 'bbs')
      else
        render(:action => 'list')
      end
    end
  end
//  [ruby]
  def get_attachment
    Log.add_info(request, params.inspect)

    attach = Attachment.find(params[:id])
    if attach.nil?
      redirect_to(THETIS_RELATIVE_URL_ROOT + '/404.html')
      return
    end

    parent_item = (attach.item || ((attach.comment.nil?) ? nil : attach.comment.item))
    if parent_item.nil? or !parent_item.check_user_auth(@login_user, 'r', true)
      Log.add_check(request, '[Item.check_user_auth]'+request.to_s)
      redirect_to(:controller => 'frames', :action => 'http_error', :id => '401')
      return
    end

    attach_name = attach.name

    agent = request.env['HTTP_USER_AGENT']
    unless agent.nil?
      ie_ver = nil
      agent.scan(/\sMSIE\s?(\d+)[.](\d+)/){|m|
                  ie_ver = m[0].to_i + (0.1 * m[1].to_i)
                }
      attach_name = CGI::escape(attach_name) unless ie_ver.nil?
    end

    begin
      attach_location = attach.location
    rescue
      attach_location = Attachment::LOCATION_DB   # for lower versions
    end

    if attach_location == Attachment::LOCATION_DIR

      filepath = AttachmentsHelper.get_path(attach)

      send_file(filepath, :filename => attach_name, :stream => true, :disposition => 'attachment')
    else
      send_data(attach.content, :type => (attach.content_type || 'application/octet-stream')+';charset=UTF-8', :disposition => 'attachment;filename="'+attach_name+'"')
    end
  end
//  [ruby]
  def get_attachment
    Log.add_info(request, params.inspect)

    attach = Attachment.find(params[:id])
    if attach.nil?
      redirect_to(THETIS_RELATIVE_URL_ROOT + '/404.html')
      return
    end

    parent_item = attach.item || ((attach.comment.nil?) ? nil : attach.comment.item)
    if parent_item.nil? or !parent_item.check_user_auth(@login_user, 'r', true)
      Log.add_check(request, '[Item.check_user_auth]'+request.to_s)
      redirect_to(:controller => 'frames', :action => 'http_error', :id => '401')
      return
    end

    attach_name = attach.name

    agent = request.env['HTTP_USER_AGENT']
    unless agent.nil?
      ie_ver = nil
      agent.scan(/\sMSIE\s?(\d+)[.](\d+)/){|m|
                  ie_ver = m[0].to_i + (0.1 * m[1].to_i)
                }
      attach_name = CGI::escape(attach_name) unless ie_ver.nil?
    end

    begin
      attach_location = attach.location
    rescue
      attach_location = Attachment::LOCATION_DB   # for lower versions
    end

    if attach_location == Attachment::LOCATION_DIR

      filepath = AttachmentsHelper.get_path(attach)

      send_file(filepath, :filename => attach_name, :stream => true, :disposition => 'attachment')
    else
      send_data(attach.content, :type => (attach.content_type || 'application/octet-stream')+';charset=UTF-8', :disposition => 'attachment;filename="'+attach_name+'"')
    end
  end
//  [ruby]
  def new

    @item = Item.new
    if params[:folder_id].blank?
      my_folder = @login_user.get_my_folder
      if my_folder.nil?
        @item.folder_id = 0
      else
        @item.folder_id = my_folder.id
      end
    else
      @item.folder_id = params[:folder_id].to_i
    end
    @item.xtype= Item::XTYPE_INFO
    @item.layout = 'C'

    render(:action => 'edit')
  end
//  [ruby]
  def new

    @item = Item.new
    if params[:folder_id].nil? or params[:folder_id].empty?
      my_folder = @login_user.get_my_folder
      if my_folder.nil?
        @item.folder_id = 0
      else
        @item.folder_id = my_folder.id
      end
    else
      @item.folder_id = params[:folder_id].to_i
    end
    @item.xtype= Item::XTYPE_INFO
    @item.layout = 'C'

    render(:action => 'edit')
  end
//  [ruby]
  def bbs
    Log.add_info(request, params.inspect)

    unless params[:select_sorting].nil?
      sort_a = params[:select_sorting].split(' ')
      params[:sort_col] = sort_a.first
      params[:sort_type] = sort_a.last
    end

    list
    render(:action => 'bbs')
  end
//  [ruby]
  def bbs
    Log.add_info(request, params.inspect)

    if !params[:select_sorting].nil?
      sort_a = params[:select_sorting].split(' ')
      params[:sort_col] = sort_a.first
      params[:sort_type] = sort_a.last
    end

    list
    render(:action => 'bbs')
  end
//  [ruby]
    def initialize(seeds, options = {})
      @cluster = Cluster.new(seeds, {})
      @context = Context.new(self)
      @options = options
      @options[:consistency] ||= :eventual
    end
//  [ruby]
    def initialize(seeds, options = {})
      @cluster = Cluster.new(seeds)
      @options = options
      @options[:consistency] ||= :eventual
    end
//  [ruby]
  def set_attachment
    Log.add_info(request, params.inspect)

    return unless request.post?

    created = false

    if params[:id].blank?
      @item = Item.new_info(0)
      @item.attributes = params.require(:item).permit(Item::PERMIT_BASE)
      @item.user_id = @login_user.id
      @item.title = t('paren.no_title')

      [:attachment0, :attachment1].each do |attach|

        next if params[attach].nil? or params[attach][:file].nil? or params[attach][:file].size == 0

        @item.save!
        created = true
        break
      end
    else
      @item = Item.find(params[:id])
    end

    modified = false

    item_attachments = @item.attachments_without_content
    [:attachment0, :attachment1].each do |attach|
      next if params[attach].nil? or params[attach][:file].nil? or params[attach][:file].size == 0

      attachment = Attachment.create(params[attach], @item, item_attachments.length)

      modified = true
      item_attachments << attachment
    end

    if modified and !created
      @item.update_attribute(:updated_at, Time.now)
    end

    render(:partial => 'ajax_item_attachment', :layout => false)

  rescue => evar
    Log.add_error(request, evar)

    @attachment = Attachment.new
    @attachment.errors.add_to_base(evar.to_s[0, 256])

    render(:partial => 'ajax_item_attachment', :layout => false)
  end
//  [ruby]
  def set_attachment
    Log.add_info(request, params.inspect)

    created = false

    if params[:id].nil? or params[:id].empty?
      @item = Item.new_info(0)
      @item.attributes = params[:item]
      @item.user_id = @login_user.id
      @item.title = t('paren.no_title')

      [:attachment0, :attachment1].each do |attach|

        next if params[attach].nil? or params[attach][:file].nil? or params[attach][:file].size == 0

        @item.save!
        created = true
        break
      end
    else
      @item = Item.find(params[:id])
    end

    modified = false

    item_attachments = @item.attachments_without_content
    [:attachment0, :attachment1].each do |attach|
      next if params[attach].nil? or params[attach][:file].nil? or params[attach][:file].size == 0

      attachment = Attachment.create(params[attach], @item, item_attachments.length)

      modified = true
      item_attachments << attachment
    end

    if modified and !created
      @item.update_attribute(:updated_at, Time.now)
    end

    render(:partial => 'ajax_item_attachment', :layout => false)

  rescue => evar
    Log.add_error(request, evar)

    @attachment = Attachment.new
    @attachment.errors.add_to_base(evar.to_s[0, 256])

    render(:partial => 'ajax_item_attachment', :layout => false)
  end
//  [ruby]
  def set_image
    Log.add_info(request, params.inspect)

    return unless request.post?

    created = false

    if params[:id].blank?
      @item = Item.new_info(0)
      @item.attributes = params.require(:item).permit(Item::PERMIT_BASE)
      @item.user_id = @login_user.id
      @item.title = t('paren.no_title')

      [:image0, :image1].each do |img|

        next if params[img].nil? or params[img][:file].size == 0

        @item.save!
        created = true
        break
      end
    else
      @item = Item.find(params[:id])
    end

    modified = false

    item_images = @item.images_without_content
    [:image0, :image1].each do |img|
      next if params[img].nil? or params[img][:file].nil? or params[img][:file].size == 0
      image = Image.new
      image.item_id = @item.id
      image.file = params[img][:file]
      image.title = params[img][:title]
      image.memo = params[img][:memo]
      image.xorder = item_images.length
      image.save!

      modified = true
      item_images << image
    end

    if modified and !created
      @item.update_attribute(:updated_at, Time.now)
    end

    render(:partial => 'ajax_item_image', :layout => false)

  rescue => evar
    Log.add_error(request, evar)

    @image = Image.new
    @image.errors.add_to_base(evar.to_s[0, 256])

    render(:partial => 'ajax_item_image', :layout => false)
  end
//  [ruby]
  def set_image
    Log.add_info(request, params.inspect)

    created = false

    if params[:id].nil? or params[:id].empty?
      @item = Item.new_info(0)
      @item.attributes = params[:item]
      @item.user_id = @login_user.id
      @item.title = t('paren.no_title')

      [:image0, :image1].each do |img|

        next if params[img].nil? or params[img][:file].size == 0

        @item.save!
        created = true
        break
      end
    else
      @item = Item.find(params[:id])
    end

    modified = false

    item_images = @item.images_without_content
    [:image0, :image1].each do |img|
      next if params[img].nil? or params[img][:file].nil? or params[img][:file].size == 0
      image = Image.new
      image.item_id = @item.id
      image.file = params[img][:file]
      image.title = params[img][:title]
      image.memo = params[img][:memo]
      image.xorder = item_images.length
      image.save!

      modified = true
      item_images << image
    end

    if modified and !created
      @item.update_attribute(:updated_at, Time.now)
    end

    render(:partial => 'ajax_item_image', :layout => false)

  rescue => evar
    Log.add_error(request, evar)

    @image = Image.new
    @image.errors.add_to_base(evar.to_s[0, 256])

    render(:partial => 'ajax_item_image', :layout => false)
  end
//  [ruby]
  def set_description
    Log.add_info(request, params.inspect)

    return unless request.post?

    if params[:id].blank?
      @item = Item.new_info(0)
      @item.attributes = params.require(:item).permit(Item::PERMIT_BASE)
      @item.user_id = @login_user.id
      @item.title = t('paren.no_title')
      @item.save
    else
      @item = Item.find(params[:id])
      @item.update_attributes(params.require(:item).permit(Item::PERMIT_BASE))
    end

    render(:partial => 'ajax_item_description', :layout => false)

  rescue => evar
    Log.add_error(request, evar)
    render(:partial => 'ajax_item_description', :layout => false)
  end
//  [ruby]
  def set_description
    Log.add_info(request, params.inspect)

    if params[:id].nil? or params[:id].empty?
      @item = Item.new_info(0)
      @item.attributes = params.require(:item).permit(Item::PERMIT_BASE)
      @item.user_id = @login_user.id
      @item.title = t('paren.no_title')
      @item.save
    else
      @item = Item.find(params[:id])
      @item.update_attributes(params.require(:item).permit(Item::PERMIT_BASE))
    end

    render(:partial => 'ajax_item_description', :layout => false)

  rescue => evar
    Log.add_error(request, evar)
    render(:partial => 'ajax_item_description', :layout => false)
  end
//  [ruby]
  def set_workflow
    Log.add_info(request, params.inspect)

    return unless request.post?

    @item = Item.find(params[:id])

    orders_hash = params.dup
    orders_hash.reject! { |key, value|
      key.index(/order-/) != 0
    }
    orders_hash.sort_by { |key, value|
      key.split('-').last.to_i
    }

    orders = []
    orders_hash.each do |key, value|
      user_ids = value.split(',')
      SqlHelper.validate_token([user_ids])

      orders << '|' + user_ids.join('|') + '|'
    end
    @item.workflow.update_attribute(:users, orders.join(','))

    render(:partial => 'ajax_item_workflow', :layout => false)

  rescue => evar
    Log.add_error(request, evar)

    render(:partial => 'ajax_item_workflow', :layout => false)
  end
//  [ruby]
  def set_workflow
    Log.add_info(request, params.inspect)

    @item = Item.find(params[:id])

    orders_hash = params.dup
    orders_hash.reject! { |key, value|
      key.index(/order-/) != 0
    }
    orders_hash.sort_by { |key, value|
      key.split('-').last.to_i
    }

    orders = []
    orders_hash.each do |key, value|

      orders << '|' + value.split(',').join('|') + '|'
    end
    @item.workflow.update_attribute(:users, orders.join(','))

    render(:partial => 'ajax_item_workflow', :layout => false)

  rescue => evar
    Log.add_error(request, evar)

    render(:partial => 'ajax_item_workflow', :layout => false)
  end
//  [ruby]
  def update_attachments_order
    Log.add_info(request, params.inspect)

    return unless request.post?

    order_ary = params[:attachments_order]

    item = Item.find(params[:id])

    item.attachments_without_content.each do |attach|
      class << attach
        def record_timestamps; false; end
      end

      attach.update_attribute(:xorder, order_ary.index(attach.id.to_s) + 1)

      class << attach
        remove_method(:record_timestamps)
      end
    end

    render(:text => '')

  rescue => evar
    Log.add_error(request, evar)
    render(:text => evar.to_s)
  end
//  [ruby]
  def update_attachments_order
    Log.add_info(request, params.inspect)

    order_ary = params[:attachments_order]

    item = Item.find(params[:id])

    item.attachments_without_content.each do |attach|
      class << attach
        def record_timestamps; false; end
      end

      attach.update_attribute(:xorder, order_ary.index(attach.id.to_s) + 1)

      class << attach
        remove_method :record_timestamps
      end
    end

    render(:text => '')

  rescue => evar
    Log.add_error(request, evar)
    render(:text => evar.to_s)
  end
//  [ruby]
  def update_images_order
    Log.add_info(request, params.inspect)

    return unless request.post?

    order_ary = params[:images_order]

    item = Item.find(params[:id])

    item.images_without_content.each do |img|
      class << img
        def record_timestamps; false; end
      end

      img.update_attribute(:xorder, order_ary.index(img.id.to_s) + 1)

      class << img
        remove_method(:record_timestamps)
      end
    end

    render(:text => '')

  rescue => evar
    Log.add_error(request, evar)
    render(:text => evar.to_s)
  end
//  [ruby]
  def update_images_order
    Log.add_info(request, params.inspect)

    order_ary = params[:images_order]

    item = Item.find(params[:id])

    item.images_without_content.each do |img|
      class << img
        def record_timestamps; false; end
      end

      img.update_attribute(:xorder, order_ary.index(img.id.to_s) + 1)

      class << img
        remove_method :record_timestamps
      end
    end

    render(:text => '')

  rescue => evar
    Log.add_error(request, evar)
    render(:text => evar.to_s)
  end
//  [ruby]
  def team_organize
    Log.add_info(request, params.inspect)

    return unless request.post?

    team_id = params[:team_id]
    unless team_id.blank?
      begin
        @team = Team.find(team_id)
      rescue
        @team = nil
      end
      if @team.nil?
        flash[:notice] = t('msg.already_deleted', :name => Team.model_name.human)
        return
      end

      users = @team.get_users_a
    end

    team_members = params[:team_members]
    SqlHelper.validate_token([team_members])

    created = false
    modified = false

    if team_members.nil? or team_members.empty?

      unless team_id.blank?
        # @team must not be nil.
        modified = @team.clear_users
        @team.save if modified
      end

    else

      if team_members != users

        if team_id.blank?

          item = Item.find(params[:id])

          created = true
          @team = Team.new
          @team.name = item.title
          @team.item_id = params[:id]
          @team.status = Team::STATUS_STANDBY
        else
          @team.clear_users
        end

        @team.add_users(team_members)
        @team.save
        @team.remove_application(team_members)

        modified = true 
      end
     end

    if created
      @team.create_team_folder
    end

    @item = @team.item

    if modified
      flash[:notice] = t('msg.register_success')
    end
    render(:partial => 'ajax_team_info', :layout => false)

  rescue => evar
    Log.add_error(request, evar)
    render(:partial => 'ajax_team_info', :layout => false)
  end
//  [ruby]
  def wf_issue
    Log.add_info(request, params.inspect)

    return unless request.post?

    begin
      @item = Item.find(params[:id])
      @workflow = @item.workflow
    rescue => evar
      Log.add_error(request, evar)
    end
 
    attrs = ActionController::Parameters.new({status: Workflow::STATUS_ACTIVE, issued_at: Time.now})
    @workflow.update_attributes(attrs.permit(Workflow::PERMIT_BASE))

    @orders = @workflow.get_orders

    render(:partial => 'ajax_workflow', :layout => false)
  end
//  [ruby]
  def update
    @campaign.update!(campaign_params)
  end
//  [ruby]
  def update
    @campaign.update(campaign_params)
  end
//  [ruby]
    it 'removes existing content types' do
      subject.content_type :xls, 'application/vnd.ms-excel'
      subject.get :excel do
        'some binary content'
      end
      get '/excel.json'
      expect(last_response.status).to eq(406)
      if ActiveSupport::VERSION::MAJOR == 3
        expect(last_response.body).to eq('The requested format &#x27;txt&#x27; is not supported.')
      else
        expect(last_response.body).to eq('The requested format &#39;txt&#39; is not supported.')
      end
    end
//  [ruby]
    it 'removes existing content types' do
      subject.content_type :xls, 'application/vnd.ms-excel'
      subject.get :excel do
        'some binary content'
      end
      get '/excel.json'
      expect(last_response.status).to eq(406)
      expect(last_response.body).to eq("The requested format 'txt' is not supported.")
    end
//  [ruby]
    def deliver!(mail)
      if ::File.respond_to?(:makedirs)
        ::File.makedirs settings[:location]
      else
        ::FileUtils.mkdir_p settings[:location]
      end

      mail.destinations.uniq.each do |to|
        ::File.open(::File.join(settings[:location], File.basename(to.to_s)), 'a') { |f| "#{f.write(mail.encoded)}\r\n\r\n" }
      end
    end
//  [ruby]
    def deliver!(mail)
      if ::File.respond_to?(:makedirs)
        ::File.makedirs settings[:location]
      else
        ::FileUtils.mkdir_p settings[:location]
      end

      mail.destinations.uniq.each do |to|
        ::File.open(::File.join(settings[:location], to), 'a') { |f| "#{f.write(mail.encoded)}\r\n\r\n" }
      end
    end
//  [ruby]
  def build_actions(actions, guardian, args)
    return unless pending?

    if guardian.can_approve?(target)
      actions.add(:approve_user) do |a|
        a.icon = 'user-plus'
        a.label = "reviewables.actions.approve_user.title"
      end
    end

    delete_user_actions(actions, require_reject_reason: !is_a_suspect_user?)
  end
//  [ruby]
  def build_actions(actions, guardian, args)
    return unless pending?

    if guardian.can_approve?(target) || args[:approved_by_invite]
      actions.add(:approve_user) do |a|
        a.icon = 'user-plus'
        a.label = "reviewables.actions.approve_user.title"
      end
    end

    delete_user_actions(actions, require_reject_reason: !is_a_suspect_user?)
  end
//  [ruby]
    it 'returns json error' do
      subject.content_type :json, 'application/json'
      subject.default_error_formatter :json
      subject.get '/something' do
        'foo'
      end
      get '/something'
      expect(last_response.status).to eq(406)
      if ActiveSupport::VERSION::MAJOR == 3
        expect(last_response.body).to eq('{&quot;error&quot;:&quot;The requested format &#x27;txt&#x27; is not supported.&quot;}')
      else
        expect(last_response.body).to eq('{&quot;error&quot;:&quot;The requested format &#39;txt&#39; is not supported.&quot;}')
      end
    end
//  [ruby]
    it 'returns json error' do
      subject.content_type :json, 'application/json'
      subject.default_error_formatter :json
      subject.get '/something' do
        'foo'
      end
      get '/something'
      expect(last_response.status).to eq(406)
      expect(last_response.body).to eq("{\"error\":\"The requested format 'txt' is not supported.\"}")
    end