pose 1.3.4 → 2.0.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 (76) hide show
  1. data/README.md +11 -0
  2. data/Rakefile +4 -2
  3. data/app/models/pose/assignment.rb +34 -0
  4. data/app/models/pose/word.rb +24 -0
  5. data/db/migrate/20130308144915_pose_install.rb +18 -0
  6. data/lib/generators/pose/remove/templates/remove_migration.rb +3 -5
  7. data/lib/generators/pose/upgrade/templates/upgrade_migration.rb +9 -0
  8. data/lib/generators/pose/upgrade/upgrade_generator.rb +35 -0
  9. data/lib/pose/activerecord_base_additions.rb +5 -2
  10. data/lib/pose/engine.rb +5 -0
  11. data/lib/pose/internal_helpers.rb +13 -7
  12. data/lib/pose/{model_additions.rb → model_class_additions.rb} +8 -8
  13. data/lib/pose/railtie.rb +1 -2
  14. data/lib/pose/static_api.rb +5 -6
  15. data/lib/pose/version.rb +1 -1
  16. data/lib/pose.rb +5 -7
  17. data/lib/tasks/pose_tasks.rake +27 -29
  18. data/spec/dummy/Rakefile +7 -0
  19. data/spec/{support/models.rb → dummy/app/models/posable_one.rb} +1 -4
  20. data/spec/dummy/app/models/posable_two.rb +5 -0
  21. data/spec/dummy/config/application.rb +59 -0
  22. data/spec/dummy/config/boot.rb +10 -0
  23. data/spec/dummy/config/database.yml +25 -0
  24. data/spec/dummy/config/environment.rb +5 -0
  25. data/spec/dummy/config/environments/development.rb +37 -0
  26. data/spec/dummy/config/environments/production.rb +67 -0
  27. data/spec/dummy/config/environments/test.rb +37 -0
  28. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/spec/dummy/config/initializers/inflections.rb +15 -0
  30. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  31. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  32. data/spec/dummy/config/initializers/session_store.rb +8 -0
  33. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  34. data/spec/dummy/config/locales/en.yml +5 -0
  35. data/spec/dummy/config/routes.rb +2 -0
  36. data/spec/dummy/config.ru +4 -0
  37. data/spec/dummy/db/migrate/20130308054001_create_posable_one.rb +8 -0
  38. data/spec/dummy/db/migrate/20130308054142_create_posable_two.rb +9 -0
  39. data/spec/dummy/db/schema.rb +41 -0
  40. data/spec/dummy/script/rails +6 -0
  41. data/spec/factories/assignments.rb +8 -0
  42. data/spec/factories/posable_one.rb +5 -0
  43. data/spec/factories/words.rb +7 -0
  44. data/spec/internal_helpers_spec.rb +40 -42
  45. data/spec/models/assignment_spec.rb +46 -0
  46. data/spec/models/word_spec.rb +42 -0
  47. data/spec/pose_api_spec.rb +198 -196
  48. data/spec/spec_helper.rb +21 -77
  49. data/spec/support/matchers.rb +0 -1
  50. metadata +83 -102
  51. data/doc/Pose/InstanceMethods.html +0 -341
  52. data/doc/Pose.html +0 -774
  53. data/doc/PoseAssignment.html +0 -125
  54. data/doc/PoseGenerator.html +0 -255
  55. data/doc/PoseMigrations.html +0 -261
  56. data/doc/PoseWord.html +0 -125
  57. data/doc/_index.html +0 -134
  58. data/doc/class_list.html +0 -47
  59. data/doc/css/common.css +0 -1
  60. data/doc/css/full_list.css +0 -55
  61. data/doc/css/style.css +0 -322
  62. data/doc/file_list.html +0 -46
  63. data/doc/frames.html +0 -13
  64. data/doc/index.html +0 -134
  65. data/doc/js/app.js +0 -205
  66. data/doc/js/full_list.js +0 -167
  67. data/doc/js/jquery.js +0 -16
  68. data/doc/method_list.html +0 -150
  69. data/doc/top-level-namespace.html +0 -172
  70. data/lib/generators/pose/install/install_generator.rb +0 -56
  71. data/lib/generators/pose/install/templates/install_migration.rb +0 -24
  72. data/lib/pose/models/pose_assignment.rb +0 -31
  73. data/lib/pose/models/pose_word.rb +0 -28
  74. data/spec/factories.rb +0 -15
  75. data/spec/pose_assignment_spec.rb +0 -45
  76. data/spec/pose_word_spec.rb +0 -26
@@ -0,0 +1,67 @@
1
+ Dummy::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 nil and saved in location specified by config.assets.prefix
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
+ # Prepend all log lines with the following tags
37
+ # config.log_tags = [ :subdomain, :uuid ]
38
+
39
+ # Use a different logger for distributed setups
40
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41
+
42
+ # Use a different cache store in production
43
+ # config.cache_store = :mem_cache_store
44
+
45
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
46
+ # config.action_controller.asset_host = "http://assets.example.com"
47
+
48
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
+ # config.assets.precompile += %w( search.js )
50
+
51
+ # Disable delivery errors, bad email addresses will be ignored
52
+ # config.action_mailer.raise_delivery_errors = false
53
+
54
+ # Enable threaded mode
55
+ # config.threadsafe!
56
+
57
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58
+ # the I18n.default_locale when a translation can not be found)
59
+ config.i18n.fallbacks = true
60
+
61
+ # Send deprecation notices to registered listeners
62
+ config.active_support.deprecation = :notify
63
+
64
+ # Log the query plan for queries taking more than this (works
65
+ # with SQLite, MySQL, and PostgreSQL)
66
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
+ end
@@ -0,0 +1,37 @@
1
+ Dummy::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
+ # Raise exception on mass assignment protection for Active Record models
33
+ config.active_record.mass_assignment_sanitizer = :strict
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
37
+ end
@@ -0,0 +1,7 @@
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!
@@ -0,0 +1,15 @@
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
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -0,0 +1,5 @@
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
@@ -0,0 +1,7 @@
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
+ Dummy::Application.config.secret_token = '018ac8601e03d056975cabe7cc0f7b317982d42610dd4b4ec217334533e33ff6e4e579b07ded701a69dc4e28422de257d228b7fd75a88f013e159b404c29cf46'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_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
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,5 @@
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"
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,8 @@
1
+ class CreatePosableOne < ActiveRecord::Migration
2
+ def change
3
+ create_table :posable_ones do |t|
4
+ t.string :text
5
+ t.boolean :private
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreatePosableTwo < ActiveRecord::Migration
2
+ def change
3
+ create_table :posable_twos do |t|
4
+ t.string :text
5
+ t.boolean :private
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,41 @@
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 => 20130308144915) do
15
+
16
+ create_table "posable_ones", :force => true do |t|
17
+ t.string "text"
18
+ t.boolean "private"
19
+ end
20
+
21
+ create_table "posable_twos", :force => true do |t|
22
+ t.string "text"
23
+ t.boolean "private"
24
+ end
25
+
26
+ create_table "pose_assignments", :force => true do |t|
27
+ t.integer "word_id", :null => false
28
+ t.integer "posable_id", :null => false
29
+ t.string "posable_type", :limit => 40, :null => false
30
+ end
31
+
32
+ add_index "pose_assignments", ["posable_id"], :name => "index_pose_assignments_on_posable_id"
33
+ add_index "pose_assignments", ["word_id"], :name => "index_pose_assignments_on_word_id"
34
+
35
+ create_table "pose_words", :force => true do |t|
36
+ t.string "text", :limit => 80, :null => false
37
+ end
38
+
39
+ add_index "pose_words", ["text"], :name => "index_pose_words_on_text"
40
+
41
+ end
@@ -0,0 +1,6 @@
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'
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :assignment, class: Pose::Assignment do
4
+ word
5
+ posable factory: :posable_one
6
+ end
7
+
8
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :posable_one do
3
+ text { Faker::Lorem.words(2).join ' ' }
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :word, class: Pose::Word do
4
+ text { Faker::Lorem.words(1).first }
5
+ end
6
+
7
+ end
@@ -1,12 +1,11 @@
1
1
  # encoding: utf-8
2
-
3
2
  require "spec_helper"
4
3
 
5
4
  describe Pose::Helpers do
6
5
 
7
6
  describe '::get_words_to_add' do
8
- let(:one) { PoseWord.new(text: 'one') }
9
- let(:two) { PoseWord.new(text: 'two') }
7
+ let(:one) { Pose::Word.new(text: 'one') }
8
+ let(:two) { Pose::Word.new(text: 'two') }
10
9
 
11
10
  context 'having a new word to be added' do
12
11
  it 'returns an array with strings that need to be added' do
@@ -23,8 +22,8 @@ describe Pose::Helpers do
23
22
 
24
23
 
25
24
  describe '::get_words_to_remove' do
26
- let(:one) { PoseWord.new(text: 'one') }
27
- let(:two) { PoseWord.new(text: 'two') }
25
+ let(:one) { Pose::Word.new(text: 'one') }
26
+ let(:two) { Pose::Word.new(text: 'two') }
28
27
 
29
28
  it "returns an array of word objects that need to be removed" do
30
29
  Pose::Helpers.get_words_to_remove([one, two], %w{one three}).should eql([two])
@@ -39,11 +38,11 @@ describe Pose::Helpers do
39
38
  describe 'make_array' do
40
39
 
41
40
  it 'converts a single value into an array' do
42
- Pose::Helpers.make_array(1).should == [1]
41
+ Pose::Helpers.make_array(1).should eq [1]
43
42
  end
44
43
 
45
44
  it 'leaves arrays as arrays' do
46
- Pose::Helpers.make_array([1]).should == [1]
45
+ Pose::Helpers.make_array([1]).should eq [1]
47
46
  end
48
47
  end
49
48
 
@@ -57,7 +56,7 @@ describe Pose::Helpers do
57
56
 
58
57
  it 'sets the given ids as the ids for this class name' do
59
58
  Pose::Helpers.merge_search_result_word_matches @result, 'class1', [1, 2]
60
- @result.should == { 'class1' => [1, 2] }
59
+ @result.should eq({ 'class1' => [1, 2] })
61
60
  end
62
61
  end
63
62
 
@@ -69,7 +68,7 @@ describe Pose::Helpers do
69
68
 
70
69
  it 'only keeps the ids that are included in both sets' do
71
70
  Pose::Helpers.merge_search_result_word_matches @result, 'class1', [1, 3]
72
- @result.should == { 'class1' => [1] }
71
+ @result.should eq({ 'class1' => [1] })
73
72
  end
74
73
  end
75
74
  end
@@ -77,19 +76,19 @@ describe Pose::Helpers do
77
76
 
78
77
  describe 'query_terms' do
79
78
  it 'returns all individual words resulting from the given query' do
80
- Pose::Helpers.query_terms('foo bar').should == ['foo', 'bar']
79
+ Pose::Helpers.query_terms('foo bar').should eq ['foo', 'bar']
81
80
  end
82
81
 
83
82
  it 'converts the individual words into their root form' do
84
- Pose::Helpers.query_terms('bars').should == ['bar']
83
+ Pose::Helpers.query_terms('bars').should eq ['bar']
85
84
  end
86
85
 
87
86
  it 'splits complex words into separate terms' do
88
- Pose::Helpers.query_terms('one-two').should == ['one', 'two']
87
+ Pose::Helpers.query_terms('one-two').should eq ['one', 'two']
89
88
  end
90
89
 
91
90
  it 'removes duplicates' do
92
- Pose::Helpers.query_terms('foo-bar foo').should == ['foo', 'bar']
91
+ Pose::Helpers.query_terms('foo-bar foo').should eq ['foo', 'bar']
93
92
  end
94
93
  end
95
94
 
@@ -101,52 +100,52 @@ describe Pose::Helpers do
101
100
  end
102
101
 
103
102
  it 'removes special characters' do
104
- Pose::Helpers.root_word('(bar').should == ['bar']
105
- Pose::Helpers.root_word('bar)').should == ['bar']
106
- Pose::Helpers.root_word('(bar)').should == ['bar']
107
- Pose::Helpers.root_word('>foo').should == ['foo']
108
- Pose::Helpers.root_word('<foo').should == ['foo']
109
- Pose::Helpers.root_word('"foo"').should == ['foo']
110
- Pose::Helpers.root_word('"foo').should == ['foo']
111
- Pose::Helpers.root_word("'foo'").should == ['foo']
112
- Pose::Helpers.root_word("'foo's").should == ['foo']
113
- Pose::Helpers.root_word("foo?").should == ['foo']
114
- Pose::Helpers.root_word("foo!").should == ['foo']
115
- Pose::Helpers.root_word("foo/bar").should == ['foo', 'bar']
116
- Pose::Helpers.root_word("foo-bar").should == ['foo', 'bar']
117
- Pose::Helpers.root_word("foo--bar").should == ['foo', 'bar']
118
- Pose::Helpers.root_word("foo.bar").should == ['foo', 'bar']
103
+ Pose::Helpers.root_word('(bar').should eq ['bar']
104
+ Pose::Helpers.root_word('bar)').should eq ['bar']
105
+ Pose::Helpers.root_word('(bar)').should eq ['bar']
106
+ Pose::Helpers.root_word('>foo').should eq ['foo']
107
+ Pose::Helpers.root_word('<foo').should eq ['foo']
108
+ Pose::Helpers.root_word('"foo"').should eq ['foo']
109
+ Pose::Helpers.root_word('"foo').should eq ['foo']
110
+ Pose::Helpers.root_word("'foo'").should eq ['foo']
111
+ Pose::Helpers.root_word("'foo's").should eq ['foo']
112
+ Pose::Helpers.root_word("foo?").should eq ['foo']
113
+ Pose::Helpers.root_word("foo!").should eq ['foo']
114
+ Pose::Helpers.root_word("foo/bar").should eq ['foo', 'bar']
115
+ Pose::Helpers.root_word("foo-bar").should eq ['foo', 'bar']
116
+ Pose::Helpers.root_word("foo--bar").should eq ['foo', 'bar']
117
+ Pose::Helpers.root_word("foo.bar").should eq ['foo', 'bar']
119
118
  end
120
119
 
121
120
  it 'removes umlauts' do
122
- Pose::Helpers.root_word('fünf').should == ['funf']
121
+ Pose::Helpers.root_word('fünf').should eq ['funf']
123
122
  end
124
123
 
125
124
  it 'splits up numbers' do
126
- Pose::Helpers.root_word('11.2.2011').should == ['11', '2', '2011']
127
- Pose::Helpers.root_word('11-2-2011').should == ['11', '2', '2011']
128
- Pose::Helpers.root_word('30:4-5').should == ['30', '4', '5']
125
+ Pose::Helpers.root_word('11.2.2011').should eq ['11', '2', '2011']
126
+ Pose::Helpers.root_word('11-2-2011').should eq ['11', '2', '2011']
127
+ Pose::Helpers.root_word('30:4-5').should eq ['30', '4', '5']
129
128
  end
130
129
 
131
130
  it 'converts into lowercase' do
132
- Pose::Helpers.root_word('London').should == ['london']
131
+ Pose::Helpers.root_word('London').should eq ['london']
133
132
  end
134
133
 
135
134
  it "stores single-letter words" do
136
- Pose::Helpers.root_word('a b').should == ['a', 'b']
135
+ Pose::Helpers.root_word('a b').should eq ['a', 'b']
137
136
  end
138
137
 
139
138
  it "does't encode external URLs" do
140
- Pose::Helpers.root_word('http://web.com').should == ['http', 'web', 'com']
139
+ Pose::Helpers.root_word('http://web.com').should eq ['http', 'web', 'com']
141
140
  end
142
141
 
143
142
  it "doesn't store empty words" do
144
- Pose::Helpers.root_word(' one two ').should == ['one', 'two']
143
+ Pose::Helpers.root_word(' one two ').should eq ['one', 'two']
145
144
  end
146
145
 
147
146
  it "removes duplicates" do
148
- Pose::Helpers.root_word('one_one').should == ['one']
149
- Pose::Helpers.root_word('one one').should == ['one']
147
+ Pose::Helpers.root_word('one_one').should eq ['one']
148
+ Pose::Helpers.root_word('one one').should eq ['one']
150
149
  end
151
150
 
152
151
  it "splits up complex URLs" do
@@ -160,7 +159,7 @@ describe Pose::Helpers do
160
159
 
161
160
  it 'returns a hash that contains all the given classes' do
162
161
  result = Pose::Helpers.search_classes_and_ids_for_word 'foo', %w{PosableOne PosableTwo}
163
- result.keys.sort.should == %w{PosableOne PosableTwo}
162
+ result.keys.sort.should eq %w{PosableOne PosableTwo}
164
163
  end
165
164
 
166
165
  it 'returns the ids of all the posable objects that include the given word' do
@@ -170,9 +169,8 @@ describe Pose::Helpers do
170
169
 
171
170
  result = Pose::Helpers.search_classes_and_ids_for_word 'one', %w{PosableOne PosableTwo}
172
171
 
173
- result['PosableOne'].should == [pos1.id]
174
- result['PosableTwo'].should == [pos2.id]
172
+ result['PosableOne'].should eq [pos1.id]
173
+ result['PosableTwo'].should eq [pos2.id]
175
174
  end
176
175
  end
177
176
  end
178
-
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ module Pose
4
+ describe Assignment do
5
+
6
+ describe "delete_class_index" do
7
+
8
+ before :each do
9
+ FactoryGirl.create :assignment, posable_id: 1, posable_type: 'PosableOne'
10
+ FactoryGirl.create :assignment, posable_id: 2, posable_type: 'PosableTwo'
11
+ Assignment.delete_class_index PosableOne
12
+ end
13
+
14
+ it "deletes all Assignments for the given class" do
15
+ expect(Assignment.where(posable_type: 'PosableOne')).to have(0).items
16
+ end
17
+
18
+ it "doesn't delete Assignments for other classes" do
19
+ expect(Assignment.where(posable_type: 'PosableTwo')).to have(1).items
20
+ end
21
+ end
22
+
23
+
24
+ describe "cleanup_orphaned_pose_assignments" do
25
+
26
+ it "deletes the assignment if the posable object doesn't exist" do
27
+ FactoryGirl.create :assignment, posable_id: 2, posable_type: 'PosableOne'
28
+ expect(Assignment.count).to be > 0
29
+ Assignment.cleanup_orphaned_pose_assignments
30
+ expect(Assignment.count).to eql 0
31
+ end
32
+
33
+ it "deletes the assignment if the word doesn't exist" do
34
+ assignment = FactoryGirl.create :assignment, word: nil, word_id: 27
35
+ Assignment.cleanup_orphaned_pose_assignments
36
+ expect(Assignment.find_by_id(assignment.id)).to be_nil
37
+ end
38
+
39
+ it "doesn't delete the assignment if it is still used" do
40
+ assignment = FactoryGirl.create :assignment
41
+ Assignment.cleanup_orphaned_pose_assignments
42
+ expect(Assignment.find_by_id(assignment.id)).to_not be_nil
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module Pose
4
+ describe Word do
5
+
6
+ describe 'class methods' do
7
+
8
+ describe '::remove_unused_words' do
9
+
10
+ shared_examples 'it properly removes unused words' do
11
+ it 'removes unused words' do
12
+ FactoryGirl.create :word
13
+ Word.remove_unused_words
14
+ expect(Word.count).to eql 0
15
+ end
16
+
17
+ it 'does not remove used words' do
18
+ FactoryGirl.create :posable_one
19
+ Word.remove_unused_words
20
+ expect(Word.count).to be > 0
21
+ end
22
+ end
23
+ end
24
+
25
+ context 'with a SQL database' do
26
+ before :each do
27
+ Helpers.should_receive(:is_sql_database?).and_return(true)
28
+ end
29
+
30
+ it_should_behave_like 'it properly removes unused words'
31
+ end
32
+
33
+ context 'without a SQL database' do
34
+ before :each do
35
+ Helpers.should_receive(:is_sql_database?).and_return(false)
36
+ end
37
+
38
+ it_should_behave_like 'it properly removes unused words'
39
+ end
40
+ end
41
+ end
42
+ end