thinking-sphinx-shoulda-matchers 0.0.1 → 0.0.2

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/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  *.gem
2
+ *.swp
3
+ *.swo
2
4
  .bundle
3
5
  Gemfile.lock
4
6
  pkg/*
data/README.md CHANGED
@@ -1,26 +1,41 @@
1
1
  # Thinking Sphinx matchers
2
2
  Ok, so here I present you my first gem. It was created out of necessity and I hope to both be useful to the community and learn a lot in the process!
3
3
 
4
+
4
5
  # Installation
5
6
  To install the matchers you only have to add the gem to your test group in `Gemfile`:
6
7
 
7
- > group :test do
8
- > gem 'thinking-sphinx-shoulda-matchers'
9
- > end
8
+ group :test do
9
+ gem 'thinking-sphinx-shoulda-matchers'
10
+ end
11
+
10
12
 
11
13
  # Use
12
- > describe "fields" do
13
- > it { should index :name, :from => :client, :as => :client_name }
14
- > it { should index :content }
15
- > end
16
- >
17
- > describe "attributes" do
18
- > it { should have_attribute :user_id, :as => :users }
19
- > end
14
+ describe "fields" do
15
+ it { should index :name, :from = :client, :as = :client_name }
16
+ it { should index :content }
17
+ end
18
+
19
+ describe "attributes" do
20
+ it { should have_attribute :user_id, :as = :users }
21
+ end
22
+
23
+ Field options
24
+ :from
25
+ :as
26
+ :facet
27
+ :sortable
28
+
29
+ Attribute Field options
30
+ :as
31
+ :facet
20
32
 
21
33
  # References
22
34
  [1] http://openmonkey.com/2009/07/19/thinking-sphinx-rspec-matchers/
35
+
23
36
  [2] https://gist.github.com/21755
24
37
 
38
+
25
39
  # Credits
26
40
  Thanks to Pal Allan from http://freelancing-gods.com/ for creating Thinking Sphinx!
41
+ Thanks to Tim Riley for the initial version of the matcher
@@ -2,22 +2,27 @@ require 'rspec'
2
2
 
3
3
  RSpec::Matchers.define(:have_attribute) do |attribute, args|
4
4
  options = args.nil? ? {} : args.dup
5
+ options[:facet] ||= false
5
6
 
6
7
  match do |model|
7
8
  if model.sphinx_indexes?
8
9
  model.class.define_indexes
9
- model.sphinx_indexes.first.attributes.select {|f| f.columns.first.__name == attribute && f.alias == options[:as] }.count == 1
10
+ model.sphinx_indexes.first.attributes.select {|a|
11
+ a.columns.first.__name == attribute &&
12
+ a.alias == options[:as] &&
13
+ (a.faceted.nil? ? true : a.faceted == options[:facet])
14
+ }.count == 1
10
15
  else
11
16
  false
12
17
  end
13
18
  end
14
19
 
15
20
  failure_message_for_should do |actual|
16
- "expected #{actual} to have an attribute for #{attribute.to_sym}"
21
+ "expected #{actual} to have an attribute for #{attribute.to_sym} with params #{args}"
17
22
  end
18
23
 
19
24
  failure_message_for_should_not do |actual|
20
- "expected #{actual} not to define an attribute for #{attribute.to_sym}"
25
+ "expected #{actual} not to define an attribute for #{attribute.to_sym} with params #{args}"
21
26
  end
22
27
 
23
28
  description do
@@ -3,22 +3,30 @@ require 'rspec'
3
3
  RSpec::Matchers.define(:index) do |field, args|
4
4
  options = args.nil? ? {} : args.dup
5
5
  options[:from] = Array(options[:from])
6
+ options[:sortable] ||= false
7
+ options[:facet] ||= false
6
8
 
7
9
  match do |model|
8
10
  if model.sphinx_indexes?
9
11
  model.class.define_indexes
10
- model.sphinx_indexes.first.fields.select {|f| f.columns.first.__name == field && f.columns.first.__stack == options[:from] && f.alias == options[:as] }.count == 1
12
+ model.sphinx_indexes.first.fields.select {|f|
13
+ f.columns.first.__name == field &&
14
+ f.columns.first.__stack == options[:from] &&
15
+ f.alias == options[:as] &&
16
+ f.sortable == options[:sortable] &&
17
+ (f.faceted.nil? ? true : f.faceted == options[:facet])
18
+ }.count == 1
11
19
  else
12
20
  false
13
21
  end
14
22
  end
15
23
 
16
24
  failure_message_for_should do |actual|
17
- "expected #{actual} to define an index for #{field.to_sym}"
25
+ "expected #{actual} to define an index for #{field.to_sym} with params #{args}"
18
26
  end
19
27
 
20
28
  failure_message_for_should_not do |actual|
21
- "expected #{actual} not to define an index for #{field.to_sym}"
29
+ "expected #{actual} not to define an index for #{field.to_sym} with params #{args}"
22
30
  end
23
31
 
24
32
  description do
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "thinking-sphinx-shoulda-matchers"
6
- s.version = "0.0.1"
6
+ s.version = "0.0.2"
7
7
  s.authors = ["Alejandro Andres"]
8
8
  s.email = ["fuzzy.alej@gmail.com"]
9
9
  s.homepage = "http://alejandroandres.com/"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thinking-sphinx-shoulda-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-23 00:00:00.000000000Z
12
+ date: 2011-11-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152353880 !ruby/object:Gem::Requirement
16
+ requirement: &2153106220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152353880
24
+ version_requirements: *2153106220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &2152349620 !ruby/object:Gem::Requirement
27
+ requirement: &2153104840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152349620
35
+ version_requirements: *2153104840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2152347780 !ruby/object:Gem::Requirement
38
+ requirement: &2153103580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2152347780
46
+ version_requirements: *2153103580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: shoulda
49
- requirement: &2152342580 !ruby/object:Gem::Requirement
49
+ requirement: &2153101840 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2152342580
57
+ version_requirements: *2153101840
58
58
  description: Shoulda matchers for Thinking Sphinx
59
59
  email:
60
60
  - fuzzy.alej@gmail.com