Skip to content

Instantly share code, notes, and snippets.

View daveworth's full-sized avatar
🔬
Science!

David E Worth daveworth

🔬
Science!
View GitHub Profile
require 'test_helper'
class TestDynamic < Test::Unit::TestCase
def setup; end
def teardown; end
def test_method1; end
def test_method2; end
end
@daveworth
daveworth / another_model_spec.rb
Created December 13, 2011 16:36
Now with external attributes
require 'spec_helper'
describe AnotherModel do
it "should process a fixture" do
ap expected = AnotherModel.human_attribute_name('expected_countries')
index = 0
country_fixture.each_line do |line|
line.should match expected[index]
index += 1
@daveworth
daveworth / another_model_spec.rb
Created December 13, 2011 16:31
Country Fixture
require 'spec_helper'
describe AnotherModel do
it "should process a fixture" do
expected = ["Zimbabwe", "Tibet", "Equador"]
index = 0
country_fixture.each_line do |line|
line.should match expected[index]
index += 1
@daveworth
daveworth / better_model.rb
Created December 12, 2011 23:03
Data separated from Model!
class OurModel < ActiveRecord::Base
# ... snip ...
#
def generate_csv_template(account_id)
csv_headers = OurModel.human_attribute_name("csv_template_headers")
headers = CustomModel.find_all_by_account_id(account_id).map(&:name)
CSV.generate do |csv|
@daveworth
daveworth / en.yml
Created December 12, 2011 22:48
Our localization file.
en:
our_model:
explanation_text: "Welcome to the site!"
@daveworth
daveworth / more_headers.rb
Created December 12, 2011 22:44
Now with more headers...
class OurModel < ActiveRecord::Base
# ... snip ...
def generate_csv_template(account_id)
headers = <<HEADERS
first_name,last_name,birth_date,pet_name
HEADERS
headers += CustomModel.find_all_by_account_id(account_id).
map(&:name).join(",")
require 'date'
require 'active_support'
require 'awesome_print'
load 'lib/gibbon.rb'
def broken_test
g = Gibbon.new("API-KEY")
ge = g.get_exporter
list_id = ""
def label=(temp_label)
#self.email_label = current_account.email_labels.find_or_create_by_name(temp_label)
label = EmailLabel.find_or_create_by_name_and_account_id(temp_label.downcase, account.id)
self.email_label = label
end
class Foo < ActiveRecord::Base
#...
end
class Bar < Foo
serialize :foo
end
def edit
foo = Foo.find(1) # => Bar(id: 1)
[["websites", /website/i], ["emails", /email/i], ["phones", /phone|fax|cell/i]].each do |getter_data|
data_type, regex = *getter_data