On Oct 21, 2009, at 8:08 AM, Tom Hoen wrote:
My site allows users to change the backround color (among other
things) for their page. These values are stored in database.
Their choices (or the default) are placed on the page using a
<style> block at the end of the <head> block in the layout. Here is
what the style block looks like.
<% if !!school %>
<style>
div#header {
color: #<%= (!!school.school_name_color and !
school.school_name_color.blank?) ? school.school_name_color :
"ffffff" %>;
background-color: #<%= (!!school.header_color and !
school.header_color.blank?) ? school.header_color : "6FA9C7" %>;
}
div#header a {
color: #<%= (!!school.school_name_color and !
school.school_name_color.blank?) ? school.school_name_color :
"ffffff" %>;
}
</style>
<% end %>
Can anyone suggest how to verify that the <div id=’header’> is
assigned the css attribute color: #ffffff or color: #<%
school.header_color%>.
I'd move all of this logic to a helper, where it is way easier to spec:
describe WhateverHelper do
context "with a school" do
it "renders the color for that school" do
school = ... # whatever a school is
helper.color_for(school).should == ...
end
end
context "without a school" do
...
end
end
Now you can do this in the view:
<% if !!school %>
<style>
div#header {
color: #<%= color_for(school) %>;
background-color: #<%= header_color_for(school) %>;
}
div#header a {
color: #<%= color_for(school) %>;
}
</style>
<% end %>
HTH,
David
Best,
Tom
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
Cheers,
David
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users