Skip to content

Instantly share code, notes, and snippets.

View kiote's full-sized avatar
👋

Ёkaterina Krivich kiote

👋
View GitHub Profile
@kiote
kiote / Observer.rb
Created July 6, 2011 08:11
Observer
class Project < ActiveRecord::Base
after_create :send_create_notifications
private
def send_create_notifications
self.members.each do |member|
ProjectMailer.deliver_notification(self, member)
end
end
end
@kiote
kiote / Ex1.rb
Created August 31, 2011 09:42
Ex1
def followers_count(user)
c = Twitter.followers_count(user)
user.update_attribute(:followers_count, c)
end
@kiote
kiote / ex2.rb
Created August 31, 2011 09:54
ex2
stub_request(:any, "api.twitter.com/followrs/count").with(:body=>'Hi')
require 'webmock/rspec'
RSpec.configure do |config|
WebMock.disable_net_connect!
require 'vcr'
VCR.config do |c|
c.cassette_library_dir = 'vcr_cassettes'
c.stub_with :webmock
c.default_cassette_options = { :record => :once }
end
it "should get followers count" do
VCR.use_cassette('twi_followers_count') do
MyModel.followers_count(@user).should == 3
end
end
@kiote
kiote / html_reporter.rb
Created September 28, 2011 10:20
html reporter
class HtmlReporter
def make_report(data)
make_html_header
make_html_body
make_html_footer
end
end
@kiote
kiote / reporter.rb
Created September 28, 2011 10:31
html reporter2
class HtmlReporter
def make_report(data)
make_html_header
make_html_body
make_html_footer
end
end
class PdfReporter
def make_report(data)
@kiote
kiote / abstract_report.rb
Created September 28, 2011 10:36
abstract_report
class Report
def make_report(data)
make_header
make_body
make_footer
end
protected
# методы ничего не реализуют
@kiote
kiote / mixin.rb
Created September 28, 2011 10:42
class HtmlReporter < SomthingElse
include Reporter
protected
# реализация методов для html-версии
def make_header
end
def make_body
class MyClass
def do_somth_with_class
OtherClass.method
other_stuff
end
end