Sha256: 2ede6c6e5350ef78695b7abce1b6e37f0a588bc52fa2e96a57fd66d07c30a04d

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

class WelcomeController < ApplicationController
  def index
    render json: {}
  end

  def show
    render json: {keys: extract_keys, fakeKey: true, fake_key: false}
  end

  def ignore
    render json: {keys: extract_keys, camelCase: false, snake_case: true}
  end

  def non_json_text_response
    render text: "----- BEGIN PUBLIC KEY -----\n#{extract_keys}\n----- END PUBLIC KEY -----"
  end

  def non_json_binary_response
    file = File.join(Rails.root, 'app', 'assets', 'images', 'grumpy-cat.gif')

    send_file(file, filename: "#{params}.gif")
  end

  def posts
    render json: {keys: extract_keys}
  end

  def array_of_elements
    render json:  [
                    {fake_key: "foo"},
                    {fake_key: "bar"}
                  ]
  end

  def upcase_first_name
    name = params[:user_options][:first_name]
    params[:user_options][:first_name] = name.upcase

    render json: params
  end

  private
  def extract_keys
    not_acceptable_keys = %w(controller format default action welcome)
    params.reduce([]) do |result, (key, value)|
      unless key.in?(not_acceptable_keys)
        result << key
        if value.is_a?(Hash)
          result << value.keys
        end
      end
      result
    end.flatten
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cp-sparrow-0.0.16 spec/integration/apps/rails_app/app/controllers/welcome_controller.rb
cp-sparrow-0.0.15 spec/integration/apps/rails_app/app/controllers/welcome_controller.rb