Skip to content

Commit

Permalink
fix checkbox helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Jan 15, 2009
1 parent 715bd54 commit c9d35f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/integrity/helpers.rb
Expand Up @@ -119,8 +119,8 @@ def error_class(object, field)

def checkbox(name, condition, extras={})
attrs = { :name => name, :type => "checkbox", :value => "1" }
attrs.merge(condition ? { :checked => "checked" } : {})
attrs.merge(extras)
attrs[:checked] = !!condition
attrs.update(extras)
end

def bash_color_codes(string)
Expand Down
16 changes: 16 additions & 0 deletions test/acceptance/edit_project_test.rb
Expand Up @@ -62,6 +62,22 @@ class EditProjectTest < Test::Unit::AcceptanceTestCase
response_body.should have_tag("a", /My Test Project/)
end

scenario "public projects have a ticked 'public' checkbox on edit form" do
Project.generate(:my_test_project, :public => true)
disable_auth!
visit "/my-test-project/edit"

response_body.should have_tag('input[@type="checkbox"][@checked="checked"][@name="project_data[public]"]')
end

scenario "private projects have an unticked 'public' checkbox on edit form" do
Project.generate(:my_test_project, :public => false)
disable_auth!
visit "/my-test-project/edit"

response_body.should_not have_tag('input[@type="checkbox"][@checked][@name="project_data[public]"]')
end

scenario "a user can't edit a project's information" do
Project.generate(:integrity)

Expand Down

1 comment on commit c9d35f5

@foca
Copy link

@foca foca commented on c9d35f5 Jan 26, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, in XHTML, if you put the “checked” attribute, it has to have a “checked” value (so checked=“checked”). In HTML, only the attribute name is needed, so having an empty attribute will still count as always “checked”.

Either way, this does not work as expected.

Please sign in to comment.