Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
8 total  XML / RSS feed 

test

// description of your code here

// insert code here..

test test

// description of your code here

/**
 * create and maintain metadata for the the events list
 */
function EventsListMetadataFactory() {
    this._metadataForView = {};
}

EventsListMetadataFactory.prototype._className = "EventsListMetadataFactory";
EventsListMetadataFactory.prototype._metadataForView;

EventsListMetadataFactory._instance;

EventsListMetadataFactory.GROUPING_BY_CASE_STATUS = "TRACKING_STATE_TYPE_COL";

EventsListMetadataFactory.getInstance = function() {
    if (!EventsListMetadataFactory._instance) {
        EventsListMetadataFactory._instance = new EventsListMetadataFactory();
    }
    return EventsListMetadataFactory._instance;
}

/**
 * get the metadata
 */
EventsListMetadataFactory.prototype.getMetadata = function() {
    // todo: apply caching
    return this._createMetadata();
}

/**
 * create the metadata
 */
EventsListMetadataFactory.prototype._createMetadata = function() {
    var metadata = this._metadata = new VerixTreeMetadata();

    var columnsMetadata = getUserView().getViewData().getDisplayData().getColumnsMetadata();
    if (columnsMetadata && columnsMetadata.length>0) {
        for (var i=0; i<columnsMetadata.length; i++) {
            var columnMetadata = columnsMetadata[i];

            metadata.addCol(this.getColMetadataByLogicalName(columnMetadata));
        }

    } else {

        metadata.addCol(new EventTitleColMetadata());

        if (getCommonPropertie("eventsList.showPinColumn")=="true") {
            metadata.addCol(new EventNodePropertyColMetadata(getNodePropertyManager().getNodePropertyOfMainPin(),false));
        }

        if (getCommonPropertie("eventsList.showDiscoveryNDateColumn")=="true") {
            metadata.addCol(new EventDiscoveryTimeColMetadata());
        }

        if (getCommonPropertie("eventsList.showStateColumn")=="true") {
            metadata.addCol(new EventStateColMetadata());
        }

        // handle column highlighting for node properties
        var highlightedColumns = getCommonPropertyArray("eventsList.highlightedColumns");
        var highlightedColumnsMap = {};
        if (highlightedColumns) {
            for (var i = 0; i < highlightedColumns.length; i++) {
                highlightedColumnsMap[highlightedColumns[i]] = true;
            }
        }

        // add node properties
        var nodeProperties = getNodePropertyManager().getNodePropertiesByIds(getCommonPropertyArray("eventLists.columns"));
        for (var i = 0; i < nodeProperties.length; i++) {
            var nodeProperty = nodeProperties[i];
            // decide upon highlighting
            var isHighlighted = false;
            if (highlightedColumnsMap[i]) {
                isHighlighted = true;
            }
            // add column
            metadata.addCol(new EventNodePropertyColMetadata(nodeProperty,isHighlighted));
        }

        if (getCommonPropertie("eventsList.showRelatedEventColumn")=="true") {
            metadata.addCol(new EventRelatedColMetadata());
        }
        if (isDebug()) {
            metadata.addCol(new EventTagIconColMetadata());
            metadata.addCol(new EventIdColMetadata());
        }

        // add dimensions
        var dNameKeys = getApplicationCodeTableManager().getKeys("D_NAME");
        dNameKeys.sort(function compare(a, b) {
            return a - b;
        });
        //create map of the required dimensions in regular mode
        var requiredDimensionMap = {};
        var requiredDimensions = getCommonPropertyArray("eventLists.dimensionColumns");
        for (var i = 0; i < requiredDimensions.length; i++){
            requiredDimensionMap[requiredDimensions[i]] = true;
        }
        for (var i = 0; i < dNameKeys.length; i++) {
            var dimensionId = dNameKeys[i];
            if (isDebug() || requiredDimensionMap[dimensionId] != null) {
                metadata.addCol(new EventDimensionColMetadata(dimensionId));
            }
        }
    }

    return metadata;
}

/**
 * create the col meta data according to the passed logical name
 */
EventsListMetadataFactory.prototype.getColMetadataByLogicalName = function(columnMetadata) {
    var logicalName = columnMetadata.logicalName;
    var width = columnMetadata.width;
    var colMetadata = eval("new " + logicalName + "()");
    if (width) {
        colMetadata.setWidth(width)
    }
    return colMetadata;
}

Scott Tiner

changes.mid
and_your_bird_can_sing.mid
another_girl.mid
Anybody Here Seen My Old Friend John.mid
APACHE.mid
AQUARIUS.mid
Bad-Moon.mid
Bell-Bottom-Blues.mid
brown-eyed girl.mid
candle in the wind.mid
carry_that_weight.mid

YAML parameters, session, etc. in Rails functional tests

This lets you embed YAML in your functional tests, for when you have complex form posts you want to mock out.

  post :process_checkout, YAML.load(<<-END.gsub(/^\s*\|/, "")).symbolize_keys
  |---
  |card:
  |  number: "4242424242424242"
  |  month: 8
  |  year: 2010
  |  first_name: Test
  |  last_name: Customer
  |  type: visa
  END

IM test

// description of your code here

stabbed in the face says:
hey wanna eat in like 10 mins? oli and rich just went to get food i think theyll meet us up there at some pt
Ben says:
k, I might pull out a bit early to have a little pow-wow with Mo and Ross though
stabbed in the face says:
word, yeah i cant waste too much time today either
stabbed in the face says:
want to put some Qs together for christian

My test snippet

// description of your code here

some test code

Simple Test if Site is online

// test if sites are online by title validation
// if the title can change, test can validate occurance of a phrase instead

require 'rwebunit'  # ruby web test based on watir

# test if sites are online by title validation
# usage: to run this test without visible ie use the -b option
# C:\ruby\workspace\ruject1>ruby rwu_site_checker.rb -b

class RwuSiteChecker < RWebUnit::WebTestCase

  # hash with url and title
  @@sites = {
    "http://www.domain_number_one.de" => "title number one",
    "http://www.seccond_domain.org" => "seccond title",
    "http://www.yet_another_domain.com" => "yet another title"
  }
  
  # test for titles
  def test_titles()
    log = "testing title \n"
    @@sites.each { |url, title|
      getTestContext().base_url=url
      beginAt("/")
      assertTitleEquals(title)
      # to check for phrase: assertTextPresent(phrase) 
   
      log += url + " ok \n"
    }
    puts log
  end
  
end

Test helper for colorfull logging

Helper methods defined in this test_helper.rb make test.log colorfull and allow to easy find specific test cases and failures. To log test names use following template for test method:

def test_creates_entry
  log_test_name
  # Rest of your test code goes here
  # ...
end


test/test_helper.rb

ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'

module Test::Unit::Assertions
  def assert_block(message="assert_block failed.") # :yields:
    _wrap_assertion do
      if (! yield)
        logger.debug("\e[0;41mFailure:\e[m #{message}")
        raise Test::Unit::AssertionFailedError.new(message.to_s)
      else
        logger.debug("\e[0;32mSuccess\e[m")
      end
    end
  end
end

class Test::Unit::TestCase
  # Transactional fixtures accelerate your tests by wrapping each test method
  # in a transaction that's rolled back on completion.  This ensures that the
  # test database remains unchanged so your fixtures don't have to be reloaded
  # between every test method.  Fewer database queries means faster tests.
  #
  # Read Mike Clark's excellent walkthrough at
  #   http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
  #
  # Every Active Record database supports transactions except MyISAM tables
  # in MySQL.  Turn off transactional fixtures in this case; however, if you
  # don't care one way or the other, switching from MyISAM to InnoDB tables
  # is recommended.
  self.use_transactional_fixtures = true

  # Instantiated fixtures are slow, but give you @david where otherwise you
  # would need people(:david).  If you don't want to migrate your existing
  # test cases which use the @david style and don't mind the speed hit (each
  # instantiated fixtures translates to a database query per test method),
  # then set this back to true.
  self.use_instantiated_fixtures  = false

  def logger
    RAILS_DEFAULT_LOGGER
  end

  def log_test_name(test_name=nil)
    test_name = caller[0].match(/`(test_[a-z_]+)'$/) unless test_name
    logger.debug "\n\e[1m#{self.class}::\e[0;31m#{test_name}\e[m\n"
  end
end

class ActionController::Integration::Session
  def logger
    RAILS_DEFAULT_LOGGER
  end

  def log_step_name(step_name=nil)
    step_name = caller[0].match(/`(test_[a-z_]+)'$/) unless step_name
    logger.debug "\n\e[1m#{step_name}\e[m"
  end
end
« Newer Snippets
Older Snippets »
8 total  XML / RSS feed