forked from lenorris/rails-int
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tero Parviainen
committed
Mar 13, 2012
1 parent
ba5423d
commit 4d1affa
Showing
7 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,7 @@ group :test do | |
gem 'shoulda' | ||
end | ||
|
||
group :development, :test do | ||
gem 'jasminerice' | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
$(function() { | ||
var searchForm = $('#search-form'); | ||
var searchField = $('#query'); | ||
var checkedRadio = $('.query-by:checked'); | ||
|
||
searchField.attr('placeholder', 'Search by '+$(checkedRadio).val()); | ||
|
||
$('.query-by').live('click', function() { | ||
$(document).on('click', '.query-by', function() { | ||
var value = $(this).val(); | ||
var searchField = $('#query'); | ||
searchField.attr('placeholder', 'Search by '+value); | ||
if (searchField.val() !== '') { | ||
searchForm.submit(); | ||
$('#search-form').submit(); | ||
} | ||
}); | ||
|
||
searchForm.live('ajax:success', function(evt, data, status, xhr) { | ||
$(document).on('ajax:success', '#search-form', function(evt, data, status, xhr) { | ||
$('#book-list').html(data); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//= require books | ||
|
||
describe("books.js", function() { | ||
|
||
beforeEach(function() { | ||
loadFixtures("book_search"); | ||
}); | ||
|
||
it("should set the search field placeholder to match the value of a clicked radio", function() { | ||
$('#query-by-isbn').click(); | ||
|
||
expect($('#query').attr('placeholder')).toEqual("Search by isbn"); | ||
}); | ||
|
||
it("should submit the search form when a radio is clicked, if the search field is not empty", function() { | ||
var submitSpy = jasmine.createSpy().andReturn(false); | ||
$('#search-form').on('submit', submitSpy); | ||
|
||
$('#query').val('my search term'); | ||
$('#query-by-isbn').click(); | ||
|
||
expect(submitSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should not submit the search form when a radio is clicked, if the search field is empty", function() { | ||
var submitSpy = jasmine.createSpy().andReturn(false); | ||
$('#search-form').on('submit', submitSpy); | ||
|
||
$('#query').val(''); | ||
$('#query-by-isbn').click(); | ||
|
||
expect(submitSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should replace the contents of the book list when the search form gets a response", function() { | ||
var newHtml = "<h2>New contents</h2>"; | ||
|
||
$('#search-form').trigger('ajax:success', newHtml); | ||
|
||
expect($('#book-list').html()).toEqual(newHtml); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<form id="search-form"> | ||
<input id="query" type="search" placeholder="Initial"> | ||
|
||
<input id="query-by-title" class="query-by" type="radio" value="title" checked> | ||
<input id="query-by-isbn" class="query-by" type="radio" value="isbn"> | ||
|
||
</form> | ||
|
||
<div id="book-list"> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//= require jquery | ||
//= require jquery_ujs | ||
//= require_tree ./ |