Permalink
Browse files

Merge pull request #3 from rshallit/master

Proposed fix for threading issue
  • Loading branch information...
2 parents fb6680f + 82417e6 commit 814c56a14e8f3cb29f56c06a24bb526a35787d57 @asanghi committed Jul 12, 2012
Showing with 13 additions and 6 deletions.
  1. +6 −6 lib/rising_sun/fiscali.rb
  2. +7 −0 spec/fiscali_spec.rb
@@ -11,21 +11,21 @@ def self.included(base)
module ClassMethods
def fiscal_zone=(zone)
- Thread.current[:fiscali_start_month] = FISCAL_ZONE[zone] || FY_START_MONTH
- Thread.current[:fiscali_zone] = zone
+ @fiscali_start_month = FISCAL_ZONE[zone] || FY_START_MONTH
+ @fiscali_zone = zone
end
def fy_start_month
- Thread.current[:fiscali_start_month] || FY_START_MONTH
+ @fiscali_start_month || FY_START_MONTH
end
def fiscal_zone
- Thread.current[:fiscali_zone]
+ @fiscali_zone
end
def fy_start_month=(month)
- Thread.current[:fiscali_zone] = nil
- Thread.current[:fiscali_start_month] = month
+ @fiscali_zone = nil
+ @fiscali_start_month = month
end
def financial_year_start(year=Date.today.year)
@@ -87,4 +87,11 @@
end
+ it "should not rely on app being single threaded" do
+ Date.fiscal_zone = :india
+ thread = Thread.new { Thread.current["my_fiscal_zone"] = Date.fiscal_zone }
+ thread.join
+ thread["my_fiscal_zone"].should == :india
+ end
+
end

0 comments on commit 814c56a

Please sign in to comment.