Skip to content
Browse files

Renamed log-weasel to log_weasel. First running spec.

  • Loading branch information...
1 parent 01e7950 commit 582976601f50226952310bd8bddd8b3f970b4528 @asalant asalant committed Feb 11, 2011
View
2 .rvmrc
@@ -1 +1 @@
-rvm --create ruby-1.9.2-p0@log-weasel
+rvm --create ruby-1.9.2-p0@log_weasel
View
2 Gemfile
@@ -1,4 +1,4 @@
source "http://rubygems.org"
-# Specify your gem's dependencies in log-weasel.gemspec
+# Specify your gem's dependencies in log_weasel.gemspec
gemspec
View
4 README.md
@@ -4,10 +4,10 @@ Instrument Rails and Resque with shared transaction IDs so that you trace execut
## Installation
-Add log-weasel to your Gemfile:
+Add log_weasel to your Gemfile:
<pre>
-gem 'log-weasel'
+gem 'log_weasel'
</pre>
Use bundler to install it:
View
9 Rakefile
@@ -1,2 +1,11 @@
require 'bundler'
+Bundler.setup
+
+require 'rspec'
+require 'rspec/core/rake_task'
+
Bundler::GemHelper.install_tasks
+
+Rspec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+end
View
5 lib/log-weasel.rb
@@ -1,5 +0,0 @@
-module Log
- module Weasel
- # Your code goes here...
- end
-end
View
1 lib/log_weasel.rb
@@ -0,0 +1 @@
+require 'log_weasel/transaction'
View
21 lib/log_weasel/transaction.rb
@@ -0,0 +1,21 @@
+module LogWeasel
+ module Transaction
+
+ def self.create(key = nil)
+ Thread.current[:manilla_transaction_id] = "#{key ? "#{key}_" : ""}#{SecureRandom.hex(10)}"
+ end
+
+ def self.destroy
+ Thread.current[:manilla_transaction_id] = nil
+ end
+
+ def self.id=(id)
+ Thread.current[:manilla_transaction_id] = id
+ end
+
+ def self.id
+ Thread.current[:manilla_transaction_id]
+ end
+ end
+
+end
View
0 lib/log-weasel/version.rb → lib/log_weasel/version.rb
File renamed without changes.
View
15 log-weasel.gemspec → log_weasel.gemspec
@@ -1,18 +1,23 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
-require "log-weasel/version"
+require "log_weasel/version"
Gem::Specification.new do |s|
- s.name = "log-weasel"
+ s.name = "log_weasel"
s.version = Log::Weasel::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Alon Salant"]
s.email = ["alon@salant.org"]
- s.homepage = ""
- s.summary = %q{Instrument Rails and Resque with shared transaction IDs so that you trace execution across instances.}
+ s.homepage = "http://github.com/carbonfive/log_weasel"
+ s.summary = "log_weasel-#{Log::Weasel::VERSION}"
s.description = %q{Instrument Rails and Resque with shared transaction IDs so that you trace execution across instances.}
- s.rubyforge_project = "log-weasel"
+ s.rubyforge_project = "log_weasel"
+
+ s.add_development_dependency('rspec')
+ s.add_development_dependency('mocha')
+ s.add_development_dependency('resque', ['~> 1.0'])
+ s.add_development_dependency('activesupport', ['~> 3.0'])
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
View
54 spec/log_weasel/transaction_spec.rb
@@ -0,0 +1,54 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require 'active_support'
+require 'active_support/secure_random'
+
+describe LogWeasel::Transaction do
+
+ describe ".id" do
+
+ it "is nil if not created" do
+ LogWeasel::Transaction.id.should be_nil
+ end
+
+ end
+
+ describe ".id=" do
+ before do
+ LogWeasel::Transaction.id = "1234"
+ end
+
+ it "sets the id" do
+ LogWeasel::Transaction.id.should == "1234"
+ end
+
+ end
+
+ describe ".create" do
+ before do
+ SecureRandom.stubs(:hex).returns('94b2')
+ end
+
+ it 'creates a transaction id with no key' do
+ id = LogWeasel::Transaction.create
+ id.should == '94b2'
+ end
+
+ it 'creates a transaction id with a key' do
+ id = LogWeasel::Transaction.create 'KEY'
+ id.should == 'KEY_94b2'
+ LogWeasel::Transaction.id.should == id
+ end
+
+ end
+
+ describe ".destroy" do
+ before do
+ LogWeasel::Transaction.create
+ end
+
+ it "removes transaction id" do
+ LogWeasel::Transaction.destroy
+ LogWeasel::Transaction.id.should be_nil
+ end
+ end
+end
View
9 spec/spec_helper.rb
@@ -0,0 +1,9 @@
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+
+require 'log_weasel'
+require 'rspec'
+
+Rspec.configure do |config|
+ config.mock_with :mocha
+end

0 comments on commit 5829766

Please sign in to comment.
Something went wrong with that request. Please try again.