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.
- data/README.md +11 -0
- data/Rakefile +4 -2
- data/app/models/pose/assignment.rb +34 -0
- data/app/models/pose/word.rb +24 -0
- data/db/migrate/20130308144915_pose_install.rb +18 -0
- data/lib/generators/pose/remove/templates/remove_migration.rb +3 -5
- data/lib/generators/pose/upgrade/templates/upgrade_migration.rb +9 -0
- data/lib/generators/pose/upgrade/upgrade_generator.rb +35 -0
- data/lib/pose/activerecord_base_additions.rb +5 -2
- data/lib/pose/engine.rb +5 -0
- data/lib/pose/internal_helpers.rb +13 -7
- data/lib/pose/{model_additions.rb → model_class_additions.rb} +8 -8
- data/lib/pose/railtie.rb +1 -2
- data/lib/pose/static_api.rb +5 -6
- data/lib/pose/version.rb +1 -1
- data/lib/pose.rb +5 -7
- data/lib/tasks/pose_tasks.rake +27 -29
- data/spec/dummy/Rakefile +7 -0
- data/spec/{support/models.rb → dummy/app/models/posable_one.rb} +1 -4
- data/spec/dummy/app/models/posable_two.rb +5 -0
- data/spec/dummy/config/application.rb +59 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20130308054001_create_posable_one.rb +8 -0
- data/spec/dummy/db/migrate/20130308054142_create_posable_two.rb +9 -0
- data/spec/dummy/db/schema.rb +41 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/assignments.rb +8 -0
- data/spec/factories/posable_one.rb +5 -0
- data/spec/factories/words.rb +7 -0
- data/spec/internal_helpers_spec.rb +40 -42
- data/spec/models/assignment_spec.rb +46 -0
- data/spec/models/word_spec.rb +42 -0
- data/spec/pose_api_spec.rb +198 -196
- data/spec/spec_helper.rb +21 -77
- data/spec/support/matchers.rb +0 -1
- metadata +83 -102
- data/doc/Pose/InstanceMethods.html +0 -341
- data/doc/Pose.html +0 -774
- data/doc/PoseAssignment.html +0 -125
- data/doc/PoseGenerator.html +0 -255
- data/doc/PoseMigrations.html +0 -261
- data/doc/PoseWord.html +0 -125
- data/doc/_index.html +0 -134
- data/doc/class_list.html +0 -47
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -55
- data/doc/css/style.css +0 -322
- data/doc/file_list.html +0 -46
- data/doc/frames.html +0 -13
- data/doc/index.html +0 -134
- data/doc/js/app.js +0 -205
- data/doc/js/full_list.js +0 -167
- data/doc/js/jquery.js +0 -16
- data/doc/method_list.html +0 -150
- data/doc/top-level-namespace.html +0 -172
- data/lib/generators/pose/install/install_generator.rb +0 -56
- data/lib/generators/pose/install/templates/install_migration.rb +0 -24
- data/lib/pose/models/pose_assignment.rb +0 -31
- data/lib/pose/models/pose_word.rb +0 -28
- data/spec/factories.rb +0 -15
- data/spec/pose_assignment_spec.rb +0 -45
- data/spec/pose_word_spec.rb +0 -26
    
        data/spec/pose_api_spec.rb
    CHANGED
    
    | @@ -2,280 +2,282 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            require "spec_helper"
         | 
| 4 4 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
               | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
                 | 
| 10 | 
            -
                   | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 5 | 
            +
            module Pose
         | 
| 6 | 
            +
              describe Pose do
         | 
| 7 | 
            +
                subject { PosableOne.new }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                describe 'associations' do
         | 
| 10 | 
            +
                  it 'allows to access the associated words of a posable object directly' do
         | 
| 11 | 
            +
                    expect(subject).to have(0).pose_words
         | 
| 12 | 
            +
                    subject.pose_words << Word.new(text: 'one')
         | 
| 13 | 
            +
                    expect(subject).to have_pose_words 'one'
         | 
| 14 | 
            +
                  end
         | 
| 13 15 | 
             
                end
         | 
| 14 | 
            -
              end
         | 
| 15 16 |  | 
| 16 17 |  | 
| 17 | 
            -
             | 
| 18 | 
            +
                describe '#update_pose_index' do
         | 
| 18 19 |  | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 20 | 
            +
                  before :each do
         | 
| 21 | 
            +
                    Pose::CONFIGURATION[:perform_search] = perform_search
         | 
| 22 | 
            +
                  end
         | 
| 22 23 |  | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 24 | 
            +
                  after :each do
         | 
| 25 | 
            +
                    Pose::CONFIGURATION.delete :perform_search
         | 
| 26 | 
            +
                  end
         | 
| 26 27 |  | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 28 | 
            +
                  context "search_in_tests flag is not enabled" do
         | 
| 29 | 
            +
                    let(:perform_search) { false }
         | 
| 29 30 |  | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 31 | 
            +
                    it "doesn't call update_pose_words" do
         | 
| 32 | 
            +
                      subject.should_not_receive :update_pose_words
         | 
| 33 | 
            +
                      subject.update_pose_index
         | 
| 34 | 
            +
                    end
         | 
| 33 35 | 
             
                  end
         | 
| 34 | 
            -
                end
         | 
| 35 36 |  | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 37 | 
            +
                  context "search_in_tests flag is enabled" do
         | 
| 38 | 
            +
                    let(:perform_search) { true }
         | 
| 38 39 |  | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 40 | 
            +
                    it "calls update_pose_words" do
         | 
| 41 | 
            +
                      subject.should_receive :update_pose_words
         | 
| 42 | 
            +
                      subject.update_pose_index
         | 
| 43 | 
            +
                    end
         | 
| 42 44 | 
             
                  end
         | 
| 43 45 | 
             
                end
         | 
| 44 | 
            -
              end
         | 
| 45 46 |  | 
| 46 47 |  | 
| 47 | 
            -
             | 
| 48 | 
            +
                describe '#update_pose_words' do
         | 
| 48 49 |  | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 50 | 
            +
                  it 'saves the words for search' do
         | 
| 51 | 
            +
                    subject.text = 'foo bar'
         | 
| 52 | 
            +
                    subject.update_pose_words
         | 
| 53 | 
            +
                    expect(subject).to have_pose_words 'foo', 'bar'
         | 
| 54 | 
            +
                  end
         | 
| 54 55 |  | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 56 | 
            +
                  it 'updates the search index when the text is changed' do
         | 
| 57 | 
            +
                    subject.text = 'foo'
         | 
| 58 | 
            +
                    subject.save!
         | 
| 58 59 |  | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 60 | 
            +
                    subject.text = 'other text'
         | 
| 61 | 
            +
                    subject.update_pose_words
         | 
| 61 62 |  | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 63 | 
            +
                    expect(subject).to have_pose_words 'other', 'text'
         | 
| 64 | 
            +
                  end
         | 
| 64 65 |  | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 66 | 
            +
                  it "doesn't create duplicate words" do
         | 
| 67 | 
            +
                    subject.text = 'foo foo'
         | 
| 68 | 
            +
                    subject.save!
         | 
| 69 | 
            +
                    expect(subject).to have(1).pose_words
         | 
| 70 | 
            +
                  end
         | 
| 69 71 | 
             
                end
         | 
| 70 | 
            -
              end
         | 
| 71 72 |  | 
| 72 73 |  | 
| 73 | 
            -
             | 
| 74 | 
            +
                describe 'search' do
         | 
| 74 75 |  | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 76 | 
            +
                  it 'works' do
         | 
| 77 | 
            +
                    pos = PosableOne.create text: 'foo'
         | 
| 78 | 
            +
                    result = Pose.search 'foo', PosableOne
         | 
| 79 | 
            +
                    expect(result).to eq({ PosableOne => [pos] })
         | 
| 80 | 
            +
                  end
         | 
| 80 81 |  | 
| 81 | 
            -
             | 
| 82 | 
            +
                  describe 'classes parameter' do
         | 
| 82 83 |  | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 84 | 
            +
                    before :each do
         | 
| 85 | 
            +
                      @pos1 = PosableOne.create text: 'foo'
         | 
| 86 | 
            +
                      @pos2 = PosableTwo.create text: 'foo'
         | 
| 87 | 
            +
                    end
         | 
| 87 88 |  | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 89 | 
            +
                    it 'returns all requested classes' do
         | 
| 90 | 
            +
                      result = Pose.search 'foo', [PosableOne, PosableTwo]
         | 
| 90 91 |  | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 92 | 
            +
                      expect(result.keys).to have(2).items
         | 
| 93 | 
            +
                      expect(result.keys).to include PosableOne
         | 
| 94 | 
            +
                      expect(result.keys).to include PosableTwo
         | 
| 95 | 
            +
                    end
         | 
| 95 96 |  | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 97 | 
            +
                    it 'returns all matching instances of each requested class' do
         | 
| 98 | 
            +
                      result = Pose.search 'foo', [PosableOne, PosableTwo]
         | 
| 98 99 |  | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 100 | 
            +
                      expect(result[PosableOne]).to eq [@pos1]
         | 
| 101 | 
            +
                      expect(result[PosableTwo]).to eq [@pos2]
         | 
| 102 | 
            +
                    end
         | 
| 102 103 |  | 
| 103 | 
            -
             | 
| 104 | 
            -
             | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 104 | 
            +
                    it 'returns only instances of the given classes' do
         | 
| 105 | 
            +
                      result = Pose.search 'foo', PosableOne
         | 
| 106 | 
            +
                      expect(result.keys).to include PosableOne
         | 
| 107 | 
            +
                      result.keys.should_not include PosableTwo
         | 
| 108 | 
            +
                    end
         | 
| 107 109 | 
             
                  end
         | 
| 108 | 
            -
                end
         | 
| 109 110 |  | 
| 110 | 
            -
             | 
| 111 | 
            +
                  describe 'query parameter' do
         | 
| 111 112 |  | 
| 112 | 
            -
             | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 113 | 
            +
                    it 'returns an empty array if nothing matches' do
         | 
| 114 | 
            +
                      pos1 = PosableOne.create text: 'one'
         | 
| 115 | 
            +
                      result = Pose.search 'two', PosableOne
         | 
| 116 | 
            +
                      expect(result[PosableOne]).to be_empty
         | 
| 117 | 
            +
                    end
         | 
| 117 118 |  | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
             | 
| 119 | 
            +
                    it 'returns only objects that match all given query words' do
         | 
| 120 | 
            +
                      pos1 = PosableOne.create text: 'one two'
         | 
| 121 | 
            +
                      pos2 = PosableOne.create text: 'one three'
         | 
| 122 | 
            +
                      pos3 = PosableOne.create text: 'two three'
         | 
| 122 123 |  | 
| 123 | 
            -
             | 
| 124 | 
            +
                      result = Pose.search 'two one', PosableOne
         | 
| 124 125 |  | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 126 | 
            +
                      expect(result[PosableOne]).to eq [pos1]
         | 
| 127 | 
            +
                    end
         | 
| 127 128 |  | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 129 | 
            +
                    it 'returns nothing if searching for a non-existing word' do
         | 
| 130 | 
            +
                      pos1 = PosableOne.create text: 'one two'
         | 
| 131 | 
            +
                      result = Pose.search 'one zonk', PosableOne
         | 
| 132 | 
            +
                      expect(result[PosableOne]).to be_empty
         | 
| 133 | 
            +
                    end
         | 
| 133 134 |  | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 135 | 
            +
                    it 'works if the query is given in uppercase' do
         | 
| 136 | 
            +
                      pos1 = PosableOne.create text: 'one two'
         | 
| 137 | 
            +
                      result = Pose.search 'OnE TwO', PosableOne
         | 
| 138 | 
            +
                      expect(result[PosableOne]).to eq [pos1]
         | 
| 139 | 
            +
                    end
         | 
| 138 140 | 
             
                  end
         | 
| 139 | 
            -
                end
         | 
| 140 141 |  | 
| 141 142 |  | 
| 142 | 
            -
             | 
| 143 | 
            +
                  describe "'limit' parameter" do
         | 
| 143 144 |  | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 145 | 
            +
                    before :each do
         | 
| 146 | 
            +
                      @pos1 = FactoryGirl.create :posable_one, text: 'foo', private: true
         | 
| 147 | 
            +
                      @pos2 = FactoryGirl.create :posable_one, text: 'foo', private: true
         | 
| 148 | 
            +
                      @pos3 = FactoryGirl.create :posable_one, text: 'foo', private: false
         | 
| 149 | 
            +
                    end
         | 
| 149 150 |  | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
             | 
| 151 | 
            +
                    context 'with ids and no scope' do
         | 
| 152 | 
            +
                      it 'limits the result set to the given number' do
         | 
| 153 | 
            +
                        result = Pose.search 'foo', PosableOne, result_type: :ids, limit: 1
         | 
| 154 | 
            +
                        expect(result[PosableOne]).to have(1).item
         | 
| 155 | 
            +
                      end
         | 
| 154 156 | 
             
                    end
         | 
| 155 | 
            -
                  end
         | 
| 156 157 |  | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
             | 
| 158 | 
            +
                    context 'with ids and scope' do
         | 
| 159 | 
            +
                      it 'limits the result set to the given number' do
         | 
| 160 | 
            +
                        result = Pose.search 'foo', PosableOne, result_type: :ids, limit: 1, where: [private: false]
         | 
| 161 | 
            +
                        expect(result[PosableOne]).to have(1).item
         | 
| 162 | 
            +
                      end
         | 
| 161 163 | 
             
                    end
         | 
| 162 | 
            -
                  end
         | 
| 163 164 |  | 
| 164 | 
            -
             | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 167 | 
            -
             | 
| 165 | 
            +
                    context 'with classes and no scope' do
         | 
| 166 | 
            +
                      it 'limits the result set to the given number' do
         | 
| 167 | 
            +
                        result = Pose.search 'foo', PosableOne, limit: 1
         | 
| 168 | 
            +
                        expect(result[PosableOne]).to have(1).item
         | 
| 169 | 
            +
                      end
         | 
| 168 170 | 
             
                    end
         | 
| 169 | 
            -
                  end
         | 
| 170 171 |  | 
| 171 | 
            -
             | 
| 172 | 
            -
             | 
| 173 | 
            -
             | 
| 174 | 
            -
             | 
| 172 | 
            +
                    context 'with classes and scope' do
         | 
| 173 | 
            +
                      it 'limits the result set to the given number' do
         | 
| 174 | 
            +
                        result = Pose.search 'foo', PosableOne, limit: 1, where: [private: false]
         | 
| 175 | 
            +
                        expect(result[PosableOne]).to have(1).item
         | 
| 176 | 
            +
                      end
         | 
| 175 177 | 
             
                    end
         | 
| 176 178 | 
             
                  end
         | 
| 177 | 
            -
                end
         | 
| 178 179 |  | 
| 179 180 |  | 
| 180 | 
            -
             | 
| 181 | 
            -
             | 
| 182 | 
            -
                  before :each do
         | 
| 183 | 
            -
                    @foo_one = FactoryGirl.create :posable_one, text: 'foo one'
         | 
| 184 | 
            -
                  end
         | 
| 181 | 
            +
                  describe "'result_type' parameter" do
         | 
| 185 182 |  | 
| 186 | 
            -
             | 
| 187 | 
            -
             | 
| 188 | 
            -
                      result = Pose.search 'foo', PosableOne
         | 
| 189 | 
            -
                      result[PosableOne].first.should == @foo_one
         | 
| 183 | 
            +
                    before :each do
         | 
| 184 | 
            +
                      @foo_one = FactoryGirl.create :posable_one, text: 'foo one'
         | 
| 190 185 | 
             
                    end
         | 
| 191 | 
            -
                  end
         | 
| 192 186 |  | 
| 193 | 
            -
             | 
| 194 | 
            -
             | 
| 195 | 
            -
             | 
| 196 | 
            -
             | 
| 187 | 
            +
                    describe 'default behavior' do
         | 
| 188 | 
            +
                      it 'returns full objects' do
         | 
| 189 | 
            +
                        result = Pose.search 'foo', PosableOne
         | 
| 190 | 
            +
                        expect(result[PosableOne].first).to eq @foo_one
         | 
| 191 | 
            +
                      end
         | 
| 197 192 | 
             
                    end
         | 
| 198 | 
            -
                  end
         | 
| 199 | 
            -
                end
         | 
| 200 | 
            -
             | 
| 201 | 
            -
             | 
| 202 | 
            -
                describe "'where' parameter" do
         | 
| 203 193 |  | 
| 204 | 
            -
             | 
| 205 | 
            -
             | 
| 206 | 
            -
             | 
| 207 | 
            -
             | 
| 194 | 
            +
                    context ':ids given' do
         | 
| 195 | 
            +
                      it 'returns ids instead of objects' do
         | 
| 196 | 
            +
                        result = Pose.search 'foo', PosableOne, result_type: :ids
         | 
| 197 | 
            +
                        expect(result[PosableOne].first).to eq @foo_one.id
         | 
| 198 | 
            +
                      end
         | 
| 199 | 
            +
                    end
         | 
| 208 200 | 
             
                  end
         | 
| 209 201 |  | 
| 210 | 
            -
                  context 'with result type :classes' do
         | 
| 211 202 |  | 
| 212 | 
            -
             | 
| 213 | 
            -
                      result = Pose.search 'foo', PosableOne, where: [ private: true ]
         | 
| 214 | 
            -
                      result[PosableOne].should have(1).item
         | 
| 215 | 
            -
                      result[PosableOne].should include @one
         | 
| 216 | 
            -
                    end
         | 
| 217 | 
            -
             | 
| 218 | 
            -
                    it 'allows to use the hash syntax for queries' do
         | 
| 219 | 
            -
                      result = Pose.search 'foo', PosableOne, where: [ private: true ]
         | 
| 220 | 
            -
                      result[PosableOne].should have(1).item
         | 
| 221 | 
            -
                      result[PosableOne].should include @one
         | 
| 222 | 
            -
                    end
         | 
| 203 | 
            +
                  describe "'where' parameter" do
         | 
| 223 204 |  | 
| 224 | 
            -
                     | 
| 225 | 
            -
                       | 
| 226 | 
            -
                       | 
| 227 | 
            -
                       | 
| 205 | 
            +
                    before :each do
         | 
| 206 | 
            +
                      @one = FactoryGirl.create :posable_one, text: 'foo one', private: true
         | 
| 207 | 
            +
                      @bar = FactoryGirl.create :posable_one, text: 'bar one', private: true
         | 
| 208 | 
            +
                      @two = FactoryGirl.create :posable_one, text: 'foo two', private: false
         | 
| 228 209 | 
             
                    end
         | 
| 229 210 |  | 
| 230 | 
            -
                     | 
| 231 | 
            -
             | 
| 232 | 
            -
                       | 
| 233 | 
            -
             | 
| 234 | 
            -
             | 
| 211 | 
            +
                    context 'with result type :classes' do
         | 
| 212 | 
            +
             | 
| 213 | 
            +
                      it 'limits the result set by the given conditions' do
         | 
| 214 | 
            +
                        result = Pose.search 'foo', PosableOne, where: [ private: true ]
         | 
| 215 | 
            +
                        expect(result[PosableOne]).to have(1).item
         | 
| 216 | 
            +
                        expect(result[PosableOne]).to include @one
         | 
| 217 | 
            +
                      end
         | 
| 218 | 
            +
             | 
| 219 | 
            +
                      it 'allows to use the hash syntax for queries' do
         | 
| 220 | 
            +
                        result = Pose.search 'foo', PosableOne, where: [ private: true ]
         | 
| 221 | 
            +
                        expect(result[PosableOne]).to have(1).item
         | 
| 222 | 
            +
                        expect(result[PosableOne]).to include @one
         | 
| 223 | 
            +
                      end
         | 
| 224 | 
            +
             | 
| 225 | 
            +
                      it 'allows to use the string syntax for queries' do
         | 
| 226 | 
            +
                        result = Pose.search 'foo', PosableOne, where: [ ['private = ?', true] ]
         | 
| 227 | 
            +
                        expect(result[PosableOne]).to have(1).item
         | 
| 228 | 
            +
                        expect(result[PosableOne]).to include @one
         | 
| 229 | 
            +
                      end
         | 
| 230 | 
            +
             | 
| 231 | 
            +
                      it 'allows to combine several conditions' do
         | 
| 232 | 
            +
                        three = FactoryGirl.create :posable_one, text: 'foo two', private: true
         | 
| 233 | 
            +
                        result = Pose.search 'foo', PosableOne, where: [ {private: true}, ['text = ?', 'foo two'] ]
         | 
| 234 | 
            +
                        expect(result[PosableOne]).to have(1).item
         | 
| 235 | 
            +
                        expect(result[PosableOne]).to include three
         | 
| 236 | 
            +
                      end
         | 
| 235 237 | 
             
                    end
         | 
| 236 | 
            -
                  end
         | 
| 237 238 |  | 
| 238 | 
            -
             | 
| 239 | 
            +
                    context 'with result type :ids' do
         | 
| 239 240 |  | 
| 240 | 
            -
             | 
| 241 | 
            -
             | 
| 242 | 
            -
             | 
| 243 | 
            -
             | 
| 241 | 
            +
                      it 'limits the result set by the given condition' do
         | 
| 242 | 
            +
                        result = Pose.search 'foo', PosableOne, result_type: :ids, where: [ private: true ]
         | 
| 243 | 
            +
                        expect(result[PosableOne]).to have(1).item
         | 
| 244 | 
            +
                        expect(result[PosableOne]).to include @one.id
         | 
| 245 | 
            +
                      end
         | 
| 244 246 | 
             
                    end
         | 
| 245 247 | 
             
                  end
         | 
| 246 248 | 
             
                end
         | 
| 247 | 
            -
              end
         | 
| 248 249 |  | 
| 249 250 |  | 
| 250 | 
            -
             | 
| 251 | 
            +
                describe 'autocomplete_words' do
         | 
| 251 252 |  | 
| 252 | 
            -
             | 
| 253 | 
            -
             | 
| 253 | 
            +
                  it 'returns words that start with the given phrase' do
         | 
| 254 | 
            +
                    PosableOne.create text: 'great green pine tree'
         | 
| 254 255 |  | 
| 255 | 
            -
             | 
| 256 | 
            +
                    result = Pose.autocomplete_words 'gr'
         | 
| 256 257 |  | 
| 257 | 
            -
             | 
| 258 | 
            -
             | 
| 259 | 
            -
             | 
| 260 | 
            -
             | 
| 258 | 
            +
                    expect(result).to have(2).words
         | 
| 259 | 
            +
                    expect(result).to include 'great'
         | 
| 260 | 
            +
                    expect(result).to include 'green'
         | 
| 261 | 
            +
                  end
         | 
| 261 262 |  | 
| 262 | 
            -
             | 
| 263 | 
            -
             | 
| 264 | 
            -
             | 
| 265 | 
            -
             | 
| 266 | 
            -
             | 
| 263 | 
            +
                  it 'returns words that match the given phrase exactly' do
         | 
| 264 | 
            +
                    Word.create text: 'cat'
         | 
| 265 | 
            +
                    result = Pose.autocomplete_words 'cat'
         | 
| 266 | 
            +
                    expect(result).to eq ['cat']
         | 
| 267 | 
            +
                  end
         | 
| 267 268 |  | 
| 268 | 
            -
             | 
| 269 | 
            -
             | 
| 270 | 
            -
             | 
| 271 | 
            -
             | 
| 272 | 
            -
             | 
| 273 | 
            -
             | 
| 269 | 
            +
                  it 'stems the search query' do
         | 
| 270 | 
            +
                    PosableOne.create text: 'car'
         | 
| 271 | 
            +
                    result = Pose.autocomplete_words 'cars'
         | 
| 272 | 
            +
                    expect(result).to have(1).words
         | 
| 273 | 
            +
                    expect(result[0]).to eq 'car'
         | 
| 274 | 
            +
                  end
         | 
| 274 275 |  | 
| 275 | 
            -
             | 
| 276 | 
            -
             | 
| 277 | 
            -
             | 
| 278 | 
            -
             | 
| 276 | 
            +
                  it 'returns nothing if the search query is empty' do
         | 
| 277 | 
            +
                    PosableOne.create text: 'foo bar'
         | 
| 278 | 
            +
                    result = Pose.autocomplete_words ''
         | 
| 279 | 
            +
                    expect(result).to be_empty
         | 
| 280 | 
            +
                  end
         | 
| 279 281 | 
             
                end
         | 
| 280 282 | 
             
              end
         | 
| 281 283 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -1,95 +1,39 @@ | |
| 1 | 
            -
            # | 
| 2 | 
            -
             | 
| 3 | 
            -
            require  | 
| 4 | 
            -
            require ' | 
| 5 | 
            -
            require ' | 
| 6 | 
            -
            require ' | 
| 7 | 
            -
            require 'active_support/core_ext/module/aliasing'
         | 
| 8 | 
            -
            require 'active_support/core_ext/string'
         | 
| 9 | 
            -
            require 'pose'
         | 
| 1 | 
            +
            # This file is copied to spec/ when you run 'rails generate rspec:install'
         | 
| 2 | 
            +
            ENV["RAILS_ENV"] ||= 'test'
         | 
| 3 | 
            +
            require File.expand_path("../dummy/config/environment.rb",  __FILE__)
         | 
| 4 | 
            +
            require 'rspec/rails'
         | 
| 5 | 
            +
            require 'rspec/autorun'
         | 
| 6 | 
            +
            require 'factory_girl_rails'
         | 
| 10 7 | 
             
            require 'faker'
         | 
| 11 | 
            -
            require 'factory_girl'
         | 
| 12 | 
            -
            require 'database_cleaner'
         | 
| 13 | 
            -
             | 
| 14 | 
            -
            FactoryGirl.find_definitions
         | 
| 15 | 
            -
             | 
| 16 | 
            -
            # Configure Rails Environment
         | 
| 17 | 
            -
            ENV["RAILS_ENV"] = "test"
         | 
| 18 | 
            -
            Rails = Hashie::Mash.new({env: 'test'})
         | 
| 19 | 
            -
             | 
| 20 | 
            -
            # We have no Railtie in these tests --> load Pose manually.
         | 
| 21 | 
            -
            ActiveRecord::Base.send :extend, Pose::ActiveRecordBaseAdditions
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            # Load support files
         | 
| 24 | 
            -
            Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
         | 
| 25 8 |  | 
| 9 | 
            +
            # Requires supporting ruby files with custom matchers and macros, etc,
         | 
| 10 | 
            +
            # in spec/support/ and its subdirectories.
         | 
| 11 | 
            +
            Dir["#{File.dirname __FILE__}/support/**/*.rb"].each {|f| require f}
         | 
| 26 12 |  | 
| 27 13 | 
             
            RSpec.configure do |config|
         | 
| 28 | 
            -
              #  | 
| 14 | 
            +
              # ## Mock Framework
         | 
| 29 15 | 
             
              #
         | 
| 30 16 | 
             
              # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
         | 
| 31 17 | 
             
              #
         | 
| 32 18 | 
             
              # config.mock_with :mocha
         | 
| 33 19 | 
             
              # config.mock_with :flexmock
         | 
| 34 20 | 
             
              # config.mock_with :rr
         | 
| 35 | 
            -
              config.mock_with :rspec
         | 
| 36 21 |  | 
| 37 22 | 
             
              # If you're not using ActiveRecord, or you'd prefer not to run each of your
         | 
| 38 23 | 
             
              # examples within a transaction, remove the following line or assign false
         | 
| 39 24 | 
             
              # instead of true.
         | 
| 40 | 
            -
               | 
| 41 | 
            -
             | 
| 42 | 
            -
              config.before :suite do
         | 
| 43 | 
            -
                setup_db
         | 
| 44 | 
            -
                DatabaseCleaner.strategy = :deletion
         | 
| 45 | 
            -
              end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
              config.before :each do
         | 
| 48 | 
            -
                DatabaseCleaner.start
         | 
| 49 | 
            -
              end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
              config.after :each do
         | 
| 52 | 
            -
                DatabaseCleaner.clean
         | 
| 53 | 
            -
              end
         | 
| 54 | 
            -
            end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
            #####################
         | 
| 58 | 
            -
            # DATABASE SETUP
         | 
| 59 | 
            -
            #
         | 
| 60 | 
            -
             | 
| 61 | 
            -
            def setup_db
         | 
| 62 | 
            -
              ActiveRecord::Base.establish_connection adapter:      'postgresql',
         | 
| 63 | 
            -
                                                      database:     'pose_test',
         | 
| 64 | 
            -
                                                      min_messages: 'INFO'
         | 
| 65 | 
            -
             | 
| 66 | 
            -
              ActiveRecord::Schema.define(version: 1) do
         | 
| 67 | 
            -
                unless table_exists? 'posable_ones'
         | 
| 68 | 
            -
                  create_table 'posable_ones' do |t|
         | 
| 69 | 
            -
                    t.string 'text'
         | 
| 70 | 
            -
                    t.boolean 'private'
         | 
| 71 | 
            -
                  end
         | 
| 72 | 
            -
                end
         | 
| 25 | 
            +
              config.use_transactional_fixtures = true
         | 
| 73 26 |  | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
                  end
         | 
| 79 | 
            -
                end
         | 
| 27 | 
            +
              # If true, the base class of anonymous controllers will be inferred
         | 
| 28 | 
            +
              # automatically. This will be the default behavior in future versions of
         | 
| 29 | 
            +
              # rspec-rails.
         | 
| 30 | 
            +
              config.infer_base_class_for_anonymous_controllers = false
         | 
| 80 31 |  | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
                  end
         | 
| 87 | 
            -
                end
         | 
| 32 | 
            +
              # Run specs in random order to surface order dependencies. If you find an
         | 
| 33 | 
            +
              # order dependency and want to debug it, you can fix the order by providing
         | 
| 34 | 
            +
              # the seed, which is printed after each run.
         | 
| 35 | 
            +
              #     --seed 1234
         | 
| 36 | 
            +
              config.order = "random"
         | 
| 88 37 |  | 
| 89 | 
            -
             | 
| 90 | 
            -
                  create_table "pose_words" do |t|
         | 
| 91 | 
            -
                    t.string "text", limit: 80, null: false
         | 
| 92 | 
            -
                  end
         | 
| 93 | 
            -
                end
         | 
| 94 | 
            -
              end
         | 
| 38 | 
            +
              config.include FactoryGirl::Syntax::Methods
         | 
| 95 39 | 
             
            end
         | 
    
        data/spec/support/matchers.rb
    CHANGED