simple_update_field 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/Gemfile +0 -19
  2. data/Gemfile.lock +0 -150
  3. data/README.creole +102 -0
  4. data/Rakefile +3 -9
  5. data/VERSION +1 -1
  6. data/lib/simple_update_field.rb +0 -8
  7. data/simple_update_field.gemspec +7 -81
  8. data/spec/{lib/simple_update_field_spec.rb → simple_update_field_spec.rb} +2 -1
  9. data/spec/spec_helper.rb +8 -28
  10. metadata +16 -162
  11. data/.rvmrc +0 -1
  12. data/README.rdoc +0 -25
  13. data/app/assets/images/rails.png +0 -0
  14. data/app/assets/javascripts/application.js +0 -14
  15. data/app/assets/stylesheets/application.css +0 -7
  16. data/app/controllers/application_controller.rb +0 -3
  17. data/app/controllers/phrases_controller.rb +0 -12
  18. data/app/helpers/application_helper.rb +0 -2
  19. data/app/mailers/.gitkeep +0 -0
  20. data/app/models/.gitkeep +0 -0
  21. data/app/models/phrase.rb +0 -4
  22. data/app/views/layouts/application.html.erb +0 -14
  23. data/app/views/phrases/_phrase.html.erb +0 -8
  24. data/app/views/phrases/index.html.erb +0 -1
  25. data/config.ru +0 -4
  26. data/config/application.rb +0 -54
  27. data/config/boot.rb +0 -6
  28. data/config/database.yml +0 -25
  29. data/config/environment.rb +0 -5
  30. data/config/environments/development.rb +0 -30
  31. data/config/environments/production.rb +0 -60
  32. data/config/environments/test.rb +0 -42
  33. data/config/initializers/backtrace_silencers.rb +0 -7
  34. data/config/initializers/inflections.rb +0 -10
  35. data/config/initializers/mime_types.rb +0 -5
  36. data/config/initializers/secret_token.rb +0 -7
  37. data/config/initializers/session_store.rb +0 -8
  38. data/config/initializers/wrap_parameters.rb +0 -14
  39. data/config/locales/en.yml +0 -5
  40. data/config/routes.rb +0 -4
  41. data/db/migrate/20120213182817_create_phrases.rb +0 -9
  42. data/db/schema.rb +0 -22
  43. data/db/seeds.rb +0 -7
  44. data/lib/assets/.gitkeep +0 -0
  45. data/lib/tasks/.gitkeep +0 -0
  46. data/lib/tasks/admin.rake +0 -9
  47. data/lib/tasks/jasmine.rake +0 -8
  48. data/script/rails +0 -6
  49. data/spec/controllers/phrases_controller_spec.rb +0 -22
  50. data/spec/javascripts/editable_list_spec.js +0 -411
  51. data/spec/javascripts/helpers/mock-ajax.js +0 -207
  52. data/spec/javascripts/spec.css +0 -3
  53. data/spec/javascripts/spec.js +0 -2
  54. data/spec/models/phrase_spec.rb +0 -11
  55. data/spec/routing/phrase_spec.rb +0 -12
  56. data/spec/routing/root_spec.rb +0 -7
  57. data/spec/views/_phrase.html.erb_spec.rb +0 -9
  58. data/spec/views/index.html.erb_spec.rb +0 -10
data/config/boot.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
-
3
- # Set up gems listed in the Gemfile.
4
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
-
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
data/config/database.yml DELETED
@@ -1,25 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- development:
7
- adapter: sqlite3
8
- database: db/development.sqlite3
9
- pool: 5
10
- timeout: 5000
11
-
12
- # Warning: The database defined as "test" will be erased and
13
- # re-generated from your development database when you run "rake".
14
- # Do not set this db to the same as development or production.
15
- test:
16
- adapter: sqlite3
17
- database: db/test.sqlite3
18
- pool: 5
19
- timeout: 5000
20
-
21
- production:
22
- adapter: sqlite3
23
- database: db/production.sqlite3
24
- pool: 5
25
- timeout: 5000
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- EditableList::Application.initialize!
@@ -1,30 +0,0 @@
1
- EditableList::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the web server when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
15
-
16
- # Don't care if the mailer can't send
17
- config.action_mailer.raise_delivery_errors = false
18
-
19
- # Print deprecation notices to the Rails logger
20
- config.active_support.deprecation = :log
21
-
22
- # Only use best-standards-support built into browsers
23
- config.action_dispatch.best_standards_support = :builtin
24
-
25
- # Do not compress assets
26
- config.assets.compress = false
27
-
28
- # Expands the lines which load the assets
29
- config.assets.debug = true
30
- end
@@ -1,60 +0,0 @@
1
- EditableList::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # Code is not reloaded between requests
5
- config.cache_classes = true
6
-
7
- # Full error reports are disabled and caching is turned on
8
- config.consider_all_requests_local = false
9
- config.action_controller.perform_caching = true
10
-
11
- # Disable Rails's static asset server (Apache or nginx will already do this)
12
- config.serve_static_assets = false
13
-
14
- # Compress JavaScripts and CSS
15
- config.assets.compress = true
16
-
17
- # Don't fallback to assets pipeline if a precompiled asset is missed
18
- config.assets.compile = false
19
-
20
- # Generate digests for assets URLs
21
- config.assets.digest = true
22
-
23
- # Defaults to Rails.root.join("public/assets")
24
- # config.assets.manifest = YOUR_PATH
25
-
26
- # Specifies the header that your server uses for sending files
27
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29
-
30
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
- # config.force_ssl = true
32
-
33
- # See everything in the log (default is :info)
34
- # config.log_level = :debug
35
-
36
- # Use a different logger for distributed setups
37
- # config.logger = SyslogLogger.new
38
-
39
- # Use a different cache store in production
40
- # config.cache_store = :mem_cache_store
41
-
42
- # Enable serving of images, stylesheets, and JavaScripts from an asset server
43
- # config.action_controller.asset_host = "http://assets.example.com"
44
-
45
- # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
46
- # config.assets.precompile += %w( search.js )
47
-
48
- # Disable delivery errors, bad email addresses will be ignored
49
- # config.action_mailer.raise_delivery_errors = false
50
-
51
- # Enable threaded mode
52
- # config.threadsafe!
53
-
54
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
55
- # the I18n.default_locale when a translation can not be found)
56
- config.i18n.fallbacks = true
57
-
58
- # Send deprecation notices to registered listeners
59
- config.active_support.deprecation = :notify
60
- end
@@ -1,42 +0,0 @@
1
- EditableList::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
6
- # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
8
- config.cache_classes = true
9
-
10
- # Configure static asset server for tests with Cache-Control for performance
11
- config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
13
-
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
16
-
17
- # Show full error reports and disable caching
18
- config.consider_all_requests_local = true
19
- config.action_controller.perform_caching = false
20
-
21
- # Raise exceptions instead of rendering exception templates
22
- config.action_dispatch.show_exceptions = false
23
-
24
- # Disable request forgery protection in test environment
25
- config.action_controller.allow_forgery_protection = false
26
-
27
- # Tell Action Mailer not to deliver emails to the real world.
28
- # The :test delivery method accumulates sent emails in the
29
- # ActionMailer::Base.deliveries array.
30
- config.action_mailer.delivery_method = :test
31
-
32
- # Use SQL instead of Active Record's schema dumper when creating the test database.
33
- # This is necessary if your schema can't be completely dumped by the schema dumper,
34
- # like if you have constraints or database-specific column types
35
- # config.active_record.schema_format = :sql
36
-
37
- # Print deprecation notices to the stderr
38
- config.active_support.deprecation = :stderr
39
-
40
- # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
41
- config.assets.allow_debugging = true
42
- end
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
- # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
-
6
- # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
- # Rails.backtrace_cleaner.remove_silencers!
@@ -1,10 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new inflection rules using the following format
4
- # (all these examples are active by default):
5
- # ActiveSupport::Inflector.inflections do |inflect|
6
- # inflect.plural /^(ox)$/i, '\1en'
7
- # inflect.singular /^(ox)en/i, '\1'
8
- # inflect.irregular 'person', 'people'
9
- # inflect.uncountable %w( fish sheep )
10
- # end
@@ -1,5 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf
5
- # Mime::Type.register_alias "text/html", :iphone
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
- # Make sure the secret is at least 30 characters and all random,
6
- # no regular words or you'll be exposed to dictionary attacks.
7
- EditableList::Application.config.secret_token = '11eeb13588ba069a89bf4bb7a38f620d69e483091c7d63ff8dc9945193477be35a285baa1c81b5984aaf0ff4742a8e874d26abecbbeeca8a7de6972ab235c2f5'
@@ -1,8 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- EditableList::Application.config.session_store :cookie_store, key: '_editable-list_session'
4
-
5
- # Use the database for sessions instead of the cookie-based default,
6
- # which shouldn't be used to store highly confidential information
7
- # (create the session table with "rails generate session_migration")
8
- # EditableList::Application.config.session_store :active_record_store
@@ -1,14 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
- #
3
- # This file contains settings for ActionController::ParamsWrapper which
4
- # is enabled by default.
5
-
6
- # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
- ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json]
9
- end
10
-
11
- # Disable root element in JSON by default.
12
- ActiveSupport.on_load(:active_record) do
13
- self.include_root_in_json = false
14
- end
@@ -1,5 +0,0 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
-
4
- en:
5
- hello: "Hello world"
data/config/routes.rb DELETED
@@ -1,4 +0,0 @@
1
- EditableList::Application.routes.draw do
2
- resources :phrases, :only => [:index,:update]
3
- root :to => "phrases#index"
4
- end
@@ -1,9 +0,0 @@
1
- class CreatePhrases < ActiveRecord::Migration
2
- def change
3
- create_table :phrases do |t|
4
- t.string :text
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
data/db/schema.rb DELETED
@@ -1,22 +0,0 @@
1
- # encoding: UTF-8
2
- # This file is auto-generated from the current state of the database. Instead
3
- # of editing this file, please use the migrations feature of Active Record to
4
- # incrementally modify your database, and then regenerate this schema definition.
5
- #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
11
- #
12
- # It's strongly recommended to check this file into your version control system.
13
-
14
- ActiveRecord::Schema.define(:version => 20120213182817) do
15
-
16
- create_table "phrases", :force => true do |t|
17
- t.string "text"
18
- t.datetime "created_at"
19
- t.datetime "updated_at"
20
- end
21
-
22
- end
data/db/seeds.rb DELETED
@@ -1,7 +0,0 @@
1
- # This file should contain all the record creation needed to seed the database with its default values.
2
- # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
- #
4
- # Examples:
5
- #
6
- # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7
- # Mayor.create(name: 'Emanuel', city: cities.first)
data/lib/assets/.gitkeep DELETED
File without changes
data/lib/tasks/.gitkeep DELETED
File without changes
data/lib/tasks/admin.rake DELETED
@@ -1,9 +0,0 @@
1
- namespace :admin do
2
- desc 'create some random phrases'
3
- task :create_phrases => :environment do
4
- 100.times do
5
- Phrase.create!(text: Faker::Lorem.sentence(1))
6
- end
7
- end
8
-
9
- end
@@ -1,8 +0,0 @@
1
- begin
2
- require 'jasmine'
3
- load 'jasmine/tasks/jasmine.rake'
4
- rescue LoadError
5
- task :jasmine do
6
- abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
7
- end
8
- end
data/script/rails DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
@@ -1,22 +0,0 @@
1
- require "spec_helper"
2
- describe PhrasesController do
3
- context "GET" do
4
- context "index" do
5
- it "should be ok" do
6
- get :index
7
- response.should be_success
8
- end
9
- it "should render template" do
10
- get :index
11
- response.should render_template('index')
12
- end
13
-
14
- it "assigns phrases to @phrases" do
15
- Phrase.create!(:text => 'Cake')
16
- Phrase.create!(:text => 'Cake 2')
17
- get :index
18
- assigns[:phrases].should == Phrase.limit(2).all # all executes the ActiveRecord::Relation
19
- end
20
- end
21
- end
22
- end
@@ -1,411 +0,0 @@
1
- describe("Editable",function() {
2
- var selector = '.phrase .text'
3
-
4
- var should_be_an_input_after_click = function() {
5
- // best jquery practice - use pseudo selectors after
6
- // using natural css selectors
7
- expect($(selector)
8
- .filter(':input')
9
- .size()
10
- ).toBe(0)
11
- $(selector)
12
- .filter(':first')
13
- .trigger('click.editable')
14
- expect($(selector)
15
- .filter(':input')
16
- .size()
17
- ).toBe(1)
18
- }
19
-
20
-
21
- it("it has a constructor", function() {
22
- expect(Editable).toBeDefined()
23
- expect(Editable()).toBeDefined()
24
- })
25
-
26
- describe("needs an attribute editable-resource-uri", function() {
27
- beforeEach(function(){
28
- var fixture = "<div class='phrase'>"+
29
- "<span class='text'>CAKE</span>"+
30
- "</div>"
31
- // removed from dom each
32
- // test
33
- setFixtures(fixture)
34
- });
35
- describe("with editable declared",function() {
36
- beforeEach(function() {
37
- // Construct
38
- Editable(selector)
39
- })
40
- describe("error messages in dom",function() {
41
- it("resource-attribute attribute",function() {
42
-
43
- $(selector)
44
- .filter(':first')
45
- .trigger('click.editable')
46
- $(selector)
47
- .filter(':first')
48
- .trigger('blur.editable')
49
-
50
- expect($('.editable-errors')
51
- .text()
52
- ).toMatch(
53
- "expected editable-resource-attribute attribute"
54
- )
55
- })
56
- it("resource-model attribute",function() {
57
-
58
- $(selector)
59
- .filter(':first')
60
- .trigger('click.editable')
61
- $(selector)
62
- .filter(':first')
63
- .trigger('blur.editable')
64
-
65
- expect($('.editable-errors')
66
- .text()
67
- ).toMatch(
68
- "expected editable-resource-model attribute"
69
- )
70
- })
71
- it("resource-uri attribute",function() {
72
-
73
- $(selector)
74
- .filter(':first')
75
- .trigger('click.editable')
76
- $(selector)
77
- .filter(':first')
78
- .trigger('blur.editable')
79
-
80
- expect($('.editable-errors')
81
- .text()
82
- ).toMatch(
83
- "expected editable-resource-uri attribute"
84
- )
85
- })
86
- })
87
- })
88
- })
89
-
90
- describe("with a single match in dom",function() {
91
-
92
- beforeEach(function(){
93
- var fixture = "<div class='phrase'>"+
94
- "<span "+
95
- " editable-resource-uri='http://s/r/i' "+
96
- " class='text'>CAKE</span>"+
97
- "</div>"
98
- setFixtures(fixture)
99
- });
100
-
101
- it("selector modifies dom",function() {
102
- Editable(selector)
103
- expect($(selector).data('editable')).toBeDefined()
104
- })
105
-
106
- describe("after installation",function() {
107
- beforeEach(function() {
108
-
109
- Editable(selector)
110
- })
111
-
112
- describe("ajax request is sent",function() {
113
- beforeEach(function() {
114
- spyOn(jQuery.ajaxSettings, 'xhr').andCallFake(function() {
115
- var newXhr = new FakeXMLHttpRequest();
116
- ajaxRequests.push(newXhr);
117
- return newXhr;
118
- })
119
- })
120
- it("when editing is complete",function() {
121
- $(selector).filter(':first').attr('editable-resource-uri',"http://cake123/")
122
- $(selector).filter(':first').attr('editable-resource-model',"phrase")
123
- $(selector).filter(':first').attr('editable-resource-attribute',"text")
124
-
125
- // become editable
126
- $(selector).filter(':first').trigger('click.editable')
127
- // change value
128
- $(selector).filter(':first').val("passion")
129
- // complete editing
130
- $(selector).filter(':first').trigger('blur.editable')
131
-
132
- request = mostRecentAjaxRequest()
133
- console.log(request)
134
- expect(request).not.toBeNull()
135
- expect(request.params).toMatch(/phrase%5Btext%5D=passion/)
136
- expect(request.method).toMatch(/PUT/)
137
- expect(request.url).toMatch("http://cake123/")
138
- })
139
- })
140
-
141
- describe("when editing begins", function() {
142
- describe("an element ",function() {
143
- it("is an input",should_be_an_input_after_click)
144
- it("has same classes",function() {
145
- $(selector).addClass('cake').addClass('oat')
146
- $(selector).filter(':first').trigger('click.editable')
147
- expect($(selector).filter('.cake').size()).toBe(1)
148
- expect($(selector).filter('.oat').size()).toBe(1)
149
- })
150
- it("has same id",function() {
151
- $(selector).attr('id','boom')
152
- $(selector).filter(':first').trigger('click.editable')
153
- expect($(selector).filter('#boom').size()).toBe(1)
154
- })
155
- it("stores its text as input value",function() {
156
- $(selector).filter(':first').text("Lily")
157
- $(selector).filter(':first').trigger('click.editable')
158
- expect($(selector).filter(':first').val()).toEqual("Lily")
159
- })
160
- it("has a unique position attribute: editable-index",function() {
161
- $(selector).attr('editable-index','333')
162
- $(selector).filter(':first').trigger('click.editable')
163
- expect($(selector).filter(':input').attr('editable-index')).toBe('333')
164
- })
165
- it("has a resource uri : editable-resource-uri",function() {
166
- $(selector).attr('editable-resource-uri','http://11')
167
- $(selector).filter(':first').trigger('click.editable')
168
- expect($(selector)
169
- .filter(':input')
170
- .attr('editable-resource-uri')).toBe('http://11')
171
- })
172
- it("has a resource name : editable-resource-model",function() {
173
- $(selector).attr('editable-resource-model','dream')
174
- $(selector).filter(':first').trigger('click.editable')
175
- expect($(selector)
176
- .filter(':input')
177
- .attr('editable-resource-model')).toBe('dream')
178
- })
179
- it("has a resource attribute : editable-resource-attribute",function() {
180
- $(selector).attr('editable-resource-attribute','vision')
181
- $(selector).filter(':first').trigger('click.editable')
182
- expect($(selector)
183
- .filter(':input')
184
- .attr('editable-resource-attribute')).toBe('vision')
185
- })
186
- it("has same jquery data",function() {
187
- // data is used in rails and jquery for storage of various properties
188
- $(selector).data('hi',1)
189
- $(selector).data('hello',2)
190
- var expected_data = $(selector).data();
191
- $(selector).filter(':first').trigger('click.editable')
192
- // this is the general pattern for iterating correctly in a hash
193
- // in javascript
194
- for(var prop in expected_data) {
195
- // ignore parent prototype properties
196
- if(expected_data.hasOwnProperty(prop)) {
197
- // use proprety expected_data[prop]
198
- expect($(selector).filter(':input').data(prop)).toEqual(expected_data[prop])
199
- }
200
- }
201
- $(selector).filter(':input').data()
202
- })
203
- it("stores previous incarnation: tagName",function() {
204
- var expected_tag = $(selector).filter(':first').get(0).tagName
205
- $(selector).filter(':first').trigger('click.editable')
206
- expect($(selector).filter(':input').data('editable-was')).toEqual(expected_tag)
207
- })
208
- it("is focused",function() {
209
- expect($(selector).filter(':focus').size()).toBe(0)
210
- $(selector).filter(':first').trigger('click.editable')
211
- expect($(selector).filter(':focus').size()).toBe(1)
212
-
213
- })
214
- })
215
- })
216
- describe("when editing is complete", function() {
217
- it("an element becomes again editable-was",function() {
218
- // first there is a mountain
219
- var expected_tag = $(selector).filter(':first').get(0).tagName
220
- expect($(selector).filter(expected_tag).size()).toBe(1)
221
- $(selector).filter(':first').trigger('click.editable')
222
- // then there is no mountain
223
- expect($(selector).filter(expected_tag).size()).toBe(0)
224
- $(selector).filter(':first').trigger('blur.editable')
225
- // then there is
226
- expect($(selector).filter(expected_tag).size()).toBe(1)
227
- })
228
- it("the input value becomes the CDATA",function () {
229
- $(selector).filter(':first').text("SOUP")
230
- $(selector).filter(':first').trigger('click.editable')
231
- expect($(selector).filter(':first').val()).toEqual("SOUP")
232
- $(selector).filter(':first').val("are you a kitty?")
233
- $(selector).filter(':first').trigger('blur.editable')
234
- expect($(selector).filter(':first').text()).toEqual("are you a kitty?")
235
-
236
- })
237
- })
238
- describe("hover event handler", function() {
239
- it("turns on editable hover class",function() {
240
- expect($(selector).filter(':first').hasClass('editable-hover')).toBeFalsy()
241
- $(selector).filter(':first').trigger('mouseover.editable')
242
- expect($(selector).filter(':first').hasClass('editable-hover')).toBeTruthy()
243
- })
244
- it("turns off editable hover class",function() {
245
- expect($(selector).filter(':first').hasClass('editable-hover')).toBeFalsy()
246
- $(selector).filter(':first').trigger('mouseover.editable')
247
- expect($(selector).filter(':first').hasClass('editable-hover')).toBeTruthy()
248
- $(selector).filter(':first').trigger('mouseout.editable')
249
- expect($(selector).filter(':first').hasClass('editable-hover')).toBeFalsy()
250
- })
251
- })
252
-
253
- describe("editable life-cycle",function() {
254
-
255
- it("moves from editable to to completed to editable to completed to editable",function() {
256
- // invariant:
257
- // the selector always exists in the dom
258
- //
259
- // invariant:
260
- // the selector must become and input on click
261
- //
262
- expect($(selector).size()).toBe(1)
263
- expect($(selector).filter(':input').size()).toBe(0)
264
- $(selector).filter(':first').trigger('click.editable')
265
- expect($(selector).size()).toBe(1)
266
- expect($(selector).filter(':input').size()).toBe(1)
267
- $(selector).filter(':first').trigger('blur.editable')
268
- expect($(selector).size()).toBe(1)
269
- expect($(selector).filter(':input').size()).toBe(0)
270
- $(selector).filter(':first').trigger('click.editable')
271
- expect($(selector).size()).toBe(1)
272
- expect($(selector).filter(':input').size()).toBe(1)
273
- $(selector).filter(':first').trigger('blur.editable')
274
- expect($(selector).size()).toBe(1)
275
- expect($(selector).filter(':input').size()).toBe(0)
276
- $(selector).filter(':first').trigger('click.editable')
277
- expect($(selector).size()).toBe(1)
278
- expect($(selector).filter(':input').size()).toBe(1)
279
- })
280
- })
281
-
282
-
283
- describe("escape key", function() {
284
- beforeEach(function() {
285
- $(selector).filter(':first').trigger('click.editable')
286
- // triffer ESC event
287
- var e = jQuery.Event("keydown.editable", { keyCode: Editable.ESC_KEY })
288
- $(selector).filter(':first').trigger(e)
289
- })
290
- describe("followed by a click",function() {
291
- it("is an input",should_be_an_input_after_click)
292
- })
293
- })
294
- })
295
- })
296
-
297
- describe("with multiple matches in dom",function() {
298
- beforeEach(function(){
299
- var fixture = "<div class='phrase'><span id='first' editable-resource-uri='http://s/r/i' class='text'>CAKE1</span></div>"
300
- fixture += "<div class='phrase'><span id='second' editable-resource-uri='http://s/r/i' class='text'>CAKE2</span></div>"
301
- fixture += "<div class='phrase'><span id='third' editable-resource-uri='http://s/r/i' class='text'>CAKE3</span></div>"
302
- setFixtures(fixture)
303
- });
304
- describe("with editable declared",function() {
305
- beforeEach(function() {
306
- Editable(selector)
307
- })
308
- it("has a data editable-index",function() {
309
- expect($(selector).filter('#first').attr("editable-index")).toEqual('1')
310
- expect($(selector).filter('#second').attr("editable-index")).toEqual('2')
311
- expect($(selector).filter('#third').attr("editable-index")).toEqual('3')
312
-
313
- })
314
- describe("editable life-cycle",function() {
315
- describe("on editing node there is a keydown handler", function() {
316
-
317
- describe("the esc key", function() {
318
- it("returns the input to it's original value", function () {
319
- // nothing if focused
320
- expect($(selector).filter(':focus').size()).toBe(0)
321
- $(selector).filter(':first').trigger('click.editable')
322
- // #first becomes focused
323
- expect($(selector).filter('#first').filter(':focus').size()).toBe(1)
324
-
325
- var expected_value = $(selector).filter(':first').val()
326
-
327
- // modify element value
328
- $(selector).filter('#first').val("are you a kitty?")
329
- // triffer ESC event
330
- var e = jQuery.Event("keydown.editable", { keyCode: Editable.ESC_KEY })
331
- $(selector).filter('#first').trigger(e)
332
-
333
- expect($(selector).filter('#first').text()).toEqual(expected_value)
334
-
335
- })
336
- })
337
-
338
- describe("the enter key",function() {
339
- it("completes edit and moves to next editable", function () {
340
- // nothing if focused
341
- expect($(selector).filter(':focus').size()).toBe(0)
342
- $(selector).filter(':first').trigger('click.editable')
343
- // #first becomes focused
344
- expect($(selector).filter('#first').filter(':focus').size()).toBe(1)
345
- var e = jQuery.Event("keydown.editable", { keyCode: Editable.ENTER_KEY })
346
- $(selector).filter(':first').trigger(e)
347
-
348
- // #second becomes focused
349
- expect($(selector).filter('#second').filter(':focus').size()).toBe(1)
350
- // #second becomes input
351
- expect($(selector).filter('#second').filter(':input').size()).toBe(1)
352
- })
353
- it("moves back to first editable after last", function () {
354
- expect($(selector).filter(':focus').size()).toBe(0)
355
-
356
- $(selector).filter('#third').trigger('click.editable')
357
- expect($(selector).filter('#third').filter(':focus').size()).toBe(1)
358
-
359
- var e = jQuery.Event("keydown.editable", { keyCode: Editable.ENTER_KEY })
360
- $(selector).filter('#third').trigger(e)
361
-
362
- expect($(selector).filter('#first').filter(':focus').size()).toBe(1)
363
- expect($(selector).filter('#first').filter(':input').size()).toBe(1)
364
- })
365
- })
366
- describe("the tab key",function() {
367
- it("completes edit and moves to next editable", function () {
368
- // nothing if focused
369
- expect($(selector).filter(':focus').size()).toBe(0)
370
- $(selector).filter(':first').trigger('click.editable')
371
- // #first becomes focused
372
- expect($(selector).filter('#first').filter(':focus').size()).toBe(1)
373
- var e = jQuery.Event("keydown.editable", { keyCode: Editable.TAB_KEY })
374
- $(selector).filter(':first').trigger(e)
375
-
376
- // #second becomes focused
377
- expect($(selector).filter('#second').filter(':focus').size()).toBe(1)
378
- // #second becomes input
379
- expect($(selector).filter('#second').filter(':input').size()).toBe(1)
380
- })
381
- it("moves back to first editable after last", function () {
382
- expect($(selector).filter(':focus').size()).toBe(0)
383
-
384
- $(selector).filter('#third').trigger('click.editable')
385
- expect($(selector).filter('#third').filter(':focus').size()).toBe(1)
386
-
387
- var e = jQuery.Event("keydown.editable", { keyCode: Editable.TAB_KEY })
388
- $(selector).filter('#third').trigger(e)
389
-
390
- expect($(selector).filter('#first').filter(':focus').size()).toBe(1)
391
- expect($(selector).filter('#first').filter(':input').size()).toBe(1)
392
- })
393
- })
394
- it("other keys do nothing", function () {
395
- // nothing if focused
396
- expect($(selector).filter(':focus').size()).toBe(0)
397
- $(selector).filter(':first').trigger('click.editable')
398
- // #first becomes focused
399
- expect($(selector).filter('#first').filter(':focus').size()).toBe(1)
400
- var e = jQuery.Event("keydown.editable", { keyCode: 99 })
401
- $(selector).filter(':first').trigger(e)
402
- // nothing changes - still only one
403
- expect($(selector).filter(':input').size()).toBe(1)
404
- // and it is the same one
405
- expect($(selector).filter('#first').filter(':focus').size()).toBe(1)
406
- })
407
- })
408
- })
409
- })
410
- })
411
- })