code
stringlengths
1
1.73M
language
stringclasses
1 value
class CreateInitialTables < ActiveRecord::Migration def up create_table :accounts do |t| t.string :username t.string :name t.string :surname t.string :email t.string :crypted_password t.string :role t.string :persistence_token t.belongs_to :modified_by t.time...
Ruby
class AddNotesToControls < ActiveRecord::Migration def change add_column :controls, :notes, :text end end
Ruby
class AddObjectObjectStartStopDates < ActiveRecord::Migration def up change_table :object_people do |t| t.datetime :start_date t.datetime :stop_date end change_table :object_documents do |t| t.datetime :start_date t.datetime :stop_date end end def down change_table :ob...
Ruby
class ChangeLikelihoodPg < ActiveRecord::Migration def _is_postgresql? begin ActiveRecord::Base.connection.kind_of?( ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) rescue false end end def up if _is_postgresql? connection.execute(%q{ alter table risks...
Ruby
class AddMissingSystemFields < ActiveRecord::Migration def up change_table :systems do |t| t.datetime :start_date t.datetime :stop_date t.string :url t.string :version end end def down change_table :systems do |t| t.remove :start_date t.remove :stop_date t.re...
Ruby
class MovePbcListsColumnsToCycles < ActiveRecord::Migration def up change_table :cycles do |t| t.string :title t.string :audit_firm t.string :audit_lead t.text :description t.string :status t.text :notes end Cycle.reset_column_information Cycle.all.each do |cycle|...
Ruby
class ChangePolymorphicTypesToProgramFromDirective < ActiveRecord::Migration RELATIONSHIP_TYPE_NAME_CHANGES = [ [:directive_applies_to_data_asset, :program_applies_to_data_asset], [:directive_applies_to_facility, :program_applies_to_facility], [:directive_applies_to_market, :program_applies_to_marke...
Ruby
class CreateControlAssessments < ActiveRecord::Migration def change create_table :control_assessments do |t| t.references :pbc_list t.references :control t.string :control_version t.boolean :internal_tod, :default => nil, :null => true t.boolean :internal_toe, :default => nil, :null ...
Ruby
class AddBaseProgramKinds < ActiveRecord::Migration def up Option.where(:role => 'program_type').destroy_all role = 'program_kind' Option.where(:role => role, :title => 'Not Applicable').destroy_all [ 'Regulation', 'Company Policy', 'Operational Group Policy', 'Data Asset Policy' ].each d...
Ruby
class RemoveDirectiveIdFromCycles < ActiveRecord::Migration def up remove_column :cycles, :directive_id end def down add_column :cycles, :directive_id, :integer end end
Ruby
class AddAssertionsToControls < ActiveRecord::Migration def change change_table :controls do |t| t.boolean :fraud_related t.boolean :key_control t.boolean :active end end end
Ruby
class ConsolidateRiskFields < ActiveRecord::Migration def up transaction do Risk.all.each do |risk| impact = [risk.financial_impact, risk.reputational_impact, risk.operational_impact] impact = impact.map(&:presence).compact.join("<br />") risk.update_attribute(:impact, impact) ...
Ruby
class CreatePrograms < ActiveRecord::Migration def change create_table :programs do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end end end
Ruby
class CreateRelationships < ActiveRecord::Migration def change create_table :relationships do |t| t.references :source, :polymorphic => true, :null => false t.references :destination, :polymorphic => true, :null => false t.references :modified_by t.string :relationship_type_id t.time...
Ruby
class FixCategoryScopes < ActiveRecord::Migration def up # Fix previously-created categories which don't specify a scope_id Category.where(:scope_id => nil).update_all(:scope_id => Control::CATEGORY_TYPE_ID) end def down end end
Ruby
class FixResponsesWithoutPopSamples < ActiveRecord::Migration def up end def down end end
Ruby
class AddTypeToRiskyAttributes < ActiveRecord::Migration def change change_table :risky_attributes do |t| t.string :type_string end end end
Ruby
class CreateRiskRiskyAttributes < ActiveRecord::Migration def change create_table :risk_risky_attributes do |t| t.references :risk, :null => false t.references :risky_attribute, :null => false t.references :modified_by t.timestamps end end end
Ruby
class DeleteReferencesWithoutUrLs < ActiveRecord::Migration def up Document.where(:link => nil).concat(Document.where(:link => "")).each {|x| x.destroy} end def down end end
Ruby
class AddNetworkZoneIdToSystems < ActiveRecord::Migration def change add_column :systems, :network_zone_id, :integer end end
Ruby
class AddUrlToSections < ActiveRecord::Migration def change add_column :sections, :url, :string end end
Ruby
class AddProgramColumns < ActiveRecord::Migration def up change_table :programs do |t| t.string :version t.datetime :start_date t.datetime :stop_date t.string :url t.string :organization t.text :scope t.references :kind t.datetime :audit_start_date t.reference...
Ruby
class AddNaToSection < ActiveRecord::Migration def change add_column :sections, :na, :boolean, :null => false, :default => false add_column :sections, :notes, :text end end
Ruby
class FixResponsesWithoutPopSamples2 < ActiveRecord::Migration def up transaction do Response .joins( :request ) .where( :requests => { :type_id => 2 } ) .joins("left outer join population_samples as population_sample on population_sample.response_id = responses.id") .where(:popu...
Ruby
class RemoveRiskFields < ActiveRecord::Migration def up remove_column :risks, :financial_impact remove_column :risks, :reputational_impact remove_column :risks, :operational_impact end def down end end
Ruby
class UpdateLanguagesAndControlKinds < ActiveRecord::Migration def up o = Option.where(:role => 'control_kind', :title => 'Directive').first if o o.title = 'Administrative' o.save end o = Option.where(:role => 'control_means', :title => 'Manual with Segregation of Duties').first if o ...
Ruby
class AddPopulationSampleForExistingResponses < ActiveRecord::Migration def up Request.all. select { |r| r.type_name == 'Population Sample' }. map { |r| r.responses.all }. flatten. each { |r| r.create_population_sample if r.population_sample.nil? } end def down end end
Ruby
class AddRiskFields < ActiveRecord::Migration def change add_column :risks, :inherent_risk, :text add_column :risks, :risk_mitigation, :text add_column :risks, :residual_risk, :text add_column :risks, :impact, :text end end
Ruby
class CreateCategories < ActiveRecord::Migration def change create_table :categories do |t| t.string :name t.integer :parent_id t.integer :lft t.integer :rgt t.integer :scope_id t.integer :depth t.timestamps end create_table :categorizations do |t| t.refer...
Ruby
class RemovePbcListsColumns < ActiveRecord::Migration def up change_table :pbc_lists do |t| t.remove :title t.remove :description t.remove :audit_firm t.remove :audit_lead t.remove :notes t.remove :list_import_date t.remove :status end end def down end end
Ruby
class CopyBizProcessesToSystems < ActiveRecord::Migration class BizProcess < ActiveRecord::Base end def up System.reset_column_information # Copy BizProcess and relations to System BizProcess.all.each do |bp| sys = System.create!( :title => bp.title, :slug => bp.slug, :...
Ruby
class FixCategories < ActiveRecord::Migration def change change_table :categorizations do |t| t.belongs_to :modified_by end rename_column :categorizations, :stuff_id, :categorizable_id rename_column :categorizations, :stuff_type, :categorizable_type change_table :categories do |t| t.b...
Ruby
class SetProgramIdOnCycles < ActiveRecord::Migration def up transaction do Cycle.all.each do |cycle| directive = Directive.find(cycle.directive_id) program = directive.programs.first cycle.update_attribute(:program_id, program.id) end end end def down end end
Ruby
class CreateMeetings < ActiveRecord::Migration def change create_table :meetings do |t| t.references :response t.datetime :start_at t.string :calendar_url t.references :modified_by t.timestamps end end end
Ruby
class CreateSystemSystems < ActiveRecord::Migration def change create_table :system_systems do |t| t.references :parent, :null => false t.references :child, :null => false t.string :type t.integer :order t.references :modified_by t.timestamps end end end
Ruby
class UpdateAccountRoles < ActiveRecord::Migration def up Account.where(:role => 'superuser').each do |account| account.role = 'admin' account.save end end def down end end
Ruby
class RenameLocationsToFacilities < ActiveRecord::Migration RELATIONSHIP_TYPE_NAME_CHANGES = [ ["location_has_process", "facility_has_process"], ["location_has_risky_attribute", "facility_has_risky_attribute"], ["location_is_dependent_on_location", "facility_is_dependent_on_faci...
Ruby
class RemoveNameFromAccounts < ActiveRecord::Migration def up Account.all.each do |a| person = Person.find_by_email(a.email) if person person.name = "#{a.name} #{a.surname}" person.save!(:validate => false) else a.person = Person.create({:email => a.email, ...
Ruby
class AddRequiredToOptions < ActiveRecord::Migration def change add_column :options, :required, :boolean end end
Ruby
class CreateTransactions < ActiveRecord::Migration def change create_table :transactions do |t| t.string :title, :null => false t.text :description t.references :system t.references :modified_by t.timestamps end end end
Ruby
class AddPersonCompany < ActiveRecord::Migration def up add_column :people, :company, :string end def down remove_column :people, :company end end
Ruby
class AddResponseDueAtToRequest < ActiveRecord::Migration def change add_column :requests, :response_due_at, :date end end
Ruby
class AddProgramForEachDirective < ActiveRecord::Migration def up transaction do Directive.all.each do |directive| if directive.programs.count == 0 program = Program.create!( :title => directive.title ) program_directive = ProgramDirective.create!( ...
Ruby
class AddDefaultOptionsAndCategories < ActiveRecord::Migration def up Option.reset_column_information Category.reset_column_information Categorization.reset_column_information options = { :control_type => [], :control_kind => ["Reactive", "Directive", "Detective", "Preventative"], :...
Ruby
class CreateRelationshipTypes < ActiveRecord::Migration def change create_table :relationship_types, :id => false do |t| t.string :relationship_type t.string :description t.string :forward_short_description t.string :backward_short_description t.timestamps end add_index...
Ruby
class FixRiskyAttributeRelationships < ActiveRecord::Migration RELATIONSHIP_TYPE_NAME_CHANGES = [ [ :risky_attribute_is_an_attribute_of_org_group, :org_group_has_risky_attribute ], [ :risky_attribute_is_an_attribute_of_product, :product_has_risky_attribute ], [ :risky_attribute_is_an_attribute_of_loca...
Ruby
class CreateRequests < ActiveRecord::Migration def change create_table :requests do |t| t.references :pbc_list t.references :type t.references :control t.string :pbc_control_code t.text :pbc_control_desc t.text :request t.text :test t.text :notes t.string :com...
Ruby
class AddRelationshipTypeSymmetric < ActiveRecord::Migration def change add_column :relationship_types, :symmetric, :boolean, :default => false end end
Ruby
class ChangeHelpsContentType < ActiveRecord::Migration def up change_column :helps, :content, :text, :limit => nil end def down change_column :helps, :content, :string end end
Ruby
class RemoveInvalidRiskyAttributes < ActiveRecord::Migration def up RiskyAttribute.where(:type_string => nil).each do |ra| ra.destroy end RiskyAttribute.where(:type_string => "").each do |ra| ra.destroy end RiskyAttribute.where(:type_string => "Org Group").each do |ra| ra.updat...
Ruby
class RemoveParentheticalsFromStatusValues < ActiveRecord::Migration REQUEST_STATUS_MIGRATIONS = [ ["Responded (by Compliance)", "Responded"], ["Amended/Updated Request (by Auditor)", "Amended/Updated Request"], ["Accepted (by Auditor)", "Accepted"] ] def up REQUEST_STATUS_MIGRATIONS.each do |old...
Ruby
class RenameProgramsToDirectives < ActiveRecord::Migration def up rename_table :programs, :directives rename_column :controls, :program_id, :directive_id rename_column :sections, :program_id, :directive_id rename_column :cycles, :program_id, :directive_id end def down rename_table :directive...
Ruby
class UpdateRelationshipTypeIds < ActiveRecord::Migration RELATIONSHIP_TYPE_NAME_CHANGES = [ [:program_is_relevant_to_org_group, :program_applies_to_org_group], [:program_is_relevant_to_product, :program_applies_to_product], [:program_is_relevant_to_facility, :program_applies_to_facility], ...
Ruby
class CreateVersions < ActiveRecord::Migration def self.up create_table :versions do |t| t.string :item_type, :null => false t.integer :item_id, :null => false t.string :event, :null => false t.string :whodunnit t.text :object t.datetime :created_at end ...
Ruby
class CreateObjectPeople < ActiveRecord::Migration class BizProcessPerson < ActiveRecord::Base end class SystemPerson < ActiveRecord::Base end def change create_table :object_people do |t| t.string :role t.text :notes t.references :person, :null => false t.references :personable, ...
Ruby
class CreateOptions < ActiveRecord::Migration def change create_table :options do |t| t.string :role, :null => false t.string :title, :null => false t.text :description t.references :modified_by t.timestamps end end end
Ruby
class FixRiskyAttributeSlugs < ActiveRecord::Migration def up RiskyAttribute.all.each do |ra| if ra.slug.match(/^RISKYATTRIBUTE/) ra.slug = ra.slug.sub(/^RISKYATTRIBUTE/, 'RA') ra.save! end end end def down end end
Ruby
class AddToProgram < ActiveRecord::Migration def up change_table :programs do |t| t.integer :frequency_type, :default => 1 t.integer :frequency, :default => 1 end end def down change_table :programs do |t| t.remove :frequency, :frequency_type end end end
Ruby
class DeprecateUnusedAccountRoles < ActiveRecord::Migration class Account < ActiveRecord::Base end def up Account.where(:role => :admin).each do |account| account.role = :superuser account.save end Account.where(:role => :admin).each do |account| account.role = :superuser acc...
Ruby
class CreatePopulationSamples < ActiveRecord::Migration def change create_table :population_samples do |t| t.references :response t.references :population_document t.integer :population t.references :sample_worksheet_document t.integer :samples t.references :sample_evidence_doc...
Ruby
class CreatePbcLists < ActiveRecord::Migration def change create_table :pbc_lists do |t| t.references :audit_cycle t.string :title t.string :audit_firm t.string :audit_lead t.text :description t.datetime :list_import_date t.string :status t.text :notes t.refer...
Ruby
class UpdateBaseRelationshipTypes < ActiveRecord::Migration def up RelationshipType.reset_column_information new_relationship_types = [ # Relationship types are in alphabetical order! { :relationship_type => 'location_is_dependent_on_location', :description => "Locations can be de...
Ruby
class CreateProducts < ActiveRecord::Migration def up create_table :products do |t| t.string :slug t.string :title t.text :description t.string :url t.string :version t.references :type t.references :modified_by t.timestamps end end def down end end
Ruby
class AddEndAtToCycles < ActiveRecord::Migration def change add_column :cycles, :end_at, :date end end
Ruby
class CreateLocations < ActiveRecord::Migration def change create_table :locations do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end end end
Ruby
class AddBaseMarketRelationships < ActiveRecord::Migration def up new_relationship_types = [ # Relationship types are in alphabetical order! { :relationship_type => 'market_contains_a_market', :description => "Markets can have submarkets.", :forward_phrase =>"containing", ...
Ruby
class AddTitleToHelps < ActiveRecord::Migration def change add_column :helps, :title, :string end end
Ruby
class CreateRiskyAttributes < ActiveRecord::Migration def change create_table :risky_attributes do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end ...
Ruby
class AddKindToDirectives < ActiveRecord::Migration def change add_column :directives, :kind, :string end end
Ruby
class CreateProgramDirectives < ActiveRecord::Migration def change create_table :program_directives do |t| t.references :program, :null => false t.references :directive, :null => false t.references :modified_by t.timestamps end end end
Ruby
class ChangeDirectiveKindToString < ActiveRecord::Migration def up transaction do Directive.all.each do |directive| option = Option.where(:role => 'directive_kind', :id => directive.kind_id).first kind = option ? option.title : "Regulation" kind = "Org Group Policy" if kind == "Opera...
Ruby
class CreateMarkets < ActiveRecord::Migration def change create_table :markets do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end end end
Ruby
class MoveProgramHelps < ActiveRecord::Migration HELP_SLUG_CHANGES = { :program_cycles => :directive_cycles, :program_info => :directive_info, :programs_list => :directives_list, :program_controls => :directive_controls, :program_more_info => :directive_more_info, :program => :directive } ...
Ruby
class ReorgControls < ActiveRecord::Migration class Program < ActiveRecord::Base end class Section < ActiveRecord::Base belongs_to :parent, :class_name => "Section" end def up raise "do not know how to migrate ControlControls" unless ControlControl.count == 0 rename_table :control_control_object...
Ruby
class CreateOrgGroups < ActiveRecord::Migration def change create_table :org_groups do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end end end
Ruby
class CreateRisks < ActiveRecord::Migration def change create_table :risks do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end end end
Ruby
class AddControlColumns < ActiveRecord::Migration def up change_table :controls do |t| t.string :version t.datetime :start_date t.datetime :stop_date t.string :url t.text :documentation_description t.references :verify_frequency t.remove :frequency t.remove :frequen...
Ruby
class AddOptionReferences < ActiveRecord::Migration def up change_table :controls do |t| t.references :type t.references :kind t.references :means end change_table :systems do |t| t.references :type end end def down change_table :controls do |t| t.remove :type_i...
Ruby
class CreateDataAssets < ActiveRecord::Migration def change create_table :data_assets do |t| t.string :slug t.string :title t.text :description t.string :url t.references :modified_by t.datetime :start_date t.datetime :stop_date t.timestamps end end end
Ruby
class ChangeCompanyControlsToPolicy < ActiveRecord::Migration def up transaction do Directive.where(:kind => "Company Controls").each do |directive| directive.kind = "Company Controls Policy" directive.save! end end end def down end end
Ruby
class ChangeRelationshipsFromLocationToFacility < ActiveRecord::Migration def up Relationship.where(:source_type => 'Location').all.each do |rel| rel.update_attribute(:source_type, 'Facility') end Relationship.where(:destination_type => 'Location').all.each do |rel| rel.update_attribute(:desti...
Ruby
class ChangePolymorphicTypesFromLocationToFacility < ActiveRecord::Migration def up ObjectPerson.where(:personable_type => 'Location').all.each do |o| o.update_attribute(:personable_type, 'Facility') end ObjectDocument.where(:documentable_type => 'Location').all.each do |o| o.update_attribute(...
Ruby
class AddRequiredToCategories < ActiveRecord::Migration def change add_column :categories, :required, :boolean end end
Ruby
class RemoveDeprecatedDatabaseObjects < ActiveRecord::Migration def up # BizProcess is now a subset/type of System # - data migration happened in 20120723223448_copy_biz_processes_to_systems.rb drop_table :biz_process_controls drop_table :biz_process_documents drop_table :biz_process_people dr...
Ruby
class CreateHelps < ActiveRecord::Migration def change create_table :helps do |t| t.string :slug t.string :content t.timestamps end end end
Ruby
class RegulationToProgram < ActiveRecord::Migration def up rename_table :regulations, :programs rename_table :control_objectives, :sections change_table :sections do |t| t.integer :parent_id t.index :parent_id end end end
Ruby
class AddControlAssessmentIdToRequests < ActiveRecord::Migration def change add_column :requests, :control_assessment_id, :integer add_index :requests, :control_assessment_id end end
Ruby
class CreateObjectDocuments < ActiveRecord::Migration class BizProcessDocument < ActiveRecord::Base end class DocumentSystem < ActiveRecord::Base end class DocumentSystemControl < ActiveRecord::Base end def change create_table :object_documents do |t| t.string :role t.text :notes t....
Ruby
class AddSystemsIsBizProcess < ActiveRecord::Migration def up change_table :systems do |t| t.boolean :is_biz_process, :default => false end end def down change_table :systems do |t| t.remove :is_biz_process end end end
Ruby
SIZE=20 ACCOUNTS = { :root => :superuser, :user => :user, :owner1 => :user, :owner2 => :user } ActiveRecord::Base.transaction do # Accounts ACCOUNTS.each do |name, role| Account. where(:email => "#{name}@t.com"). first_or_create!( {:password => name, :password_confirmation => name...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integrati...
Ruby
# Uncomment or put the following in Gemfile.local # source 'http://rubygems.org' if File.exist? 'Gemfile.local' instance_eval(Bundler.read_file('Gemfile.local'), 'Gemfile.local', 1) end RAILS_VERSION = '= 3.2.13' # Fulltext search gem 'thinking-sphinx', '~> 2.0.14' gem 'remotipart' #gem 'gdata-ruby-util', '1.1.2...
Ruby
#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
# Test some of the authorization basics for resource controllers. # # Usage: # # require 'authorized_controller' # # before :each do # @model = <model> # The model that you're testing authorization for, e.g. Account # @object = <obj> # An instance you want to test read and update actions against # @index_objs = ...
Ruby
module UserSpecHelper # Set the rspec environment so that we can call stub_model def set_rspec(rspec) @_rspec = rspec end def current_user(stubs = {}) return @current_user if @current_user role = (stubs.delete(:role) || :user).to_s if respond_to?(:stub_model) @current_user = stub_model(...
Ruby
require 'spork' require 'simplecov' require 'capybara/rspec' if ENV['COVERAGE'] SimpleCov.start do add_group 'Models', 'app/models' add_group 'Helpers', 'app/helpers' add_group 'Controllers', 'app/controllers' add_group 'Admin C', 'app/controllers/admin' add_filter 'config' add_fil...
Ruby
# Read about factories at https://github.com/thoughtbot/factory_girl FactoryGirl.define do factory :control_assessment do pbc_list { |c| c.association(:pbc_list) } control { |c| c.association(:control) } control_version "MyString" internal_tod false internal_toe false external_tod false e...
Ruby
FactoryGirl.define do sequence(:slug) do |n| # FIXME: Do I need to generate slugs according to a convention, or # do they only need to be unique? # FIXME: Slugs will become invalid if parenting is ever changed # anywhere in the ancestor heirarchy. # FIXME: Slug validation makes factories for secti...
Ruby
module BaseObjects def create_base_objects @prog = FactoryGirl.create(:program, :title => 'Program') @opt_reg = FactoryGirl.create(:option, :title => 'Regulation', :role => 'directive_kind') @opt_com = FactoryGirl.create(:option, :title => 'Company Policy', :role => 'directive_kind') @creg = FactoryGi...
Ruby
module DatedModel include ActiveSupport::Concern def self.included(model) model.validate :stop_date_later_than_start_date end def stop_date_later_than_start_date if self.has_attribute? :stop_date if self.start_date.present? && self.stop_date.present? errors.add(:stop_date, 'Must be l...
Ruby