Skip to content

Commit

Permalink
Merge pull request #3 from rshallit/master
Browse files Browse the repository at this point in the history
Proposed fix for threading issue
  • Loading branch information
asanghi committed Jul 12, 2012
2 parents fb6680f + 82417e6 commit 814c56a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/rising_sun/fiscali.rb
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions spec/fiscali_spec.rb
Expand Up @@ -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.