text stringlengths 10 2.61M |
|---|
class RenameVesselColumn < ActiveRecord::Migration
def self.up
rename_column :vessels, :vesel_type ,:vessel_type
end
def self.down
rename_column :vessels, :vessel_type ,:vesel_type
end
end
|
class Sieve
def initialize(num)
@num = num
end
def primes
divisor = 2
sieve_arr = [*2..@num]
while sieve_arr[divisor] do
sieve_arr.slice(divisor, sieve_arr.length).each do |el|
sieve_arr.delete(el) if el % divisor == 0
end
divisor += 1
end
sieve_arr
end
end
|
class MilkShake
def initialize(flavor, price)
@flavor = flavor
@price = price
end
end
milkshake = MilkShake.new("Chocolate",7)
class Ingredient
attr_reader :name, :price
def initialize(name, price)
@name = name
@price = price
end
end
banana = Ingredient.new("Banana",2)
class Milkshake
def initialize ... |
# frozen_string_literal: true
module TestProf
# Add ability to run only a specified number of example groups (randomly selected)
module RSpecSample
def ordered_example_groups
@example_groups = @example_groups.sample(ENV['SAMPLE'].to_i) unless ENV['SAMPLE'].nil?
super
end
end
end
RSpec::Core:... |
class Subscription < ActiveRecord::Base
self.table_name = 'subscriptions'
belongs_to :user
has_many :subscribedposts
def updatable_attributes
attributes.slice(*%w(id email topic_id))
end
end
|
class RemoveColumnsIdDay < ActiveRecord::Migration[5.0]
def change
def self.up
remove_column :days, :user_id
end
end
end
|
class TasksController < ApplicationController
before_action :set_task, only: [:show, :edit, :update, :favorite, :complete, :complete, :duplicate]
def index
end
def new
@task = current_user.tasks.new
end
def create
@task = current_user.tasks.new(task_params)
if @task.save
flash[:succ... |
# global methods acceable from any where in the application
module UsersHelper
def current_user
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
end
def logged_in?
!current_user.nil?
end
def require_user
return if logged_in?
flash[:danger] = 'you must be logged in t... |
require 'juego.rb'
RSpec.describe Juego do
it "inicializo el monto de nuestro balance en 0" do
banco = Banco.new()
expect(banco.setMonto(0)).to eq 0
end
it "Realizo un deposito de 100 pesos y devuelve 100 " do
banco = Banco.new()
deposito = 100
expect(banco.setDepos... |
class Dog < ActiveRecord::Base
SEXES = %w[Male Female]
# Associations
has_many :dog_people, dependent: :destroy
has_many :people, through: :dog_people
has_many :image_assets, class_name: "MediaAsset::ImageAsset", as: :media_assetable, dependent: :destroy
has_many :media_gallery_assets, class_name: "MediaAs... |
require './lib/person.rb'
require './lib/library.rb'
describe Person do
it 'every customer has a user_id and a pin_code' do
expect(subject.user_id).not_to be nil
expect(subject.pin_code).not_to be nil
end
it 'every customer has empty book list when created' do
expect(subject.read... |
module Roglew
module GL
SURFACE_MAPPED_NV ||= 0x8700
SURFACE_REGISTERED_NV ||= 0x86FD
SURFACE_STATE_NV ||= 0x86EB
WRITE_DISCARD_NV ||= 0x88BE
end
end
module GL_NV_vdpau_interop
module RenderHandle
include Roglew::RenderHandleExtension
functions [
[:glVDPAUFiniNV, []... |
module Backoffice
module V1
class CompaniesController < ::Backoffice::ApplicationController
include ActiveModel::Validations
respond_to :json, :jsonapi
before_action :load_company, except: %i[create index]
def index
companies = Company.all
show_response(companies, serializ... |
class Guide < ActiveRecord::Base
belongs_to :dosen
has_many :students
end
|
class AddAttributesToUsers < ActiveRecord::Migration
def change
add_column :users, :first_name, :string
add_column :users, :last_name, :string
add_column :users, :location, :string
add_column :users, :avatar, :string
add_column :users, :blurb, :text
add_column :users, :portfolio, :text
end
end
|
class ReaderUserNotebook < ActiveRecord::Base
require 'date'
def self.sort_list
notebook_obj = ReaderUserNotebook.find(1)
notebook_list_hash =Oj.load(notebook_obj.list)
book_id = ReaderUser.find(notebook_obj.user_id).book
book_word_hash = ReaderPageWord.book_word_frequency_statistics(book_id)
wo... |
require 'rspec'
require 'active_support'
require_relative '../lib/aa_questions'
RSpec.describe ModelBase do
describe '::find_by_id' do
it 'finds an object by id' do
expect(User.find_by_id(1)).to be_a(User)
end
end
describe '::all' do
user = User.find_by_id(1)
it 'returns all objects in ta... |
require 'spec_helper'
describe 'vagrant-friendly docker baseimages' do
PLATFORMS = {
ubuntu: ["12.04", "14.04", "16.04", "18.04"]
}
PLATFORMS.each_pair do |platform, versions|
versions.each do |version|
before(:all) do
@tempdir = Dir.mktmpdir
write_config @tempdir, vagrantfile_wi... |
require 'rails_helper'
RSpec.describe RecipesController, type: :controller do
describe '#index' do
context "as an authenticated user" do
before do
@user = create(:user)
@menu = create(:menu, user_id: @user.id)
@plate = create(:plate, user_id: @user.id, menu_id: @menu.id)
sig... |
require 'spec_helper'
describe BackpackTF::Interface do
describe '::defaults' do
after(:each) do
described_class.class_eval do
@format = 'json'
@callback = nil
@appid = '440'
end
end
it 'has these attributes & values by default' do
expect(described_class).to hav... |
require_relative '../monster_types/animal_monster.rb'
require_relative '../monster_types/humanoid_monster.rb'
require_relative '../monster_types/golems_monster.rb'
class MonsterTypeRandomizer
POSSIBLE_MONSTER_TYPE = [AnimalMonster, HumanoidMonster, GolemsMonster]
@instance = new
private_class_method :new
def... |
require 'test_helper'
class Admin::UserModelCreationTest < ActionDispatch::IntegrationTest
setup do
@admin = users(:admin)
log_in_as @admin
end
test 'unsuccessful user creation' do
get new_admin_user_path
assert_response :success
assert_template 'new'
assert_select 'form[action="/admin/u... |
class Category < ApplicationRecord
has_many :posts
validates :title,
presence: true,
length: {minimum: 2, message: "titre minimum 5 caracter"}
end
|
require_relative "./00_tree_node.rb"
class KnightPathFinder
attr_reader :pos
def initialize(pos)
@pos = pos
@root_node = PolyTreeNode.new(pos)
@considered_position = [pos]
end
def self.valid_moves(arr_pos)
arr = []
arr_pos.each do |pos|
if (pos... |
require 'clearwater'
require_relative './dsl'
module Bluesky
# A presentation `Component`
class PureComponent
# Example:
#
# class FooView < Bluesky::PureComponent
#
# attribute :times
#
# def render
# div([
# div("Clicked #{times}!"),
# form([
# ... |
namespace :mamashai do
desc "create gou logos "
task :create_gou_logos => [:environment] do
include MamashaiTools
def help
Helper.instance
end
class Helper
include Singleton
include ActionView::Helpers::TextHelper
include ApplicationHelper
end
i,count = 0,... |
class TopicsController < ApplicationController
before_filter :init_board
before_filter :protect_from_banned, only: :create
def index
@topics = Topic.with_replies.with_comment_replies.page(params[:page])
@new_topic = Topic.new
end
def show
@topic = Topic.find(params[:id])
@new_comment = Com... |
module QBIntegration
class Customer < Base
attr_reader :customers, :page_num, :new_page_number
def initialize(message = {}, config)
super
end
def get
now = Time.now.utc.iso8601
@customers, @new_page_number = customer_service.find_by_updated_at(page_number)
summary = "Retrieve... |
When(/^I fill in Company Name with "(.*?)"$/) do |arg1|
fill_in "name", :with => arg1
end |
# RSPEC SNIPPETS (DOES NOT INCLUDE CAPYBARA)
# Credit:: https://www.udemy.com/course/testing-ruby-with-rspec/
RSpec.describe 'change matcher' do
subject { [1, 2, 3] }
it 'checks that a method changes object state' do
# this version works but is inflexible
expect { subject.push(4) }.to change {... |
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe V1::BanksController, type: :controller do
before(:each) do
user = FactoryGirl.create(:user)
allow(controller).to receive(:authenticate_request).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end
descri... |
#!/usr/bin/rake
require 'pathname'
require 'shellwords'
## [ Constants ] ##############################################################
WORKSPACE = 'ModelGen'
SCHEME_NAME='modelgen'
CONFIGURATION = 'Release'
POD_NAME = 'ModelGen'
MIN_XCODE_VERSION = 9.0
BUILD_DIR = File.absolute_path('./build')
BIN_NAME = 'modelgen... |
# frozen_string_literal: true
RSpec.describe ItemPolicy do
include_context 'item migration'
include_context 'organization migration'
include_context 'store migration'
include_context 'user migration'
let!(:items_a) { create_list :item, 3, organization: organization_a }
let!(:items_b) { creat... |
Rails.application.routes.draw do
devise_for :users
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :questions, shallow: true do
resources :answers
end
root to: 'questions#index'
end
|
require 'rails_helper'
RSpec.feature 'Create a new expense' do
def login
login_as(create(:user))
end
scenario 'with valid data', js: true do
skip
category = create(:subcategory)
expense_attributes = {
'Description' => 'Jantar',
'Amount' => 100,
'Paid on' => Date.today
}
... |
require 'rails_helper_anywhere/version'
class Helper
# Makes all rails helper methods (including your custom helper methods) class methods.
#
# @example
# Helper.link_to('Home', '/') #=> '<a href="/">home page</a>'
# Helper.pins_path #=> '/pins'
# Helper.method_from_custom_helpers #=> 'return from cu... |
class OrganizationsController < CompanyController
add_breadcrumb 'На главную', '/', except: [:index, :show]
skip_before_action :find_organization, only: [:index, :new, :create]
before_action :redirect_if_not_owner, only: [:edit, :update]
before_action :need_to_login, only: [:new, :create]
def index
@act... |
class FacilitiesManagement::FurtherCompetitionSpreadsheetCreator < FacilitiesManagement::DeliverableMatrixSpreadsheetCreator
attr_accessor :session_data
def initialize(procurement_id)
@procurement = FacilitiesManagement::Procurement.find(procurement_id)
@report = FacilitiesManagement::SummaryReport.new(@pr... |
class MessagesController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show, :map_old_file]
before_filter :administrator!, :except => [:index, :show, :map_old_file]
# GET /messages
# GET /messages.xml
def index
if params[:date]
date = params[:date]
date += ... |
require './lib/supermarket'
require './lib/product'
require './lib/till'
describe Supermarket
describe '#initialize' do
it 'can generate a new supermarket with an empty inventory of stock' do
aldi = Supermarket.new
expect(aldi.stock).to be_a_kind_of(Array)
end
it 'can fill the supermarket ... |
class Dashboard::CoachUsersController < DashboardController
before_filter :check_if_user_is_stadium_user!
before_filter :find_coach, except: [ :index, :new, :create, :confirm ]
def index
@coaches = current_user.stadium.coaches.uniq
end
def new
@coach_user = CoachUser.new
@coach = @coach_user.bui... |
enclosure_type ||= article.audio.present? ? :audio : :image
xml.item do
xml.title article.title
xml.guid article.public_url
xml.link article.public_url
xml.dc :creator, article.byline
if enclosure_type == :image
if asset = article.assets.first
xml.enclosure url: asset.full.url, type: "image/jpe... |
class Comment < ActiveRecord::Base
# belongs_to :commentable, polymorphic: true
belongs_to :user
belongs_to :board
validates :content, presence: true
end
|
module DynamicRecord
class DynamicRecord < ActiveRecord::Base
#basically, it's exactly like a base only it allows
#rountripping back to the actual dynamic:record class
self.abstract_class = true
@columns = []
include Persistence
class << self
attr_accessor :record_class
delegate... |
require 'spec_helper'
describe Api::V1::ArtistsController do
describe 'with no artists' do
before :each do
Artist.delete_all
end
it 'creates an artist on create' do
expect {
make_request :post, '/artists', {:artist => (new_artist = FactoryGirl.build(:artist)).attributes}
res... |
require 'rails_helper'
describe "user can visit the welcome page" do
scenario "and see a dropdown menu" do
visit '/'
expect(page).to have_content("Nearest Fuel Station")
expect(page).to have_content("Search For The Nearest Electric Charging Station")
expect(page).to have_button("Find Nearest Station"... |
require 'csv'
class CsvHandler
attr_reader :data
def initialize(filename)
@data = CSV.open(filename, headers: true, header_converters: :symbol)
end
end |
class InfoUnzip < Package
name 'info-unzip'
desc 'UnZip is an extraction utility for archives compressed in .zip format'
homepage 'http://www.info-zip.org/UnZip.html'
url 'https://sourceforge.net/projects/infozip/files/UnZip%206.x%20%28latest%29/UnZip%20${version}/unzip${block}.tar.gz' do |r| r.version.split('... |
class ScoreSerializer < ActiveModel::Serializer
attributes :id, :user_id, :test_id, :value
end
|
class FontIbmPlexSans < Formula
head "https://github.com/google/fonts.git", verified: "github.com/google/fonts", branch: "main", only_path: "ofl/ibmplexsans"
desc "IBM Plex Sans"
homepage "https://fonts.google.com/specimen/IBM+Plex+Sans"
def install
(share/"fonts").install "IBMPlexSans-Bold.ttf"
(share/... |
class VenueActivity < ActiveRecord::Base
belongs_to :venue
belongs_to :activity
validates_uniqueness_of :venue_id, scope: :activity_id
end
|
require 'spec_helper'
describe FactoryGirl::Proxy::Build do
before do
@instance = stub("built-instance", :attribute => "value", :attribute= => nil, :owner= => nil)
@class = stub("class", :new => @instance)
@proxy = FactoryGirl::Proxy::Build.new(@class)
end
it "should instantiate the class" do
... |
class Hand
include Comparable
POKER_HANDS = [:pair,
:two_pair,
:trip,
:straight,
:flush,
:full_house,
:quad,
:straight_flush]
attr_reader :cards
def initialize(cards)
@cards = cards
... |
module Roglew
module GL
COUNTER_RANGE_AMD ||= 0x8BC1
COUNTER_TYPE_AMD ||= 0x8BC0
PERCENTAGE_AMD ||= 0x8BC3
PERFMON_RESULT_AMD ||= 0x8BC6
PERFMON_RESULT_AVAILABLE_AMD ||= 0x8BC4
PERFMON_RESULT_SIZE_AMD ||= 0x8BC5
UNSIGNED_INT64_AMD ... |
Spree::UserSessionsController.class_eval do
respond_to :js, :only => [:new, :create]
def create
authenticate_user!
if user_signed_in?
respond_to do |format|
format.html {
flash.notice = t(:logged_in_successfully)
redirect_back_or_default(products_path)
}
f... |
namespace :admin_user_management do
desc ''
task :add_user => :environment do
if AdminUser.all[0]
p '[ERROR] 既に管理ユーザーが作成されています。'
exit
end
unless ENV['ADMIN_EMAIL'] || ENV['ADMIN_PASSWORD']
p '[ERROR] 管理者ユーザー情報を環境変数に設定して下さい。(email or password)'
exit
end
user_params =... |
class Item < ActiveRecord::Base
belongs_to :user
belongs_to :address
accepts_nested_attributes_for :address, allow_destroy: true, reject_if: lambda{|address| address[:number_and_street].blank? }
has_many :images, as: :imageable, dependent: :destroy
accepts_nested_attributes_for :images, allow_destroy: true,... |
#
class HashMap
attr_reader :size, :table
def initialize(default_capacity = 11, default_load_factor = 0.9)
raise ArgumentError, 'Invalid load factor' if default_load_factor <= 0 ||
default_load_factor >= 1
@load_factor = default_load_factor
@table = Arr... |
class ChangedTaskChoicesRenamedTaskChoiceIdAndIndexedTaskInfoId < ActiveRecord::Migration
def self.up
rename_column :task_choices, :task_choice_id, :task_info_id
end
def self.down
rename_column :task_choices, :task_info_id, :task_choice_id
end
end
|
require 'spec_helper'
require 'fixtures_helper'
describe Irobot::TxtParser do
let(:goodbot) { 'goodbot' }
let(:badbot) { 'badbot' }
let(:paths) { ['', '/', '/foo', '/index.html'] }
let(:bots) { [goodbot, badbot] }
let(:parser) do
proc { |filename, path, ua| Irobot::TxtParser.new(robot_txt(filename), path... |
require './spec/helper'
require 'yaml'
# See also:
# - `configuration/default_configuration_spec.rb` for the specs of the
# configuration without a config file.
# - `configuration/configuration_file_spec.rb` for the specs of the
# configuration involving a config file.
# - `configuration/configuration_legacy_spec.... |
# -*- coding: utf-8 -*-
steps_for :shopping do
attr_accessor :items, :money
step "店に立ち寄った:" do |table|
self.items = {}
table.each do |line|
self.items[line[0]] = line[1].gsub(/G$/, "").to_i
end
end
step "所持金は :gold G" do |gold|
self.money = gold.to_i
end
step ":item は買える" do |item|... |
# frozen_string_literal: true
require 'bolt_spec/files'
require 'bolt/task'
module BoltSpec
module Task
class TaskTypeMatcher
def initialize(name, executable, input_method)
@name = name
@executable = Regexp.new(executable)
@input_method = input_method
end
def ===(other... |
#staff/senior/manager/parnter/admin/superuser
authorization do
role :guest do
has_permission_on :users, :to => [:read_index,:create,:read_show]
has_permission_on :personalcharges, :to =>[:get_ot]
end
# 需要创建一个hr角色, 管理client/staff/projects, 只能创建不能删除
role :staff do
includes :guest
has... |
class Admin::UsersController < ::ApplicationController
layout 'dashboard'
before_action :authenticate_admin_user!
before_action :load_user, only: [:verify, :show]
before_action :check_not_verified, only: :verify
before_action :check_user_details_complete, only: :verify
def index
@users = User.all.ord... |
class FeedbackSerializer < ActiveModel::Serializer
attributes :id, :project_name, :app_name, :app_comp, :feedback_title, :feedback_desc, :screenshot,:email
has_many :user
end
|
class Model::Domain::User
attr_accessor :username
attr_accessor :password
attr_accessor :email
def initialize
@username = ""
@password = ""
@email = ""
self
end
def set_username username
@username = username
end
def set_password password
@password = password
end
def set_e... |
FactoryGirl.define do
factory :lawyer_type do
name {Faker::Name.name}
end
end
|
class ApplicationMailer < ActionMailer::Base
default from: 'ClientComm <hello@clientcomm.org>'
layout 'mailer'
end
|
class Attendee < ActiveRecord::Base
belongs_to :event
belongs_to :user
before_save :find_facebook_id, :add_timestamps
validates_uniqueness_of :user_id, :scope => [:event_id]
# scope :current, lambda { where('created_at between ? and ?', Date.today, Date.today + 5.days) }
protected
def find_facebook... |
class AddRelHeroGrownLevels < ActiveRecord::Migration
def change
create_table :rel_hero_grown_levels do |t|
t.integer :hero_id, :null => false
t.integer :grown_level_master_id, :null => false
t.float :str, :null => false
t.float :int, :null => false
t.float :agi, :null => false
... |
class CurrenciesController < ApplicationController
before_action :set_user, only: %i[create destroy]
def create
@currency = @user.currencies.build(from: params[:from], to: params[:to], user_id: params[:user])
if @currency.save!
render json: @currency, status: :created
CurrencyCheckJob.perform_... |
class AddCategoriesToReviews < ActiveRecord::Migration
def change
add_column :reviews, :emotion, :string
add_column :reviews, :trust, :string
add_column :reviews, :values, :string
add_column :reviews, :manners, :string
add_column :reviews, :sexual_confidence, :string
add_column :reviews, :self... |
module Sensors
class El001 < Base
attributes :energy_minus, :energy_plus
display_as :line_chart, group_by: :minute, attributes: [:energy_minus, :energy_plus]
def payloadHexa
message.payloadHex.gsub(/../) { |pair| pair.hex.chr }
end
def energy_minus
@energy_minus ||= values.energy_mi... |
system "clear"
class Santa
attr_reader :age, :ethnicity
attr_accessor :gender
def initialize(gender, ethnicity)
@gender = gender
@ethnicity = ethnicity
@reindeer_ranking = ["Rudolph", "Dasher", "Dancer", "Prancer", "Vixen",
"Comet", "Cupid", "Donner", "Blitzen"]
print "Initializing Santa inst... |
require 'rails_helper'
RSpec.describe ListsController, type: :controller do
let(:my_list) { List.create!(title: "My List Title", body: "My list body") }
describe "GET #index" do
it "returns http success" do
get :index
expect(response).to have_http_status(:success)
end
end
describe "GET #n... |
describe "the signup process", :type => :feature do
before :each do
User.new(:email => 'user@example.com', :password => 'Test1234', :password_confirmation =>'Test1234')
end
it "signs me in" do
visit '/accounts/sign_in'
within("#session") do
fill_in ':email', :with => 'user@example.com'
fi... |
When /^I edit the affiliation$/ do
fill_in "Name", with: "University of Notre Dame"
click_button "commit"
end
When /^I create a new affiliation$/ do
fill_in "affiliation_name", with: @new_affiliation.name
fill_in "affiliation_social_info_attributes_twitter_name", with: @new_affiliation.social_info.... |
require 'rails_helper'
RSpec.describe Bargain, type: :model do
# associations
it { should belong_to(:album) }
it { should belong_to(:bargain_type) }
it { should belong_to(:city) }
it { should belong_to(:country) }
it { should belong_to(:currency) }
it { should belong_to(:medium_type) }
it { should belo... |
class Customers::PeopleController < ApplicationController
before_action :authenticate_customer!, except: [:show, :index]
def new
@person = Person.new
end
def index
@people = Person.order(:name_kana)
end
def search
@people = Person.search(params[:keyword]).order(:name_kana)
@keyword = params[:keyword]
... |
class User < ActiveRecord::Base
has_many :documents
def self.from_omniauth(auth)
user = where(google_id: auth.uid).first_or_initialize.tap do |u|
u.google_id = auth.uid
u.first_name = auth.info.first_name if auth.info.first_name
u.last_name = auth.info.last_name if auth.info.last_name
... |
require "spec_helper"
RSpec.describe TwitterBro::Tweet do
let(:text) { "text" }
let(:tweet) do
described_class.new text: text
end
subject { tweet }
its(:text) { is_expected.to eq text }
end
|
class StoreTypesController < ApplicationController
before_filter :login_required
filter_access_to :all
# GET /store_types
# GET /store_types.xml
def index
@store_type = StoreType.new
@store_types = StoreType.active
respond_to do |format|
format.html # index.html.erb
format.xml { rend... |
require_relative 'player'
require_relative 'coordinate_validator'
class Game
attr_accessor :players, :status
include CoordinateValidator
def initialize
@players = []
@status = nil
end
def current_player
players.first
end
def other_player
players.last
end
def add(player)
players << player
en... |
require "rails_helper"
RSpec.describe "Courses", type: :request do
context "unathenticated" do
it "redirects user to sign_in when unauthenticated" do
get courses_path
expect(response).to have_http_status(302)
expect(response.location).to include()
end
end
context "authenticated" do
... |
class CharactersController < ApplicationController
before_action :set_character, only: [:show, :edit, :update, :destroy]
def index
@characters = Character.all.order(:name).page(params[:page]).per(26)
end
def show
end
def new
@character = Character.new
end
def edit
end
def create
@ch... |
# encoding: UTF-8
# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0
require 'spec_helper'
class FakeParser < TwitterCldr::Parsers::Parser
def do_parse(options); end
end
describe TwitterCldr::Parsers::Parser do
let(:parser) { FakeParser.new }
let(:tokens) do
[
TwitterCldr::To... |
class AddAlternativeNumberToContacts < ActiveRecord::Migration
def change
add_column :contacts, :alternative_number, :string
end
end
|
class HomeController < ApplicationController
def index
@user = current_user
@users = User.all
gon.jbuilder "app/views/users/index.json.jbuilder", as: "endorsements"
end
end
|
class Event < ApplicationRecord
belongs_to :game
belongs_to :user
has_many :user_events, dependent: :destroy
geocoded_by :place
after_validation :geocode, if: :will_save_change_to_place?
validates :date, presence: true
include PgSearch::Model
pg_search_scope :global_search,
against: [:date, :detai... |
require 'test_helper'
class QuestionDetailsControllerTest < ActionController::TestCase
setup do
@question_detail = question_details(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:question_details)
end
test "should get new" do
get :new
... |
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :users
resources :events
resources :visits
resources :interests
resources :categories
get 'users/identification/:identification', to: 'users#identification'
end
|
require File.dirname(__FILE__) + "/../../spec_helper"
describe Managers::ScenariosController do
let(:current_user) { Factory.stub(:manager) }
before(:each) do
controller.stub!(:current_user).and_return(current_user)
end
def mock_scenario(stubs={})
@mock_scenario ||= mock_model(Scenario, {:name => "bl... |
require_relative "room"
require_relative "item"
class House
attr_reader :rooms
def initialize
@rooms = []
end
def add_room(room)
if @rooms.length < 11
@rooms << room
true
else
false
end
end
def total_value
value = 0
@rooms.each do |room|
value += room.total_value
end
value
end
d... |
class CreateUsersSkills < ActiveRecord::Migration
def change
create_table :users_skills do |t|
t.integer "user_id"
t.integer "skill_id"
t.integer "proficiency"
t.timestamps
end
add_index "users_skills", :user_id
add_index "users_skills", :skill_id
end
end
|
require 'rails_helper'
describe 'As a user' do
before :each do
token = ENV['GOOGLE_TOKEN']
shop = Shop.create( name: 'Tattood',
street_address: '1331 17th Street',
city: 'Denver',
zip: '80202',
phone_number: '4325... |
# Method to create a list
# input: string of items separated by spaces (example: "carrots apples cereal pizza", quantity=1)
# steps:
# split up the string of items into an array (.split)
# create the hash for the list
# push the items in the array into the keys of the hash (list)
# set default quantity for eac... |
class School < ApplicationRecord
has_many :users
scope :draft, -> { where(status: 0) }
scope :active, -> { where(status: 1) }
scope :fund_raising, -> { where(status: 2) }
scope :built, -> { where(status: 3) }
enum status: {
draft: 0,
active: 1,
fund_raising: 2,
built: 3
}
end
|
class ChangeSyllabusTypeInCourses < ActiveRecord::Migration
def change
change_column :courses, :syllabus, :text, :default => ""
end
end
|
class ModelWithFiles < ActiveRecord::Base
include Upload::FileUtils
self.abstract_class = true
before_save :prepare_save_files
before_destroy :prepare_destroy_files
ImagesRootWeb = "/images/upload/"
@@file_attrs = {}
def self.file_attr(map)
cfg = {:required => true, :name => "f... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.