backtastic 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,9 @@ class Example.Routers.PeopleRouter extends Backbone.Router
3
3
  super
4
4
  @people = new Example.Collections.PeopleCollection(peopleJson)
5
5
  @occupations = new Example.Collections.OccupationsCollection(occupationsJson)
6
- @people.on "sync", => @navigate "people/list", trigger: true
6
+ @people.on "sync", @showPeople, @
7
+ @people.off null, null, @
8
+ => @navigate "people/list", trigger: true
7
9
  @peopleView = new Example.Views.PeopleView(collection: @people, el: $("#people_view"))
8
10
  @editPersonView = new Example.Views.EditPersonView(el: $("#edit_person"), occupations: @occupations)
9
11
  @showPeople()
@@ -1,5 +1,5 @@
1
1
  class Person < ActiveRecord::Base
2
- # validates_presence_of :first_name
2
+ validates_presence_of :first_name
3
3
 
4
4
  belongs_to :occupation
5
5
  end
@@ -0,0 +1 @@
1
+ Jasminerice::Runner.capybara_driver = :webkit
@@ -9,12 +9,17 @@ describe "Person", ->
9
9
  describe "failing validation", ->
10
10
  beforeEach ->
11
11
  @person.set first_name: "", last_name: "NotJones"
12
- it "should not be valid", ->
13
- expect(@person.isValid()).toBeFalsy()
14
12
  it "should have triggered the error event for first name", ->
15
13
  expect(@validationErrors.first_name.length).toEqual 1
16
14
  it "should have triggered the error event for last name", ->
17
15
  expect(@validationErrors.last_name.length).toEqual 1
16
+ describe "with only one attribute", ->
17
+ beforeEach ->
18
+ @person.set last_name: "Jones"
19
+ it "should only validate attributes that being set", ->
20
+ expect(@person.isValid()).toBeTruthy()
21
+ it "should have set the last name", ->
22
+ expect(@person.get("last_name")).toEqual "Jones"
18
23
  describe "with valid attributes", ->
19
24
  beforeEach ->
20
25
  @person.set first_name: "Fred", last_name: "Jones"
@@ -11,7 +11,24 @@ describe "text field view", ->
11
11
  parentView: new Example.Views.FormView
12
12
  @textFieldView.render()
13
13
  it "renders has a value", ->
14
- expect(@textFieldView.$("input[name=name]").val()).toEqual "bob"
14
+ expect(@textFieldView.$("input[name=name]").val()).toEqual "bob"
15
15
  it "puts a label on it", ->
16
16
  expect(@textFieldView.$("label[for=name]")).toExist()
17
17
  expect(@textFieldView.$("label[for=name]")).toHaveText /Name/
18
+
19
+ describe "displaying errors", ->
20
+ beforeEach ->
21
+ @textFieldView.displayErrors
22
+ name: ["totally borked"]
23
+ it "should add the error class", ->
24
+ expect(@textFieldView.$el).toHaveClass "error"
25
+ it "should add the error message", ->
26
+ expect(@textFieldView.$("span.help-inline")).toHaveText "totally borked"
27
+ describe "again", ->
28
+ beforeEach ->
29
+ @textFieldView.displayErrors
30
+ name: ["totally borked"]
31
+ it "should only display it once", ->
32
+ expect(@textFieldView.$("span.help-inline").size()).toEqual 1
33
+
34
+
@@ -27,13 +27,16 @@ Backtastic.Validation =
27
27
 
28
28
  clearErrors: -> @errors = {}
29
29
 
30
+ validateAttribute: (attribute, value) ->
31
+ return unless @constructor.validations[attribute]
32
+ for validator in @constructor.validations[attribute]
33
+ error = validator(attribute, value)
34
+ @addError(attribute, error) if error
35
+
30
36
  validate: (attributes) ->
31
37
  @clearErrors()
32
38
  return unless @constructor.validations
33
- for attr, validators of @constructor.validations
34
- for validator in validators
35
- error = validator(attr, attributes[attr])
36
- @addError(attr, error) if error
39
+ @validateAttribute(attr, value) for attr, value of attributes
37
40
  @errors if _.keys(@errors).length > 0
38
41
 
39
42
  Backtastic.include Backbone.Model, Backtastic.Validation
@@ -6,7 +6,7 @@ class Backtastic.Views.FormFieldView extends Backtastic.View
6
6
  @label = options.label
7
7
  @parentView = options.parentView
8
8
  @parentView.on "rendered", => @afterParentRender()
9
- @model.on "error", (model, errors) => @displayErrors(errors)
9
+ @model.on "error", (model, errors) => @displayErrors(errors)
10
10
 
11
11
  afterParentRender: ->
12
12
  @setElement(@parentView.$("[data-view-id=#{@cid}]"))
@@ -21,6 +21,7 @@ class Backtastic.Views.FormFieldView extends Backtastic.View
21
21
  if errors?[@field]
22
22
  messages = errors[@field]
23
23
  @$el.addClass "error"
24
+ @$("span.help-inline").remove()
24
25
  @$el.append "<span class='help-inline'>#{message}</span>" for message in messages
25
26
 
26
27
  clearErrors: ->
@@ -1,3 +1,3 @@
1
1
  module Backtastic
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1 @@
1
+ require 'backtastic'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-14 00:00:00.000000000 Z
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70247227211360 !ruby/object:Gem::Requirement
16
+ requirement: &70353452602400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70247227211360
24
+ version_requirements: *70353452602400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: pry
27
- requirement: &70247227210000 !ruby/object:Gem::Requirement
27
+ requirement: &70353452601920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70247227210000
35
+ version_requirements: *70353452601920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: haml_coffee_assets
38
- requirement: &70247227209440 !ruby/object:Gem::Requirement
38
+ requirement: &70353452601460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70247227209440
46
+ version_requirements: *70353452601460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rails-backbone
49
- requirement: &70247227208580 !ruby/object:Gem::Requirement
49
+ requirement: &70353452601000 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70247227208580
57
+ version_requirements: *70353452601000
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: inflection-js-rails
60
- requirement: &70247227223960 !ruby/object:Gem::Requirement
60
+ requirement: &70353452600580 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70247227223960
68
+ version_requirements: *70353452600580
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: twitter-bootstrap-rails
71
- requirement: &70247227222820 !ruby/object:Gem::Requirement
71
+ requirement: &70353452600020 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70247227222820
79
+ version_requirements: *70353452600020
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &70247227222140 !ruby/object:Gem::Requirement
82
+ requirement: &70353452598880 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70247227222140
90
+ version_requirements: *70353452598880
91
91
  description: ! "Create backbone twitter bootstrap form views easily using helpers.
92
92
  Handle and display\n validation failures from rails.\n "
93
93
  email:
@@ -147,6 +147,7 @@ files:
147
147
  - example/config/environments/test.rb
148
148
  - example/config/initializers/backtrace_silencers.rb
149
149
  - example/config/initializers/inflections.rb
150
+ - example/config/initializers/jasminerice_runner.rb
150
151
  - example/config/initializers/mime_types.rb
151
152
  - example/config/initializers/secret_token.rb
152
153
  - example/config/initializers/session_store.rb
@@ -199,6 +200,7 @@ files:
199
200
  - lib/assets/javascripts/views/text_field_view.coffee
200
201
  - lib/backtastic.rb
201
202
  - lib/backtastic/version.rb
203
+ - spec/spec_helper.rb
202
204
  - vendor/assets/javascripts/bootstrap-datepicker.js
203
205
  - vendor/assets/javascripts/jquery.serializeObject.js.coffee
204
206
  - vendor/assets/stylesheets/datepicker.less
@@ -214,16 +216,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
216
  - - ! '>='
215
217
  - !ruby/object:Gem::Version
216
218
  version: '0'
219
+ segments:
220
+ - 0
221
+ hash: -824130021871109077
217
222
  required_rubygems_version: !ruby/object:Gem::Requirement
218
223
  none: false
219
224
  requirements:
220
225
  - - ! '>='
221
226
  - !ruby/object:Gem::Version
222
227
  version: '0'
228
+ segments:
229
+ - 0
230
+ hash: -824130021871109077
223
231
  requirements: []
224
232
  rubyforge_project:
225
233
  rubygems_version: 1.8.17
226
234
  signing_key:
227
235
  specification_version: 3
228
236
  summary: Formtastic meets backbone.. ish.
229
- test_files: []
237
+ test_files:
238
+ - spec/spec_helper.rb