Permalink
Browse files

+ Fixed functions that was not applying not continuing to apply if so…

…meone was invalid.
  • Loading branch information...
1 parent d030001 commit 7fc43f3b4a000bbde143804a9985769f40a25876 @wbotelhos committed May 4, 2012
Showing with 52 additions and 4 deletions.
  1. +4 −4 js/jquery.raty.js
  2. +48 −0 test/spec.js
View
@@ -6,7 +6,7 @@
*
* Licensed under The MIT License
*
- * @version 2.4.0
+ * @version 2.4.3
* @since 2010.06.11
* @author Washington Botelho
* @documentation wbotelhos.com/raty
@@ -186,7 +186,7 @@
$this = $(self);
if ($this.data('readonly') == 'readonly') {
- return false;
+ return this;
}
if (isClick) {
@@ -200,7 +200,7 @@
}, click: function(score) {
return $(this).each(function() {
if ($(this).data('readonly') == 'readonly') {
- return false;
+ return this;
}
methods.initialize.call(this, score);
@@ -339,7 +339,7 @@
}, setScore: function(score) {
return $(this).each(function() {
if ($(this).data('readonly') == 'readonly') {
- return false;
+ return this;
}
methods.initialize.call(this, score);
View
@@ -2923,4 +2923,52 @@ describe('Using function with class', function() {
expect(imgs3.eq(4)).toHaveAttr('src', 'img/star-off.png');
});
+ it ('[score] should set score on rating that is not read-only', function() {
+ // given
+ var stars = $('.star');
+
+ stars.raty();
+ stars.eq(1).raty('readOnly', true);
+
+ // when
+ stars.raty('score', 2);
+
+ // then
+ expect(stars.eq(0).children('input')).toHaveValue('2');
+ expect(stars.eq(1).children('input').val()).toEqual('');
+ expect(stars.eq(2).children('input')).toHaveValue('2');
+ });
+
+ it ('[click] should click on rating that is not read-only', function() {
+ // given
+ var stars = $('.star');
+
+ stars.raty({ click: function() { } });
+ stars.eq(1).raty('readOnly', true);
+
+ // when
+ stars.raty('click', 2);
+
+ // then
+ expect(stars.eq(0).children('input')).toHaveValue('2');
+ expect(stars.eq(1).children('input').val()).toEqual('');
+ expect(stars.eq(2).children('input')).toHaveValue('2');
+ });
+
+ it ('[cancel] should cancel all rating that is not read-only', function() {
+ // given
+ var stars = $('.star');
+
+ stars.raty({ score: 2 });
+ stars.eq(1).raty('readOnly', true);
+
+ // when
+ stars.raty('cancel');
+
+ // then
+ expect(stars.eq(0).children('input').val()).toEqual('');
+ expect(stars.eq(1).children('input')).toHaveValue('2');
+ expect(stars.eq(2).children('input').val()).toEqual('');
+ });
+
});

0 comments on commit 7fc43f3

Please sign in to comment.