This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| 727e04e0 » | markbates | 2008-08-08 | 1 | require 'pathname' | |
| 2 | require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper' | ||||
| 3 | |||||
| 4 | describe Mack::ViewHelpers::FormHelpers do | ||||
| 5 | include Mack::ViewHelpers | ||||
| 6 | |||||
| 25aed197 » | markbates | 2008-08-14 | 7 | class Cop | |
| 8 | attr_accessor :full_name | ||||
| 9 | attr_accessor :level | ||||
| 10 | attr_accessor :tos | ||||
| 11 | attr_accessor :bio_file | ||||
| 12 | end | ||||
| 13 | |||||
| 14 | before(:each) do | ||||
| 15 | @cop = Cop.new | ||||
| 16 | @cop.full_name = "ness" | ||||
| 17 | @cop.level = 1 | ||||
| 18 | @cop.bio_file = "~/bio.doc" | ||||
| 19 | @simple = "hi" | ||||
| 20 | @default_file = "~/resume.doc" | ||||
| 620bd22d » | markbates | 2008-08-14 | 21 | @select_options = [["one", 1], ["two", 2], ["three", 3]] | |
| 25aed197 » | markbates | 2008-08-14 | 22 | end | |
| 23 | |||||
| 24 | describe "check_box" do | ||||
| 25 | |||||
| 26 | it "should create a nested checkbox for a model" do | ||||
| 27 | check_box(:cop, :tos).should == %{<input id="cop_tos" name="cop[tos]" type="checkbox" />} | ||||
| 28 | end | ||||
| 29 | |||||
| 30 | it "should create a non-nested checkbox for a simple object" do | ||||
| 31 | check_box(:simple).should == %{<input checked="checked" id="simple" name="simple" type="checkbox" />} | ||||
| 32 | end | ||||
| 33 | |||||
| 34 | it "should create a non-nested checkbox for just a symbol" do | ||||
| 35 | check_box(:unknown).should == %{<input id="unknown" name="unknown" type="checkbox" />} | ||||
| 36 | end | ||||
| 37 | |||||
| 38 | it "should be checked if the value is true" do | ||||
| 39 | @cop.tos = true | ||||
| 40 | check_box(:cop, :tos).should == %{<input checked="checked" id="cop_tos" name="cop[tos]" type="checkbox" />} | ||||
| 41 | end | ||||
| 42 | |||||
| 43 | it "should be unchecked if the value is false" do | ||||
| 44 | @cop.tos = false | ||||
| 45 | check_box(:cop, :tos).should == %{<input id="cop_tos" name="cop[tos]" type="checkbox" />} | ||||
| 46 | end | ||||
| 47 | |||||
| 48 | end | ||||
| 49 | |||||
| 50 | describe "file_field" do | ||||
| 51 | |||||
| 52 | it "should create a nested file_field for a model" do | ||||
| 53 | file_field(:cop, :bio_file).should == %{<input id="cop_bio_file" name="cop[bio_file]" type="file" value="~/bio.doc" />} | ||||
| 54 | end | ||||
| 55 | |||||
| 56 | it "should create a non-nested file_field for a simple object" do | ||||
| 57 | file_field(:default_file).should == %{<input id="default_file" name="default_file" type="file" value="~/resume.doc" />} | ||||
| 58 | end | ||||
| 59 | |||||
| 60 | it "should create a non-nested file_field for just a symbol" do | ||||
| 61 | file_field(:unknown).should == %{<input id="unknown" name="unknown" type="file" />} | ||||
| 62 | end | ||||
| 63 | |||||
| 64 | it "should create a nested file_field for a model with an empty value if value is false" do | ||||
| 65 | @cop.bio_file = nil | ||||
| 66 | file_field(:cop, :bio_file).should == %{<input id="cop_bio_file" name="cop[bio_file]" type="file" value="" />} | ||||
| 67 | end | ||||
| 68 | |||||
| 69 | end | ||||
| 70 | |||||
| 71 | describe "hidden_field" do | ||||
| 72 | |||||
| 73 | it "should create a nested hidden_field for a model" do | ||||
| 74 | hidden_field(:cop, :full_name).should == %{<input id="cop_full_name" name="cop[full_name]" type="hidden" value="ness" />} | ||||
| 75 | end | ||||
| 76 | |||||
| 77 | it "should create a non-nested hidden_field for a simple object" do | ||||
| 78 | hidden_field(:simple).should == %{<input id="simple" name="simple" type="hidden" value="hi" />} | ||||
| 79 | end | ||||
| 80 | |||||
| 81 | it "should create a non-nested hidden_field for just a symbol" do | ||||
| 82 | hidden_field(:unknown).should == %{<input id="unknown" name="unknown" type="hidden" />} | ||||
| 83 | end | ||||
| 84 | |||||
| 85 | it "should create a nested hidden_field for a model with an empty value if value is false" do | ||||
| 86 | @cop.full_name = nil | ||||
| 87 | hidden_field(:cop, :full_name).should == %{<input id="cop_full_name" name="cop[full_name]" type="hidden" value="" />} | ||||
| 88 | end | ||||
| 89 | |||||
| 90 | end | ||||
| 91 | |||||
| 92 | describe "password_field" do | ||||
| 93 | |||||
| 94 | it "should create a nested password_field for a model" do | ||||
| 95 | password_field(:cop, :full_name).should == %{<input id="cop_full_name" name="cop[full_name]" type="password" value="ness" />} | ||||
| 96 | end | ||||
| 97 | |||||
| 98 | it "should create a non-nested password_field for a simple object" do | ||||
| 99 | password_field(:simple).should == %{<input id="simple" name="simple" type="password" value="hi" />} | ||||
| 100 | end | ||||
| 101 | |||||
| 102 | it "should create a non-nested password_field for just a symbol" do | ||||
| 103 | password_field(:unknown).should == %{<input id="unknown" name="unknown" type="password" />} | ||||
| 104 | end | ||||
| 105 | |||||
| 106 | it "should create a nested password_field for a model with an empty value if value is false" do | ||||
| 107 | @cop.full_name = nil | ||||
| 108 | password_field(:cop, :full_name).should == %{<input id="cop_full_name" name="cop[full_name]" type="password" value="" />} | ||||
| 109 | end | ||||
| 110 | |||||
| 111 | end | ||||
| 112 | |||||
| 113 | describe "image_submit" do | ||||
| 114 | |||||
| 115 | it "should create an image submit tag" do | ||||
| 116 | image_submit("login.png").should == %{<input src="/images/login.png" type="image" />} | ||||
| 117 | image_submit("purchase.png", :disabled => true).should == %{<input disabled="disabled" src="/images/purchase.png" type="image" />} | ||||
| 118 | image_submit("search.png", :class => 'search-button').should == %{<input class="search-button" src="/images/search.png" type="image" />} | ||||
| 119 | end | ||||
| 120 | |||||
| 121 | end | ||||
| 122 | |||||
| 53d126e1 » | markbates | 2008-08-14 | 123 | describe "label_tag" do | |
| 25aed197 » | markbates | 2008-08-14 | 124 | ||
| 125 | it "should create a nested label for a model" do | ||||
| 53d126e1 » | markbates | 2008-08-14 | 126 | label_tag(:cop, :full_name).should == %{<label for="cop_full_name">Full name</label>} | |
| 25aed197 » | markbates | 2008-08-14 | 127 | end | |
| 128 | |||||
| 129 | it "should create a non-nested label for a simple object" do | ||||
| 53d126e1 » | markbates | 2008-08-14 | 130 | label_tag(:simple).should == %{<label for="simple">Simple</label>} | |
| 25aed197 » | markbates | 2008-08-14 | 131 | end | |
| 132 | |||||
| 133 | it "should create a non-nested label for just a symbol" do | ||||
| 53d126e1 » | markbates | 2008-08-14 | 134 | label_tag(:unknown).should == %{<label for="unknown">Unknown</label>} | |
| 25aed197 » | markbates | 2008-08-14 | 135 | end | |
| 136 | |||||
| 137 | it "should create a non-nested label for just a symbol" do | ||||
| 53d126e1 » | markbates | 2008-08-14 | 138 | label_tag(:unknown).should == %{<label for="unknown">Unknown</label>} | |
| 25aed197 » | markbates | 2008-08-14 | 139 | end | |
| 140 | |||||
| 141 | it "should create a non-nested label and use :value for it's content" do | ||||
| 53d126e1 » | markbates | 2008-08-14 | 142 | label_tag(:unknown, :value => "My Label").should == %{<label for="unknown">My Label</label>} | |
| 25aed197 » | markbates | 2008-08-14 | 143 | end | |
| 144 | |||||
| 145 | it "should create a non-nested label and use :for for it's for" do | ||||
| 53d126e1 » | markbates | 2008-08-14 | 146 | label_tag(:unknown, :for => "my_label").should == %{<label for="my_label">Unknown</label>} | |
| 25aed197 » | markbates | 2008-08-14 | 147 | end | |
| 148 | |||||
| 149 | end | ||||
| 150 | |||||
| 151 | describe "radio_button" do | ||||
| 152 | |||||
| 153 | it "should create a nested radio_button for a model" do | ||||
| d83e931e » | markbates | 2008-08-14 | 154 | radio_button(:cop, :level).should == %{<input checked="checked" id="cop_level" name="cop[level]" type="radio" value="1" />} | |
| 155 | radio_button(:cop, :level, :value => "twoa").should == %{<input id="cop_level" name="cop[level]" type="radio" value="twoa" />} | ||||
| 25aed197 » | markbates | 2008-08-14 | 156 | end | |
| 157 | |||||
| 158 | it "should create a non-nested radio_button for a simple object" do | ||||
| d83e931e » | markbates | 2008-08-14 | 159 | radio_button(:simple).should == %{<input checked="checked" id="simple" name="simple" type="radio" value="hi" />} | |
| 160 | radio_button(:simple, :value => "twob").should == %{<input id="simple" name="simple" type="radio" value="twob" />} | ||||
| 25aed197 » | markbates | 2008-08-14 | 161 | end | |
| 162 | |||||
| 163 | it "should create a non-nested radio_button for just a symbol" do | ||||
| d83e931e » | markbates | 2008-08-14 | 164 | radio_button(:unknown).should == %{<input id="unknown" name="unknown" type="radio" value="" />} | |
| 165 | radio_button(:unknown, :value => "twoc").should == %{<input id="unknown" name="unknown" type="radio" value="twoc" />} | ||||
| 166 | radio_button(:unknown, :value => "twod", :checked => true).should == %{<input checked="checked" id="unknown" name="unknown" type="radio" value="twod" />} | ||||
| 25aed197 » | markbates | 2008-08-14 | 167 | end | |
| 168 | |||||
| 169 | end | ||||
| 170 | |||||
| 7201f443 » | markbates | 2008-08-14 | 171 | describe "select_tag" do | |
| 25aed197 » | markbates | 2008-08-14 | 172 | ||
| 620bd22d » | markbates | 2008-08-14 | 173 | it "should create a nested select tag for a model" do | |
| 7201f443 » | markbates | 2008-08-14 | 174 | select_tag(:cop, :level).should == %{<select id="cop_level" name="cop[level]"></select>} | |
| 620bd22d » | markbates | 2008-08-14 | 175 | end | |
| 176 | |||||
| 177 | it "should create a non-nested select tag for a simple model" do | ||||
| 7201f443 » | markbates | 2008-08-14 | 178 | select_tag(:simple).should == %{<select id="simple" name="simple"></select>} | |
| 620bd22d » | markbates | 2008-08-14 | 179 | end | |
| 180 | |||||
| 181 | it "should build the options from a given array of arrays" do | ||||
| 7201f443 » | markbates | 2008-08-14 | 182 | select_tag(:simple, :options => @select_options).should == %{<select id="simple" name="simple"><option value="1" >one</option><option value="2" >two</option><option value="3" >three</option></select>} | |
| 620bd22d » | markbates | 2008-08-14 | 183 | end | |
| 184 | |||||
| 185 | it "should build the options from a given hash" do | ||||
| 7201f443 » | markbates | 2008-08-14 | 186 | select_tag(:simple, :options => {"one" => 1, "two" => 2, "three" => 3}).should == %{<select id="simple" name="simple"><option value="1" >one</option><option value="3" >three</option><option value="2" >two</option></select>} | |
| 620bd22d » | markbates | 2008-08-14 | 187 | end | |
| 188 | |||||
| 189 | it "should mark an option as selected if the model has it seleceted" do | ||||
| 7201f443 » | markbates | 2008-08-14 | 190 | select_tag(:cop, :level, :options => @select_options).should == %{<select id="cop_level" name="cop[level]"><option value="1" selected>one</option><option value="2" >two</option><option value="3" >three</option></select>} | |
| 620bd22d » | markbates | 2008-08-14 | 191 | end | |
| 192 | |||||
| 193 | it "should mark an option as selected if the selected options is available" do | ||||
| 7201f443 » | markbates | 2008-08-14 | 194 | select_tag(:simple, :options => @select_options, :selected => 1).should == %{<select id="simple" name="simple"><option value="1" selected>one</option><option value="2" >two</option><option value="3" >three</option></select>} | |
| 620bd22d » | markbates | 2008-08-14 | 195 | end | |
| 196 | |||||
| 25aed197 » | markbates | 2008-08-14 | 197 | end | |
| 198 | |||||
| 199 | describe "text_area" do | ||||
| 200 | |||||
| 201 | it "should create a nested text_area for a model" do | ||||
| b9bda035 » | markbates | 2008-08-15 | 202 | text_area(:cop, :full_name).should == %{<textarea cols="60" id="cop_full_name" name="cop[full_name]" rows="20">ness</textarea>} | |
| 25aed197 » | markbates | 2008-08-14 | 203 | end | |
| 204 | |||||
| 205 | it "should create a non-nested text_area for a simple object" do | ||||
| b9bda035 » | markbates | 2008-08-15 | 206 | text_area(:simple).should == %{<textarea cols="60" id="simple" name="simple" rows="20">hi</textarea>} | |
| 25aed197 » | markbates | 2008-08-14 | 207 | end | |
| 208 | |||||
| 209 | it "should create a non-nested text_area for just a symbol" do | ||||
| b9bda035 » | markbates | 2008-08-15 | 210 | text_area(:unknown).should == %{<textarea cols="60" id="unknown" name="unknown" rows="20"></textarea>} | |
| 211 | text_area(:unknown, :value => "hi there").should == %{<textarea cols="60" id="unknown" name="unknown" rows="20">hi there</textarea>} | ||||
| 25aed197 » | markbates | 2008-08-14 | 212 | end | |
| 213 | |||||
| 214 | it "should create a nested text_area for a model with an empty value if value is false" do | ||||
| 215 | @cop.full_name = nil | ||||
| b9bda035 » | markbates | 2008-08-15 | 216 | text_area(:cop, :full_name).should == %{<textarea cols="60" id="cop_full_name" name="cop[full_name]" rows="20"></textarea>} | |
| 25aed197 » | markbates | 2008-08-14 | 217 | end | |
| 218 | |||||
| 219 | end | ||||
| 220 | |||||
| 221 | describe "text_field" do | ||||
| 222 | |||||
| 223 | it "should create a nested text_field for a model" do | ||||
| 224 | text_field(:cop, :full_name).should == %{<input id="cop_full_name" name="cop[full_name]" type="text" value="ness" />} | ||||
| 225 | end | ||||
| 226 | |||||
| 227 | it "should create a non-nested text_field for a simple object" do | ||||
| 228 | text_field(:simple).should == %{<input id="simple" name="simple" type="text" value="hi" />} | ||||
| 229 | end | ||||
| 230 | |||||
| 231 | it "should create a non-nested text_field for just a symbol" do | ||||
| 232 | text_field(:unknown).should == %{<input id="unknown" name="unknown" type="text" />} | ||||
| 233 | end | ||||
| 234 | |||||
| 235 | it "should create a nested text_field for a model with an empty value if value is false" do | ||||
| 236 | @cop.full_name = nil | ||||
| 237 | text_field(:cop, :full_name).should == %{<input id="cop_full_name" name="cop[full_name]" type="text" value="" />} | ||||
| 238 | end | ||||
| 239 | |||||
| 240 | end | ||||
| 241 | |||||
| 242 | |||||
| 727e04e0 » | markbates | 2008-08-08 | 243 | describe "form" do | |
| 244 | include CommonHelpers | ||||
| 245 | |||||
| 246 | it "should generate proper form tags" do | ||||
| 247 | tmp = <<-EOF | ||||
| 248 | <% form("http://www.mackframework.com") do %> | ||||
| 249 | Hello | ||||
| 250 | <% end %> | ||||
| 251 | EOF | ||||
| 252 | erb(tmp).should == "<form action=\"http://www.mackframework.com\" method=\"post\">\nHello\n</form>" | ||||
| 253 | tmp = <<-EOF | ||||
| 254 | <% form("http://www.mackframework.com", :multipart => true) do %> | ||||
| 255 | Hello | ||||
| 256 | <% end %> | ||||
| 257 | EOF | ||||
| 258 | erb(tmp).should == "<form action=\"http://www.mackframework.com\" enctype=\"multipart/form-data\" method=\"post\">\nHello\n</form>" | ||||
| 259 | tmp = <<-EOF | ||||
| 260 | <% form("http://www.mackframework.com", :id => "my_form") do %> | ||||
| 261 | Hello | ||||
| 262 | <% end %> | ||||
| 263 | EOF | ||||
| 264 | erb(tmp).should == "<form action=\"http://www.mackframework.com\" class=\"my_form\" id=\"my_form\" method=\"post\">\nHello\n</form>" | ||||
| 265 | |||||
| 266 | tmp = <<-EOF | ||||
| 267 | <% form("http://www.mackframework.com", :id => "my_form", :method => :get) do %> | ||||
| 268 | Hello | ||||
| 269 | <% end %> | ||||
| 270 | EOF | ||||
| 271 | erb(tmp).should == "<form action=\"http://www.mackframework.com\" class=\"my_form\" id=\"my_form\" method=\"get\">\nHello\n</form>" | ||||
| 272 | tmp = <<-EOF | ||||
| 273 | <% form("http://www.mackframework.com", :id => "my_form", :method => :put) do %> | ||||
| 274 | Hello | ||||
| 275 | <% end %> | ||||
| 276 | EOF | ||||
| 277 | erb(tmp).should == "<form action=\"http://www.mackframework.com\" class=\"my_form\" id=\"my_form\" method=\"post\">\n<input name=\"_method\" type=\"hidden\" value=\"put\" />\nHello\n</form>" | ||||
| 278 | end | ||||
| 279 | |||||
| 280 | end | ||||
| 281 | |||||
| 7201f443 » | markbates | 2008-08-14 | 282 | describe "submit_button" do | |
| 727e04e0 » | markbates | 2008-08-08 | 283 | ||
| 284 | it "should build a simple submit tag" do | ||||
| 7201f443 » | markbates | 2008-08-14 | 285 | submit_button.should == %{<input type="submit" value="Submit" />} | |
| 727e04e0 » | markbates | 2008-08-08 | 286 | end | |
| 287 | |||||
| 288 | it "should allow you to change the value" do | ||||
| 7201f443 » | markbates | 2008-08-14 | 289 | submit_button("Login").should == %{<input type="submit" value="Login" />} | |
| 727e04e0 » | markbates | 2008-08-08 | 290 | end | |
| 291 | |||||
| 292 | it "should take options" do | ||||
| 7201f443 » | markbates | 2008-08-14 | 293 | submit_button("Login", {:class => :foo}).should == %{<input class="foo" type="submit" value="Login" />} | |
| 727e04e0 » | markbates | 2008-08-08 | 294 | end | |
| 295 | |||||
| 296 | end | ||||
| 297 | |||||
| 298 | end | ||||








