# Tying into SiteController - Specs Failing

**URL:** <https://www.ruby-forum.com/t/tying-into-sitecontroller-specs-failing/137252>\
**Category:** Radiant CMS\
**Created:** [May 10, 2008, 6:51pm UTC](https://www.ruby-forum.com/t/tying-into-sitecontroller-specs-failing/137252 "2008-05-10T18:51:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [May 10, 2008, 6:51pm UTC](https://www.ruby-forum.com/t/tying-into-sitecontroller-specs-failing/137252/1 "2008-05-10T18:51:08Z")

</div>

Ok, I’ve got a weird one here. In an extension, I’m attempting to add a  
method or two to SiteController. I do this in the extension activate  
method like:

def activate  
SiteController.send :include, SiteControllerMods  
end

Then, in /lib/site\_controller\_mods.rb I define a module to add methods,  
like:

module SiteControllerMods  
end

Even without adding any methods, Radiant doesn’t like this – the  
built-in SiteController specs start to fail left and right. I’ve used  
this approach in the past and it worked just fine – what changed with  
0.6.6?

Could this be something to do with Rails 2.0? Or maybe a conflict with  
rSpec?

Is there a better approach?

-Chris

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [May 11, 2008, 3:59am UTC](https://www.ruby-forum.com/t/tying-into-sitecontroller-specs-failing/137252/2 "2008-05-11T03:59:52Z")

</div>

I just added a module to the SiteController the other day for the  
first time (thanks Cribbs). I overwrite one of the methods actually.  
Here is a sample of my module:

module TunaSiteOverride  
def self.included(base)  
base.class\_eval do  
alias\_method\_chain :show\_page, :tuna\_site\_override  
end  
end

def show\_page\_with\_ tuna\_site\_override  
# Code in here  
end  
end

And here is my extension:

class TunaExtension \< Radiant::Extension  
def activate  
SiteController.send :include, TunaSiteOverride  
end  
end

What are the exact errors you are getting? I am curious as to where  
it is failing in the SiteController. As for what is new in 0.6.6, no  
clue. I am JUST starting to hack into it 🙂

On Sat, May 10, 2008 at 12:50 PM, Chris P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there a better approach?
> 
> -Chris
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
\m/^.^\m/  
“Some scientists claim that hydrogen,  
because it is so plentiful, is the basic building block of the universe.  
I dispute that.  
I say that there is more stupidity than hydrogen,  
and that is the basic building block of the universe.”  
-Frank Zappa

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [May 11, 2008, 5:06am UTC](https://www.ruby-forum.com/t/tying-into-sitecontroller-specs-failing/137252/3 "2008-05-11T05:06:32Z")

</div>

Well, I was having problems with my tests where:  
get :my\_method, :other\_params

Just wasn’t seeming to trigger my method. When I ran “rake  
spec:controllers” it turns out that Radiant’s site\_controller\_spec.rb  
would fail all over the place too – errors tied to checking the  
response (success expected but was fail, etc).This would happen even if  
I didn’t declare any methods – just mixed in the code. Remove the  
include line from the extension\_name.rb file and all was well.

Since I’m writing this extension BDD style, I didn’t even bother to fire  
up a server (I don’t have any views yet anyway) so I don’t know if this  
would have run fine and that the errors might just be a testing setup  
thing… As I mentioned originally, perhaps this is a case of the rSpec  
mixins fighting with mine.

My other thought was that possibly something special was needed to  
properly declare the controller and response objects – that rSpec  
wasn’t doing it’s magic just right given my spec name or something. (in  
fact, I wound up moving my spec to  
/specs/controllers/site\_controller\_mods.rb to get some of the tests to  
pass).

Anyway, since then, I altered my approach to allow me to create my own  
controller that inherits from SiteController so my problems have gone  
away on their own. I would love to know what was up here, though.

-Chris
