Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 131 lines (95 sloc) 3.739 kb
860e519 @karmi [ACTIVEMODEL] Fixed error where persistent model was not found with a li...
authored
1 require 'test_helper'
2
19e570b @karmi [GEM] Updated gem name to "tire" and renamed all files from "slingshot" ...
authored
3 module Tire
860e519 @karmi [ACTIVEMODEL] Fixed error where persistent model was not found with a li...
authored
4
5 class PersistentModelIntegrationTest < Test::Unit::TestCase
6 include Test::Integration
7
8 def setup
9 super
10 PersistentArticle.index.delete
11 end
12
13 def teardown
14 super
15 PersistentArticle.index.delete
db6e911 @karmi [ACTIVEMODEL] Added support for property defaults in Tire::Model::Persis...
authored
16 PersistentArticleWithDefaults.index.delete
860e519 @karmi [ACTIVEMODEL] Fixed error where persistent model was not found with a li...
authored
17 end
18
19 context "PersistentModel" do
32bf8d3 @karmi [PERSISTENCE] Changed that search in persistence returns instances of mo...
authored
20 should "search with simple query" do
21 PersistentArticle.create :id => 1, :title => 'One'
22 PersistentArticle.index.refresh
23
24 results = PersistentArticle.search 'one'
25 assert_equal 'One', results.first.title
26 end
27
28 should "search with a block" do
29 PersistentArticle.create :id => 1, :title => 'One'
30 PersistentArticle.index.refresh
31
32 results = PersistentArticle.search(:sort => 'title') { query { string 'one' } }
33 assert_equal 'One', results.first.title
34 end
35
36 should "return instances of model" do
37 PersistentArticle.create :id => 1, :title => 'One'
38 PersistentArticle.index.refresh
39
40 results = PersistentArticle.search 'one'
41 assert_instance_of PersistentArticle, results.first
42 end
43
860e519 @karmi [ACTIVEMODEL] Fixed error where persistent model was not found with a li...
authored
44 should "save documents into index and find them by IDs" do
45 one = PersistentArticle.create :id => 1, :title => 'One'
46 two = PersistentArticle.create :id => 2, :title => 'Two'
47
48 PersistentArticle.index.refresh
49
50 results = PersistentArticle.find [1, 2]
51
52 assert_equal 2, results.size
2191823 @karmi [#352] [FIX] Fixes MyModel#persisted? for Tire::Model::Persistence integ...
authored
53 end
54
55 should "be persisted" do
56 one = PersistentArticle.create :id => 1, :title => 'One'
57 PersistentArticle.index.refresh
58
59 a = PersistentArticle.all.first
60 assert a.persisted?, a.inspect
61
62 b = PersistentArticle.first
63 assert b.persisted?, b.inspect
630a007 @vwall Added support for Kaminari
vwall authored
64
2191823 @karmi [#352] [FIX] Fixes MyModel#persisted? for Tire::Model::Persistence integ...
authored
65 c = PersistentArticle.search { query { string 'one' } }.first
66 assert c.persisted?, c.inspect
860e519 @karmi [ACTIVEMODEL] Fixed error where persistent model was not found with a li...
authored
67 end
fd0ee47 @karmi [TEST] Added test for paginated search in persistent model
authored
68
db6e911 @karmi [ACTIVEMODEL] Added support for property defaults in Tire::Model::Persis...
authored
69 should "return default values for properties without value" do
70 PersistentArticleWithDefaults.create :id => 1, :title => 'One'
71 PersistentArticleWithDefaults.index.refresh
72
73 results = PersistentArticleWithDefaults.all
74
75 assert_equal [], results.first.tags
76 end
77
fd0ee47 @karmi [TEST] Added test for paginated search in persistent model
authored
78 context "with pagination" do
79
80 setup do
81 1.upto(9) { |number| PersistentArticle.create :title => "Test#{number}" }
1255bfc @karmi [ACTIVEMODEL] Implemented all Tire features for models via a `MyModel.ti...
authored
82 PersistentArticle.index.refresh
fd0ee47 @karmi [TEST] Added test for paginated search in persistent model
authored
83 end
84
85 should "find first page with five results" do
86 results = PersistentArticle.search( :per_page => 5, :page => 1 ) { query { all } }
357b053 @andrewtimberlake Changed `MyModel.search` implementation so it allows passing the :page, ...
andrewtimberlake authored
87 assert_equal 5, results.size
fd0ee47 @karmi [TEST] Added test for paginated search in persistent model
authored
88
630a007 @vwall Added support for Kaminari
vwall authored
89 # WillPaginate
90 #
fd0ee47 @karmi [TEST] Added test for paginated search in persistent model
authored
91 assert_equal 2, results.total_pages
92 assert_equal 1, results.current_page
93 assert_equal nil, results.previous_page
94 assert_equal 2, results.next_page
630a007 @vwall Added support for Kaminari
vwall authored
95
96 # Kaminari
97 #
98 assert_equal 5, results.limit_value
99 assert_equal 9, results.total_count
100 assert_equal 2, results.num_pages
101 assert_equal 0, results.offset_value
fd0ee47 @karmi [TEST] Added test for paginated search in persistent model
authored
102 end
26f01b0 @karmi [ACTIVEMODEL] Fixed and cleaned up URL-escaping of document type
authored
103
104 end
105
106 context "with namespaced models" do
107 setup do
108 MyNamespace::PersistentArticleInNamespace.create :title => 'Test'
109 MyNamespace::PersistentArticleInNamespace.index.refresh
110 end
111
112 teardown do
113 MyNamespace::PersistentArticleInNamespace.index.delete
114 end
115
116 should "find the document in the index" do
117 results = MyNamespace::PersistentArticleInNamespace.search 'test'
118
119 assert results.any?, "No results returned: #{results.inspect}"
120 assert_equal 1, results.count
121
122 assert_instance_of MyNamespace::PersistentArticleInNamespace, results.first
123 end
124
fd0ee47 @karmi [TEST] Added test for paginated search in persistent model
authored
125 end
126
860e519 @karmi [ACTIVEMODEL] Fixed error where persistent model was not found with a li...
authored
127 end
128
129 end
130 end
Something went wrong with that request. Please try again.