Skip to content
Browse files

Fix threading issue

  • Loading branch information...
1 parent fb6680f commit 82417e69bbb184fccd6dca81df9801dc58a371a1 Rachel Shallit 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
View
12 lib/rising_sun/fiscali.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)
View
7 spec/fiscali_spec.rb
@@ -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 82417e6

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