semantically-taggable 0.2.0 → 0.2.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.
|
@@ -4,6 +4,8 @@ describe "Tagging articles" do
|
|
|
4
4
|
before(:each) do
|
|
5
5
|
reset_database!
|
|
6
6
|
@article = Article.new(:name => "Bob Jones")
|
|
7
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
|
8
|
+
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
it "should have tag schemes" do
|
|
@@ -37,9 +39,6 @@ describe "Tagging articles" do
|
|
|
37
39
|
|
|
38
40
|
it "should assign the associated scheme when tagging" do
|
|
39
41
|
@article.keyword_list = %w{one two three}
|
|
40
|
-
ActiveRecord::Base.logger.info "******* "
|
|
41
|
-
ActiveRecord::Base.logger.info "******* ASSOCIATED SCHEME"
|
|
42
|
-
ActiveRecord::Base.logger.info "******* "
|
|
43
42
|
@article.save
|
|
44
43
|
@article.keywords.each {|k| k.scheme.should == SemanticallyTaggable::Scheme.by_name(:keywords)}
|
|
45
44
|
end
|
|
@@ -8,6 +8,7 @@ describe SemanticallyTaggable::TagParentage do
|
|
|
8
8
|
reset_database!
|
|
9
9
|
import_rdf('dg_abridged.rdf')
|
|
10
10
|
SemanticallyTaggable::TagParentage.refresh_closure!
|
|
11
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
let(:taxonomy_tag) { SemanticallyTaggable::Tag.find_by_name('Directgov Taxonomy') }
|
|
@@ -17,7 +18,7 @@ describe SemanticallyTaggable::TagParentage do
|
|
|
17
18
|
|
|
18
19
|
specify { taxonomy_tag.should parent(travel_health_tag).at_distance(2) }
|
|
19
20
|
specify { taxonomy_tag.should parent(nhs_direct_tag).at_distance(3) }
|
|
20
|
-
specify { health_and_care_tag.should parent(nhs_direct_tag).at_distance(2)}
|
|
21
|
+
specify { health_and_care_tag.should parent(nhs_direct_tag).at_distance(2) }
|
|
21
22
|
|
|
22
23
|
it "should not make direct connections to indirect tags through narrower_tags" do
|
|
23
24
|
taxonomy_tag.narrower_tags.should_not include(nhs_direct_tag)
|
|
@@ -37,9 +38,28 @@ describe SemanticallyTaggable::TagParentage do
|
|
|
37
38
|
Article.tagged_with('Health and care', :on => :dg_topics).should have(1).article
|
|
38
39
|
end
|
|
39
40
|
|
|
41
|
+
|
|
40
42
|
it "should get all articles for the taxonomy" do
|
|
41
43
|
Article.tagged_with('Directgov taxonomy', :on => :dg_topics).should have(2).articles
|
|
42
44
|
end
|
|
45
|
+
|
|
46
|
+
describe "The :any option" do
|
|
47
|
+
subject { Article.tagged_with('Health and care', :on => :dg_topics, :any => true) }
|
|
48
|
+
|
|
49
|
+
it { should have(1).article }
|
|
50
|
+
its(:first) { should eql(@nhs_article) }
|
|
51
|
+
specify do
|
|
52
|
+
Article.tagged_with(['Health and care', 'Job Grants'], :on => :dg_topics, :any => true).
|
|
53
|
+
should have(2).articles
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe "Indirect exclusions" do
|
|
58
|
+
subject { Article.tagged_with(['Health and care', 'Travel'], :on => :dg_topics, :exclude => true) }
|
|
59
|
+
|
|
60
|
+
its(:length) { should eql(1) }
|
|
61
|
+
its(:first) { should eql(@jobs_article) }
|
|
62
|
+
end
|
|
43
63
|
end
|
|
44
64
|
end
|
|
45
65
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'spork'
|
|
3
|
+
|
|
4
|
+
spec_dir = File.dirname(__FILE__)
|
|
5
|
+
Spork.prefork do
|
|
6
|
+
# Loading more in this block will cause your tests to run faster. However,
|
|
7
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
|
8
|
+
# need to restart spork for it take effect.
|
|
9
|
+
$LOAD_PATH << spec_dir unless $LOAD_PATH.include?(spec_dir)
|
|
10
|
+
lib_path = File.expand_path(File.join(spec_dir, '../lib'))
|
|
11
|
+
$LOAD_PATH << lib_path unless $LOAD_PATH.include?(lib_path)
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
require "rubygems"
|
|
15
|
+
require "bundler"
|
|
16
|
+
|
|
17
|
+
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.5")
|
|
18
|
+
raise RuntimeError, "Your bundler version is too old." +
|
|
19
|
+
"Run `gem install bundler` to upgrade."
|
|
20
|
+
end
|
|
6
21
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
22
|
+
# Set up load paths for all bundled gems
|
|
23
|
+
Bundler.setup(:development)
|
|
24
|
+
rescue Bundler::GemNotFound
|
|
25
|
+
raise RuntimeError, "Bundler couldn't find some gems." +
|
|
26
|
+
"Did you run `bundle install`?"
|
|
10
27
|
end
|
|
11
28
|
|
|
12
|
-
|
|
13
|
-
Bundler.setup
|
|
14
|
-
rescue Bundler::GemNotFound
|
|
15
|
-
raise RuntimeError, "Bundler couldn't find some gems." +
|
|
16
|
-
"Did you run `bundle install`?"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
Bundler.require
|
|
20
|
-
|
|
21
|
-
require 'active_record'
|
|
29
|
+
Bundler.require
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
require 'rspec'
|
|
32
|
+
require 'active_record'
|
|
33
|
+
require File.expand_path('../../lib/semantically-taggable', __FILE__)
|
|
34
|
+
require 'database_seeder'
|
|
35
|
+
require 'semantically_taggable/shared_spec_helpers'
|
|
24
36
|
|
|
25
|
-
database_yml = File.expand_path('../database.yml', __FILE__)
|
|
26
|
-
if File.exists?(database_yml)
|
|
27
|
-
active_record_configuration = YAML.load_file(database_yml)[ENV['DB']]
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
|
31
|
-
else
|
|
32
|
-
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
|
|
33
|
-
end
|
|
38
|
+
ENV['DB'] ||= 'mysql'
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
database_yml = File.expand_path('../database.yml', __FILE__)
|
|
41
|
+
if File.exists?(database_yml)
|
|
42
|
+
active_record_configuration = YAML.load_file(database_yml)[ENV['DB']]
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
each { |e| k[e]+=1 }
|
|
44
|
-
k
|
|
45
|
-
end
|
|
44
|
+
ActiveRecord::Base.establish_connection(active_record_configuration)
|
|
45
|
+
ActiveRecord::Base.logger = Logger.new(File.join(spec_dir, "debug.log"))
|
|
46
|
+
else
|
|
47
|
+
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
|
|
46
48
|
end
|
|
47
|
-
end
|
|
48
49
|
|
|
49
50
|
# Set @@variable_name in a before(:all) block and give access to it
|
|
50
51
|
# via let(:variable_name)
|
|
@@ -57,42 +58,56 @@ end
|
|
|
57
58
|
# transaction.state.should == 'in_progress'
|
|
58
59
|
# end
|
|
59
60
|
# end
|
|
60
|
-
def set(variable_name, &block)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
def set(variable_name, &block)
|
|
62
|
+
before(:all) do
|
|
63
|
+
self.class.send(:class_variable_set, "@@#{variable_name}".to_sym, instance_eval(&block))
|
|
64
|
+
end
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
let(variable_name) do
|
|
67
|
+
self.class.send(:class_variable_get, "@@#{variable_name}".to_sym).tap do |i|
|
|
68
|
+
if i.respond_to?(:new_record?)
|
|
69
|
+
i.reload unless i.new_record?
|
|
70
|
+
end
|
|
69
71
|
end
|
|
70
72
|
end
|
|
71
73
|
end
|
|
72
|
-
end
|
|
73
74
|
|
|
74
|
-
RSpec::Matchers.define :parent do |expected|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
RSpec::Matchers.define :parent do |expected|
|
|
76
|
+
match do |actual|
|
|
77
|
+
sql = "SELECT * FROM tag_parentages WHERE parent_tag_id = #{actual.id} AND child_tag_id = #{expected.id} AND distance = #{@distance}"
|
|
78
|
+
rows = SemanticallyTaggable::TagParentage.find_by_sql(sql)
|
|
79
|
+
rows.length == 1
|
|
80
|
+
end
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
failure_message_for_should do
|
|
83
|
+
"Expected #{actual.name} to parent #{expected.name} at a distance of #{@distance}"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
chain :at_distance do |distance|
|
|
87
|
+
@distance = distance
|
|
88
|
+
end
|
|
83
89
|
end
|
|
84
90
|
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
unless [].respond_to?(:freq)
|
|
92
|
+
class Array
|
|
93
|
+
def freq
|
|
94
|
+
k = Hash.new(0)
|
|
95
|
+
each { |e| k[e]+=1 }
|
|
96
|
+
k
|
|
97
|
+
end
|
|
98
|
+
end
|
|
87
99
|
end
|
|
88
100
|
end
|
|
89
101
|
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
Spork.each_run do
|
|
103
|
+
# This code will be run each time you run your specs.
|
|
104
|
+
ActiveRecord::Base.silence do
|
|
105
|
+
ActiveRecord::Migration.verbose = false
|
|
92
106
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
end
|
|
107
|
+
load(spec_dir + '/schema.rb')
|
|
108
|
+
load_schemes!
|
|
109
|
+
load(spec_dir + '/models.rb')
|
|
110
|
+
end
|
|
97
111
|
|
|
98
|
-
reset_database!
|
|
112
|
+
reset_database!
|
|
113
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: semantically-taggable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
prerelease:
|
|
4
|
+
prerelease: false
|
|
6
5
|
segments:
|
|
7
6
|
- 0
|
|
8
7
|
- 2
|
|
9
|
-
-
|
|
10
|
-
version: 0.2.
|
|
8
|
+
- 2
|
|
9
|
+
version: 0.2.2
|
|
11
10
|
platform: ruby
|
|
12
11
|
authors:
|
|
13
12
|
- Russell Garner
|
|
@@ -15,129 +14,134 @@ autorequire:
|
|
|
15
14
|
bindir: bin
|
|
16
15
|
cert_chain: []
|
|
17
16
|
|
|
18
|
-
date: 2011-
|
|
17
|
+
date: 2011-07-05 00:00:00 +01:00
|
|
19
18
|
default_executable:
|
|
20
19
|
dependencies:
|
|
21
20
|
- !ruby/object:Gem::Dependency
|
|
22
|
-
|
|
23
|
-
type: :runtime
|
|
21
|
+
name: rails
|
|
24
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
23
|
none: false
|
|
26
24
|
requirements:
|
|
27
25
|
- - ">="
|
|
28
26
|
- !ruby/object:Gem::Version
|
|
29
|
-
hash: 7
|
|
30
27
|
segments:
|
|
31
28
|
- 3
|
|
32
29
|
- 0
|
|
33
30
|
version: "3.0"
|
|
34
|
-
|
|
31
|
+
type: :runtime
|
|
32
|
+
prerelease: false
|
|
35
33
|
version_requirements: *id001
|
|
36
34
|
- !ruby/object:Gem::Dependency
|
|
37
|
-
|
|
38
|
-
type: :runtime
|
|
35
|
+
name: activerecord
|
|
39
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
40
37
|
none: false
|
|
41
38
|
requirements:
|
|
42
39
|
- - ">="
|
|
43
40
|
- !ruby/object:Gem::Version
|
|
44
|
-
hash: 7
|
|
45
41
|
segments:
|
|
46
42
|
- 3
|
|
47
43
|
- 0
|
|
48
44
|
version: "3.0"
|
|
49
|
-
|
|
45
|
+
type: :runtime
|
|
46
|
+
prerelease: false
|
|
50
47
|
version_requirements: *id002
|
|
51
48
|
- !ruby/object:Gem::Dependency
|
|
52
|
-
|
|
53
|
-
type: :runtime
|
|
49
|
+
name: mysql
|
|
54
50
|
requirement: &id003 !ruby/object:Gem::Requirement
|
|
55
51
|
none: false
|
|
56
52
|
requirements:
|
|
57
53
|
- - ">="
|
|
58
54
|
- !ruby/object:Gem::Version
|
|
59
|
-
hash: 3
|
|
60
55
|
segments:
|
|
61
56
|
- 0
|
|
62
57
|
version: "0"
|
|
63
|
-
|
|
58
|
+
type: :runtime
|
|
59
|
+
prerelease: false
|
|
64
60
|
version_requirements: *id003
|
|
65
61
|
- !ruby/object:Gem::Dependency
|
|
66
|
-
|
|
67
|
-
type: :runtime
|
|
62
|
+
name: nokogiri
|
|
68
63
|
requirement: &id004 !ruby/object:Gem::Requirement
|
|
69
64
|
none: false
|
|
70
65
|
requirements:
|
|
71
66
|
- - ">="
|
|
72
67
|
- !ruby/object:Gem::Version
|
|
73
|
-
hash: 3
|
|
74
68
|
segments:
|
|
75
69
|
- 0
|
|
76
70
|
version: "0"
|
|
77
|
-
|
|
71
|
+
type: :runtime
|
|
72
|
+
prerelease: false
|
|
78
73
|
version_requirements: *id004
|
|
79
74
|
- !ruby/object:Gem::Dependency
|
|
80
|
-
|
|
81
|
-
type: :development
|
|
75
|
+
name: rspec
|
|
82
76
|
requirement: &id005 !ruby/object:Gem::Requirement
|
|
83
77
|
none: false
|
|
84
78
|
requirements:
|
|
85
79
|
- - ~>
|
|
86
80
|
- !ruby/object:Gem::Version
|
|
87
|
-
hash: 31
|
|
88
81
|
segments:
|
|
89
82
|
- 2
|
|
90
|
-
-
|
|
83
|
+
- 5
|
|
91
84
|
- 0
|
|
92
|
-
version: 2.
|
|
93
|
-
|
|
85
|
+
version: 2.5.0
|
|
86
|
+
type: :development
|
|
87
|
+
prerelease: false
|
|
94
88
|
version_requirements: *id005
|
|
95
89
|
- !ruby/object:Gem::Dependency
|
|
96
|
-
|
|
97
|
-
type: :development
|
|
90
|
+
name: bundler
|
|
98
91
|
requirement: &id006 !ruby/object:Gem::Requirement
|
|
99
92
|
none: false
|
|
100
93
|
requirements:
|
|
101
94
|
- - ~>
|
|
102
95
|
- !ruby/object:Gem::Version
|
|
103
|
-
hash: 23
|
|
104
96
|
segments:
|
|
105
97
|
- 1
|
|
106
98
|
- 0
|
|
107
99
|
- 0
|
|
108
100
|
version: 1.0.0
|
|
109
|
-
|
|
101
|
+
type: :development
|
|
102
|
+
prerelease: false
|
|
110
103
|
version_requirements: *id006
|
|
111
104
|
- !ruby/object:Gem::Dependency
|
|
112
|
-
|
|
113
|
-
type: :development
|
|
105
|
+
name: jeweler
|
|
114
106
|
requirement: &id007 !ruby/object:Gem::Requirement
|
|
115
107
|
none: false
|
|
116
108
|
requirements:
|
|
117
109
|
- - ~>
|
|
118
110
|
- !ruby/object:Gem::Version
|
|
119
|
-
hash: 7
|
|
120
111
|
segments:
|
|
121
112
|
- 1
|
|
122
113
|
- 5
|
|
123
114
|
- 2
|
|
124
115
|
version: 1.5.2
|
|
125
|
-
|
|
116
|
+
type: :development
|
|
117
|
+
prerelease: false
|
|
126
118
|
version_requirements: *id007
|
|
127
119
|
- !ruby/object:Gem::Dependency
|
|
128
|
-
|
|
129
|
-
type: :development
|
|
120
|
+
name: rcov
|
|
130
121
|
requirement: &id008 !ruby/object:Gem::Requirement
|
|
131
122
|
none: false
|
|
132
123
|
requirements:
|
|
133
124
|
- - ">="
|
|
134
125
|
- !ruby/object:Gem::Version
|
|
135
|
-
hash: 3
|
|
136
126
|
segments:
|
|
137
127
|
- 0
|
|
138
128
|
version: "0"
|
|
139
|
-
|
|
129
|
+
type: :development
|
|
130
|
+
prerelease: false
|
|
140
131
|
version_requirements: *id008
|
|
132
|
+
- !ruby/object:Gem::Dependency
|
|
133
|
+
name: spork
|
|
134
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
|
135
|
+
none: false
|
|
136
|
+
requirements:
|
|
137
|
+
- - ">="
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
segments:
|
|
140
|
+
- 0
|
|
141
|
+
version: "0"
|
|
142
|
+
type: :development
|
|
143
|
+
prerelease: false
|
|
144
|
+
version_requirements: *id009
|
|
141
145
|
description: |-
|
|
142
146
|
Based really very heavily on acts_as_taggable_on, but introduces tagging schemes and moves
|
|
143
147
|
context into tags (so, for example, "Environment" in a 'green_tags' scheme is not semantically equivalent
|
|
@@ -201,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
201
205
|
requirements:
|
|
202
206
|
- - ">="
|
|
203
207
|
- !ruby/object:Gem::Version
|
|
204
|
-
hash:
|
|
208
|
+
hash: 1510912516109491173
|
|
205
209
|
segments:
|
|
206
210
|
- 0
|
|
207
211
|
version: "0"
|
|
@@ -210,14 +214,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
210
214
|
requirements:
|
|
211
215
|
- - ">="
|
|
212
216
|
- !ruby/object:Gem::Version
|
|
213
|
-
hash: 3
|
|
214
217
|
segments:
|
|
215
218
|
- 0
|
|
216
219
|
version: "0"
|
|
217
220
|
requirements: []
|
|
218
221
|
|
|
219
222
|
rubyforge_project:
|
|
220
|
-
rubygems_version: 1.
|
|
223
|
+
rubygems_version: 1.3.7
|
|
221
224
|
signing_key:
|
|
222
225
|
specification_version: 3
|
|
223
226
|
summary: A semantic tagging system for Rails 3
|