thinking-sphinx-shoulda-matchers 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in thinking-sphinx-shoulda-matchers.gemspec
4
+ gemspec
@@ -0,0 +1,26 @@
1
+ # Thinking Sphinx matchers
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
+
4
+ # Installation
5
+ To install the matchers you only have to add the gem to your test group in `Gemfile`:
6
+
7
+ > group :test do
8
+ > gem 'thinking-sphinx-shoulda-matchers'
9
+ > end
10
+
11
+ # 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
20
+
21
+ # References
22
+ [1] http://openmonkey.com/2009/07/19/thinking-sphinx-rspec-matchers/
23
+ [2] https://gist.github.com/21755
24
+
25
+ # Credits
26
+ Thanks to Pal Allan from http://freelancing-gods.com/ for creating Thinking Sphinx!
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require_relative "thinking-sphinx-shoulda-matchers/field_matcher.rb"
2
+ require_relative "thinking-sphinx-shoulda-matchers/attribute_matcher.rb"
@@ -0,0 +1,26 @@
1
+ require 'rspec'
2
+
3
+ RSpec::Matchers.define(:have_attribute) do |attribute, args|
4
+ options = args.nil? ? {} : args.dup
5
+
6
+ match do |model|
7
+ if model.sphinx_indexes?
8
+ model.class.define_indexes
9
+ model.sphinx_indexes.first.attributes.select {|f| f.columns.first.__name == attribute && f.alias == options[:as] }.count == 1
10
+ else
11
+ false
12
+ end
13
+ end
14
+
15
+ failure_message_for_should do |actual|
16
+ "expected #{actual} to have an attribute for #{attribute.to_sym}"
17
+ end
18
+
19
+ failure_message_for_should_not do |actual|
20
+ "expected #{actual} not to define an attribute for #{attribute.to_sym}"
21
+ end
22
+
23
+ description do
24
+ "have a search attribute for #{options[:as] || attribute}"
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ require 'rspec'
2
+
3
+ RSpec::Matchers.define(:index) do |field, args|
4
+ options = args.nil? ? {} : args.dup
5
+ options[:from] = Array(options[:from])
6
+
7
+ match do |model|
8
+ if model.sphinx_indexes?
9
+ 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
11
+ else
12
+ false
13
+ end
14
+ end
15
+
16
+ failure_message_for_should do |actual|
17
+ "expected #{actual} to define an index for #{field.to_sym}"
18
+ end
19
+
20
+ failure_message_for_should_not do |actual|
21
+ "expected #{actual} not to define an index for #{field.to_sym}"
22
+ end
23
+
24
+ description do
25
+ "have an index field for #{options[:as] || field}"
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "thinking-sphinx-shoulda-matchers"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Alejandro Andres"]
8
+ s.email = ["fuzzy.alej@gmail.com"]
9
+ s.homepage = "http://alejandroandres.com/"
10
+ s.summary = %q{Shoulda matchers for Thinking Sphinx}
11
+ s.description = %q{Shoulda matchers for Thinking Sphinx}
12
+
13
+ s.rubyforge_project = "thinking-sphinx-shoulda-matchers"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # specify any dependencies here; for example:
21
+ s.add_development_dependency "rspec"
22
+ s.add_development_dependency "shoulda"
23
+ s.add_runtime_dependency "rspec"
24
+ s.add_runtime_dependency "shoulda"
25
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thinking-sphinx-shoulda-matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alejandro Andres
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2152353880 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2152353880
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ requirement: &2152349620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2152349620
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &2152347780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2152347780
47
+ - !ruby/object:Gem::Dependency
48
+ name: shoulda
49
+ requirement: &2152342580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2152342580
58
+ description: Shoulda matchers for Thinking Sphinx
59
+ email:
60
+ - fuzzy.alej@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - lib/thinking-sphinx-shoulda-matchers.rb
70
+ - lib/thinking-sphinx-shoulda-matchers/attribute_matcher.rb
71
+ - lib/thinking-sphinx-shoulda-matchers/field_matcher.rb
72
+ - thinking-sphinx-shoulda-matchers.gemspec
73
+ homepage: http://alejandroandres.com/
74
+ licenses: []
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project: thinking-sphinx-shoulda-matchers
93
+ rubygems_version: 1.8.10
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Shoulda matchers for Thinking Sphinx
97
+ test_files: []