# Sharing Methods Across Fixtures

**URL:** <https://www.ruby-forum.com/t/sharing-methods-across-fixtures/147642>\
**Category:** Rails\
**Created:** [September 3, 2008, 10:35pm UTC](https://www.ruby-forum.com/t/sharing-methods-across-fixtures/147642 "2008-09-03T22:35:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [September 3, 2008, 10:35pm UTC](https://www.ruby-forum.com/t/sharing-methods-across-fixtures/147642/1 "2008-09-03T22:35:55Z")

</div>

I’ve got a fixture where a couple methods are defined in the top of the  
fixture that take an argument and return a date. Does anybody have any  
idea where can I put these methods (test\_helper.rb doesn’t seem to work)  
that they will be available to all my fixtures?

## Here’s a copy of the fixture file that demonstrates what I’m doing. I want to move the start\_date and end\_date methods off to some appropriate place that will be accessible to ALL of my fixtures

# Read about fixtures at [http://ar.rubyonrails.org/classes/Fixtures.html](http://ar.rubyonrails.org/classes/Fixtures.html)

\<%  
def start\_date(offset = 0)  
#September first of _ **this calendar** _ year  
sepone = Date.new(Time.now.year,9,1)

```
#Year of first day of school for ***offset school*** year
start_year = (sepone <= Date.today ? Time.now.year :

```

Time.now.year-1)+offset

```
#Start date of school for ***offset school*** year.
Date.new(start_year,9,1)

```

end

def end\_date(offset = 0)  
start\_date(offset)+1.year-1.day  
end  
%\>  
past:  
start\_dt: \<%= start\_date(-2) %\>  
end\_dt: \<%= end\_date(-2) %\>  
previous:  
start\_dt: \<%= start\_date(-1) %\>  
end\_dt: \<%= end\_date(-1) %\>  
current:  
start\_dt: \<%= start\_date() %\>  
end\_dt: \<%= end\_date() %\>  
next:  
start\_dt: \<%= start\_date(+1) %\>  
end\_dt: \<%= end\_date(+1) %\>  
future:  
start\_dt: \<%= start\_date(+2) %\>  
end\_dt: \<%= end\_date(+2) %\>

–

[http://www.5valleys.com/](http://www.5valleys.com/)

[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [September 3, 2008, 10:44pm UTC](https://www.ruby-forum.com/t/sharing-methods-across-fixtures/147642/2 "2008-09-03T22:44:08Z")

</div>

Uhhh, nevermind. Putting the method in test\_helper.rb, but not inside  
any other classes, seems to do the trick.

Jon G. wrote:

> \<%  
> end  
> end\_dt: \<%= end\_date(-1) %\>

–

[http://www.5valleys.com/](http://www.5valleys.com/)

[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)
