stickyflag 0.3.0 → 0.3.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.
- data/TODO.md +2 -1
- data/lib/stickyflag/version.rb +1 -1
- data/stickyflag.gemspec +5 -4
- metadata +8 -116
- data/.gitignore +0 -7
- data/.rspec +0 -4
- data/.simplecov +0 -9
- data/.travis.yml +0 -13
- data/features/clear.feature +0 -14
- data/features/clear_quietly.feature +0 -23
- data/features/configuration.feature +0 -14
- data/features/get.feature +0 -14
- data/features/get_quietly.feature +0 -23
- data/features/set.feature +0 -14
- data/features/set_quietly.feature +0 -22
- data/features/step_definitions/configuration_steps.rb +0 -31
- data/features/step_definitions/database_steps.rb +0 -41
- data/features/step_definitions/pending_steps.rb +0 -5
- data/features/step_definitions/tag_steps.rb +0 -62
- data/features/support/cukegem.rb +0 -82
- data/features/support/env.rb +0 -37
- data/features/tags.feature +0 -18
- data/features/unset.feature +0 -14
- data/features/unset_quietly.feature +0 -23
- data/spec/spec_helper.rb +0 -22
- data/spec/stickyflag/configuration_spec.rb +0 -132
- data/spec/stickyflag/database_spec.rb +0 -331
- data/spec/stickyflag/external_cmds_spec.rb +0 -175
- data/spec/stickyflag/patches/tempfile_encoding_spec.rb +0 -26
- data/spec/stickyflag/patches/tmpnam_spec.rb +0 -35
- data/spec/stickyflag/paths_spec.rb +0 -29
- data/spec/stickyflag/tag_factory_spec.rb +0 -126
- data/spec/stickyflag/tags/c_spec.rb +0 -14
- data/spec/stickyflag/tags/mkv_spec.rb +0 -54
- data/spec/stickyflag/tags/mmd_spec.rb +0 -40
- data/spec/stickyflag/tags/pdf_spec.rb +0 -39
- data/spec/stickyflag/tags/png_spec.rb +0 -6
- data/spec/stickyflag/tags/tex_spec.rb +0 -6
- data/spec/stickyflag_spec.rb +0 -482
- data/spec/support/examples.rb +0 -32
- data/spec/support/examples/c_all_comments.c +0 -3
- data/spec/support/examples/c_no_tags.c +0 -5
- data/spec/support/examples/c_with_tag.c +0 -6
- data/spec/support/examples/mkv_no_tags.mkv +0 -0
- data/spec/support/examples/mkv_with_tag.mkv +0 -0
- data/spec/support/examples/mmd_all_meta.mmd +0 -6
- data/spec/support/examples/mmd_crazy_keys.mmd +0 -8
- data/spec/support/examples/mmd_crazy_tags.mmd +0 -9
- data/spec/support/examples/mmd_no_tags.mmd +0 -1
- data/spec/support/examples/mmd_with_tag.mmd +0 -3
- data/spec/support/examples/pdf_no_tags.pdf +0 -0
- data/spec/support/examples/pdf_with_tag.pdf +0 -0
- data/spec/support/examples/png_no_tags.png +0 -0
- data/spec/support/examples/png_with_tag.png +0 -0
- data/spec/support/examples/tex_no_tags.tex +0 -10
- data/spec/support/examples/tex_with_tag.tex +0 -11
- data/spec/support/examples/untaggable.txt +0 -0
- data/spec/support/run_with_args.rb +0 -36
- data/spec/support/silence_stream.rb +0 -12
- data/spec/support/tag_handler_behavior.rb +0 -125
data/features/support/cukegem.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
# Copyright 2011 Solano Labs All Rights Reserved
|
2
|
-
|
3
|
-
require 'aruba'
|
4
|
-
require 'aruba/api'
|
5
|
-
|
6
|
-
class CukeGem
|
7
|
-
@setup_done = false
|
8
|
-
|
9
|
-
class << self
|
10
|
-
include Aruba::Api
|
11
|
-
|
12
|
-
attr_reader :setup_done
|
13
|
-
|
14
|
-
def setup(gemspec, once=true)
|
15
|
-
gem_home = setup_env
|
16
|
-
if !@setup_done || !once then
|
17
|
-
@setup_done = true
|
18
|
-
mkgemdir(gem_home)
|
19
|
-
gem_install(gemspec)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def teardown
|
24
|
-
restore_env
|
25
|
-
end
|
26
|
-
|
27
|
-
def setup_env
|
28
|
-
tid = ENV['TDDIUM_TID'] || ''
|
29
|
-
gem_home = File.expand_path(File.join(Dir.tmpdir, "aruba-gem"))
|
30
|
-
|
31
|
-
set_env('GEM_HOME', gem_home)
|
32
|
-
set_env('GEM_PATH', gem_home)
|
33
|
-
set_env('BUNDLE_PATH', gem_home)
|
34
|
-
unset_bundler_env_vars
|
35
|
-
|
36
|
-
paths = (ENV['PATH'] || "").split(File::PATH_SEPARATOR)
|
37
|
-
paths.unshift(File.join(gem_home, 'bin'))
|
38
|
-
set_env('PATH', paths.uniq.join(File::PATH_SEPARATOR))
|
39
|
-
|
40
|
-
return gem_home
|
41
|
-
end
|
42
|
-
|
43
|
-
def mkgemdir(gem_home)
|
44
|
-
FileUtils::rm_rf(gem_home)
|
45
|
-
FileUtils::mkdir_p(gem_home)
|
46
|
-
|
47
|
-
output = `gem install bundler`
|
48
|
-
if $?.exitstatus != 0 then
|
49
|
-
raise "unable to install bundler into #{gem_home}: #{output}"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def gem_install(gemspec)
|
54
|
-
gem_file = nil
|
55
|
-
begin
|
56
|
-
pwd = Dir.pwd
|
57
|
-
gemspec_dir = File.dirname(gemspec)
|
58
|
-
Dir.chdir(gemspec_dir)
|
59
|
-
output = `gem build #{File.basename(gemspec)}`
|
60
|
-
Dir.chdir(pwd)
|
61
|
-
|
62
|
-
if $?.exitstatus != 0 then
|
63
|
-
raise "unable to build gem: #{output}"
|
64
|
-
end
|
65
|
-
|
66
|
-
if output =~ /File:\s+([A-Za-z0-9_.-]+[.]gem)/ then
|
67
|
-
gem_file = $1
|
68
|
-
output = `gem install #{File.join(gemspec_dir, gem_file)}`
|
69
|
-
if $?.exitstatus != 0 then
|
70
|
-
raise "unable to install gem: #{output}"
|
71
|
-
end
|
72
|
-
else
|
73
|
-
raise "garbled gem build output: #{output}"
|
74
|
-
end
|
75
|
-
ensure
|
76
|
-
if gem_file then
|
77
|
-
FileUtils.rm_f(File.join(gemspec_dir, gem_file))
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
data/features/support/env.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
$:.unshift File.expand_path("../../../lib", __FILE__)
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'bundler/setup'
|
6
|
-
|
7
|
-
require 'backports'
|
8
|
-
require 'aruba/cucumber'
|
9
|
-
require 'stickyflag'
|
10
|
-
require 'fileutils'
|
11
|
-
require_relative './cukegem'
|
12
|
-
|
13
|
-
# JRuby is slow to start up
|
14
|
-
Before do
|
15
|
-
@aruba_timeout_seconds = 10
|
16
|
-
end
|
17
|
-
|
18
|
-
# Back up and restore the user's configuration and database
|
19
|
-
$backup_db = File.tmpnam('.sqlite')
|
20
|
-
$backup_config = File.tmpnam('.yml')
|
21
|
-
|
22
|
-
class GetPaths
|
23
|
-
include StickyFlag::Paths
|
24
|
-
end
|
25
|
-
$paths = GetPaths.new
|
26
|
-
|
27
|
-
FileUtils.mv $paths.config_path, $backup_config if File.exist? $paths.config_path
|
28
|
-
FileUtils.mv $paths.database_path, $backup_db if File.exist? $paths.database_path
|
29
|
-
|
30
|
-
CukeGem.setup(File.expand_path('../../../stickyflag.gemspec', __FILE__))
|
31
|
-
|
32
|
-
at_exit do
|
33
|
-
CukeGem.teardown
|
34
|
-
|
35
|
-
FileUtils.mv $backup_config, $paths.config_path if File.exist? $backup_config
|
36
|
-
FileUtils.mv $backup_db, $paths.database_path if File.exist? $backup_db
|
37
|
-
end
|
data/features/tags.feature
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
Feature: Get List of Tags in Use
|
2
|
-
In order to know which tags I've already used
|
3
|
-
As a user with some tagged files
|
4
|
-
I want to be able to get a list of all file tags
|
5
|
-
|
6
|
-
Scenario: Get list of tags
|
7
|
-
Given the example database
|
8
|
-
When I get the list of tags in use
|
9
|
-
Then the output should contain " test"
|
10
|
-
And the output should contain " asdf"
|
11
|
-
And the output should contain "Tags currently in use:"
|
12
|
-
And the output should not contain "rspec"
|
13
|
-
|
14
|
-
Scenario: Get bare list of tags for scripting
|
15
|
-
Given the example database
|
16
|
-
When I quietly get the list of tags in use
|
17
|
-
Then the output should not contain "Tags currently in use:"
|
18
|
-
And the output should contain "\ntest\n"
|
data/features/unset.feature
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
Feature: Unset File Tags
|
2
|
-
In order to be able to change my mind
|
3
|
-
As a user
|
4
|
-
I want to be able to unset or remove tags from files
|
5
|
-
|
6
|
-
Scenario: Unset tags from a file with multiple tags
|
7
|
-
Given the example configuration
|
8
|
-
When I unset the tag "asdf" for "mmd_crazy_tags.mmd"
|
9
|
-
Then the output should match /New tags for .*mmd_crazy_tags.mmd: sdfg, dfgh, fghj, qwer/
|
10
|
-
|
11
|
-
Scenario: Unset tags from a file with one tag
|
12
|
-
Given the example configuration
|
13
|
-
When I unset the tag "test" for "mmd_with_tag.mmd"
|
14
|
-
Then the output should match /New tags for .*mmd_with_tag.mmd: no tags/
|
@@ -1,23 +0,0 @@
|
|
1
|
-
Feature: Silence Extraneous Output on Unset
|
2
|
-
In order to use StickyFlag in scripts
|
3
|
-
As a power user
|
4
|
-
I want to be able to unset tags without any output at all
|
5
|
-
|
6
|
-
Scenario: Unset tags with no output at all
|
7
|
-
Given the example configuration
|
8
|
-
When I quietly unset the tag "asdf" for "mmd_crazy_tags.mmd"
|
9
|
-
Then the output should not contain "mmd_crazy_tags.mmd"
|
10
|
-
And the output should not contain "sdfg"
|
11
|
-
|
12
|
-
Scenario: Determine quiet unset tag success from return value
|
13
|
-
Given the example configuration
|
14
|
-
Given PENDING: figure out how to get Thor to do exit codes
|
15
|
-
When I quietly unset the tag "asdf" for "mmd_crazy_tags.mmd"
|
16
|
-
Then the exit status should be 0
|
17
|
-
|
18
|
-
Scenario: Determine quiet unset tag failure from return value
|
19
|
-
Given the example configuration
|
20
|
-
Given PENDING: figure out how to get Thor to do exit codes
|
21
|
-
When I quietly unset the tag "test" for "nonexistent.mmd"
|
22
|
-
Then the exit status should not be 0
|
23
|
-
|
data/spec/spec_helper.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
$KCODE = 'U' if RUBY_VERSION < "1.9.0"
|
3
|
-
ENV['RSPEC_TESTING'] = 'true'
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'bundler/setup'
|
7
|
-
require 'simplecov' unless ENV["CI"] == 'true'
|
8
|
-
|
9
|
-
require 'backports'
|
10
|
-
require 'rspec/autorun'
|
11
|
-
require 'stickyflag'
|
12
|
-
|
13
|
-
Dir['./spec/support/**/*.rb'].map { |f| require f }
|
14
|
-
|
15
|
-
RSpec.configure do |c|
|
16
|
-
c.before(:each) do
|
17
|
-
# Don't write anything to the console
|
18
|
-
Thor::Shell::Basic.any_instance.stub(:say) { }
|
19
|
-
Thor::Shell::Basic.any_instance.stub(:say_status) { }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
@@ -1,132 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'stickyflag/paths'
|
3
|
-
require 'stickyflag/configuration'
|
4
|
-
|
5
|
-
class ConfigTester < Thor
|
6
|
-
include StickyFlag::Paths
|
7
|
-
include StickyFlag::Configuration
|
8
|
-
end
|
9
|
-
|
10
|
-
describe 'StickyFlag::Configuration' do
|
11
|
-
describe '#initialize' do
|
12
|
-
it 'loads default configuration values' do
|
13
|
-
@obj = ConfigTester.new
|
14
|
-
@obj.stub(:load_config!) { }
|
15
|
-
@obj.stub(:save_config!) { }
|
16
|
-
|
17
|
-
StickyFlag::Configuration::DEFAULT_CONFIG.keys.each do |k|
|
18
|
-
@obj.get_config(k).should eq(StickyFlag::Configuration::DEFAULT_CONFIG[k])
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '.get_config' do
|
24
|
-
before(:each) do
|
25
|
-
@obj = ConfigTester.new
|
26
|
-
|
27
|
-
@obj.stub(:load_config!) { }
|
28
|
-
@obj.stub(:save_config!) { }
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with good keys' do
|
32
|
-
it 'reads default values' do
|
33
|
-
@obj.get_config(:have_pdftk).should eq(false)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'reads updated values' do
|
37
|
-
@obj.set_config :have_pdftk, true
|
38
|
-
@obj.get_config(:have_pdftk).should eq(true)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'with bad keys' do
|
43
|
-
it 'raises an error on get' do
|
44
|
-
expect { @obj.get_config(:bad_key) }.to raise_error
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'raises an error on set' do
|
48
|
-
expect { @obj.set_config(:bad_key, 'test') }.to raise_error
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '.reset_config!' do
|
54
|
-
before(:each) do
|
55
|
-
@obj = ConfigTester.new
|
56
|
-
|
57
|
-
@obj.stub(:load_config!) { }
|
58
|
-
@obj.stub(:save_config!) { }
|
59
|
-
|
60
|
-
@obj.set_config :have_pdftk, true
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'resets changed values to defaults' do
|
64
|
-
@obj.reset_config!
|
65
|
-
@obj.get_config(:have_pdftk).should eq(false)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '.dump_config' do
|
70
|
-
before(:each) do
|
71
|
-
@obj = ConfigTester.new
|
72
|
-
|
73
|
-
@obj.stub(:load_config!) { }
|
74
|
-
@obj.stub(:save_config!) { }
|
75
|
-
|
76
|
-
@obj.set_config :pdftk_path, 'wut'
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'prints out the set configuration values' do
|
80
|
-
@obj.stub(:say) {}
|
81
|
-
@obj.should_receive(:say).with(/pdftk_path: 'wut'/)
|
82
|
-
@obj.dump_config
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '.load_config!' do
|
87
|
-
before(:each) do
|
88
|
-
@obj = ConfigTester.new
|
89
|
-
|
90
|
-
@obj.stub(:save_config!) { }
|
91
|
-
|
92
|
-
@config_file = File.join(File.dirname(__FILE__), 'config.yml')
|
93
|
-
@obj.stub(:config_path) { @config_file }
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should load from the requested YAML file' do
|
97
|
-
config = {
|
98
|
-
:have_pdftk => true,
|
99
|
-
:pdftk_path => 'wut'
|
100
|
-
}
|
101
|
-
File.open(@config_file, 'w:UTF-8') do |f|
|
102
|
-
YAML.dump(config, f)
|
103
|
-
end
|
104
|
-
|
105
|
-
@obj.load_config!
|
106
|
-
@obj.get_config(:pdftk_path).should eq('wut')
|
107
|
-
|
108
|
-
File.delete(@config_file)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe '.save_config!' do
|
113
|
-
before(:each) do
|
114
|
-
@obj = ConfigTester.new
|
115
|
-
|
116
|
-
@obj.stub(:load_config!) { }
|
117
|
-
|
118
|
-
@config_file = File.join(File.dirname(__FILE__), 'config.yml')
|
119
|
-
@obj.stub(:config_path) { @config_file }
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'should save to the requested YAML file' do
|
123
|
-
@obj.set_config :pdftk_path, 'wut'
|
124
|
-
@obj.save_config!
|
125
|
-
|
126
|
-
config = YAML::load(File.open(@config_file, 'r:UTF-8'))
|
127
|
-
config[:pdftk_path].should eq('wut')
|
128
|
-
|
129
|
-
File.delete(@config_file)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
@@ -1,331 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'stickyflag/paths'
|
3
|
-
require 'stickyflag/configuration'
|
4
|
-
require 'stickyflag/external_cmds'
|
5
|
-
require 'stickyflag/tag_factory'
|
6
|
-
require 'stickyflag/database'
|
7
|
-
|
8
|
-
class DatabaseTester < Thor
|
9
|
-
include StickyFlag::Paths
|
10
|
-
include StickyFlag::Configuration
|
11
|
-
include StickyFlag::ExternalCmds
|
12
|
-
include StickyFlag::TagFactory
|
13
|
-
include StickyFlag::Database
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'StickyFlag::Database' do
|
17
|
-
before(:each) do
|
18
|
-
@obj = DatabaseTester.new
|
19
|
-
|
20
|
-
@obj.stub(:load_config!) { }
|
21
|
-
@obj.stub(:save_config!) { }
|
22
|
-
@obj.stub(:database_path) { ":memory:" }
|
23
|
-
|
24
|
-
@obj.find_external_cmds
|
25
|
-
@obj.load_database
|
26
|
-
|
27
|
-
# Save this out for (lots of) later use
|
28
|
-
@database = @obj.instance_variable_get(:@database)
|
29
|
-
end
|
30
|
-
|
31
|
-
after(:each) do
|
32
|
-
# We've disabled automatic cleanup, so make sure we do this
|
33
|
-
@database.disconnect
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '.load_database' do
|
37
|
-
it 'sets the member variable' do
|
38
|
-
@database.should be
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '.update_database_from_files' do
|
43
|
-
context 'without a specific directory' do
|
44
|
-
before(:each) do
|
45
|
-
@obj.update_database_from_files
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'has some files in the database' do
|
49
|
-
@database[:tagged_files].should_not be_empty
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'has found the test and asdf tags' do
|
53
|
-
@obj.tag_list.should include('asdf')
|
54
|
-
@obj.tag_list.should include('test')
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'has found a sample markdown file' do
|
58
|
-
path = example_path 'mmd_crazy_keys.mmd'
|
59
|
-
@obj.files_for_tags(['test']).map { |f| File.expand_path(f) }.should include(path)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'with an empty directory' do
|
64
|
-
before(:each) do
|
65
|
-
@dir = File.tmpnam('.dir')
|
66
|
-
Dir.mkdir(@dir)
|
67
|
-
|
68
|
-
@obj.update_database_from_files(@dir)
|
69
|
-
end
|
70
|
-
|
71
|
-
after(:each) do
|
72
|
-
Dir.rmdir(@dir)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'has no files in the database' do
|
76
|
-
@database[:tagged_files].should be_empty
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'with some bad files in the directory' do
|
81
|
-
before(:each) do
|
82
|
-
@dir = File.tmpnam('.dir')
|
83
|
-
Dir.mkdir(@dir)
|
84
|
-
|
85
|
-
file = File.new(File.join(@dir, 'bad.pdf'), 'w:UTF-8')
|
86
|
-
file.puts('test bad')
|
87
|
-
file.close
|
88
|
-
end
|
89
|
-
|
90
|
-
after(:each) do
|
91
|
-
File.unlink(File.join(@dir, 'bad.pdf'))
|
92
|
-
Dir.rmdir(@dir)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'does not throw an exception' do
|
96
|
-
expect { @obj.update_database_from_files(@dir) }.to_not raise_error
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'prints a warning' do
|
100
|
-
@obj.should_receive(:say_status).with(:warning, kind_of(String), kind_of(Symbol))
|
101
|
-
@obj.update_database_from_files(@dir)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context 'with a full directory' do
|
106
|
-
before(:each) do
|
107
|
-
@obj.update_database_from_files(example_root)
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'has some files in the database' do
|
111
|
-
@database[:tagged_files].should_not be_empty
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'has found the test and asdf tags' do
|
115
|
-
@obj.tag_list.should include('asdf')
|
116
|
-
@obj.tag_list.should include('test')
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'has found a sample markdown file' do
|
120
|
-
path = example_path 'mmd_crazy_keys.mmd'
|
121
|
-
@obj.files_for_tags(['test']).map { |f| File.expand_path(f) }.should include(path)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '.set_database_tag' do
|
127
|
-
context 'with an already extant tag' do
|
128
|
-
before(:each) do
|
129
|
-
@obj.update_database_from_files example_root
|
130
|
-
@path = example_path 'mmd_with_tag.mmd'
|
131
|
-
@obj.set_database_tag(@path, 'asdf')
|
132
|
-
end
|
133
|
-
|
134
|
-
it "adds the record for the tagged file" do
|
135
|
-
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
136
|
-
file_id.should_not be_nil
|
137
|
-
|
138
|
-
tag_id = @database[:tag_list].where(:tag_name => 'asdf').get(:id)
|
139
|
-
tag_id.should_not be_nil
|
140
|
-
|
141
|
-
ds = @database[:tagged_files].where(:file => file_id).and(:tag => tag_id)
|
142
|
-
ds.should_not be_empty
|
143
|
-
ds.count.should eq(1)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "doesn't duplicate the entry for the tag" do
|
147
|
-
ds = @database[:tag_list].where(:tag_name => 'asdf')
|
148
|
-
ds.count.should eq(1)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context 'with a new tag' do
|
153
|
-
before(:each) do
|
154
|
-
@obj.update_database_from_files example_root
|
155
|
-
@path = example_path 'mmd_with_tag.mmd'
|
156
|
-
@obj.set_database_tag(@path, 'zuzzax')
|
157
|
-
end
|
158
|
-
|
159
|
-
it "adds a new record for the new tag" do
|
160
|
-
ds = @database[:tag_list].where(:tag_name => 'zuzzax')
|
161
|
-
ds.should_not be_empty
|
162
|
-
ds.count.should eq(1)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "adds the record for the tagged file" do
|
166
|
-
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
167
|
-
file_id.should_not be_nil
|
168
|
-
|
169
|
-
tag_id = @database[:tag_list].where(:tag_name => 'zuzzax').get(:id)
|
170
|
-
tag_id.should_not be_nil
|
171
|
-
|
172
|
-
ds = @database[:tagged_files].where(:file => file_id).and(:tag => tag_id)
|
173
|
-
ds.should_not be_empty
|
174
|
-
ds.count.should eq(1)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe '.unset_database_tag' do
|
180
|
-
context 'with a multiply-present tag' do
|
181
|
-
before(:each) do
|
182
|
-
@obj.update_database_from_files example_root
|
183
|
-
@path = example_path 'mmd_with_tag.mmd'
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'removes the record for the tagged file' do
|
187
|
-
@obj.unset_database_tag(@path, 'test')
|
188
|
-
|
189
|
-
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
190
|
-
file_id.should_not be_nil
|
191
|
-
|
192
|
-
tag_id = @database[:tag_list].where(:tag_name => 'test').get(:id)
|
193
|
-
tag_id.should_not be_nil
|
194
|
-
|
195
|
-
ds = @database[:tagged_files].where(:file => file_id).and(:tag => tag_id)
|
196
|
-
ds.should be_empty
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context 'with a singly-present tag' do
|
201
|
-
before(:each) do
|
202
|
-
@obj.update_database_from_files example_root
|
203
|
-
@path = example_path 'mmd_crazy_tags.mmd'
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'removes the record for the tagged file' do
|
207
|
-
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
208
|
-
file_id.should_not be_nil
|
209
|
-
|
210
|
-
tag_id = @database[:tag_list].where(:tag_name => 'qwer').get(:id)
|
211
|
-
tag_id.should_not be_nil
|
212
|
-
|
213
|
-
@obj.unset_database_tag(@path, 'qwer')
|
214
|
-
|
215
|
-
ds = @database[:tagged_files].where(:file => file_id).and(:tag => tag_id)
|
216
|
-
ds.should be_empty
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'removes the record of the tag' do
|
220
|
-
@obj.unset_database_tag(@path, 'qwer')
|
221
|
-
ds = @database[:tag_list].where(:tag_name => 'qwer')
|
222
|
-
ds.should be_empty
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
describe '.clear_database_tags' do
|
228
|
-
before(:each) do
|
229
|
-
@obj.update_database_from_files example_root
|
230
|
-
@path = example_path 'mmd_crazy_tags.mmd'
|
231
|
-
@obj.clear_database_tags(@path)
|
232
|
-
end
|
233
|
-
|
234
|
-
it 'removes all tag records for the file' do
|
235
|
-
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
236
|
-
file_id.should_not be_nil
|
237
|
-
|
238
|
-
ds = @database[:tagged_files].where(:file => file_id)
|
239
|
-
ds.should be_empty
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'removes the tag after clearing single-instance tags' do
|
243
|
-
ds = @database[:tag_list].where(:tag_name => 'qwer')
|
244
|
-
ds.should be_empty
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe '.files_for_tags' do
|
249
|
-
before(:each) do
|
250
|
-
@obj.update_database_from_files example_root
|
251
|
-
end
|
252
|
-
|
253
|
-
context 'with good, single tags' do
|
254
|
-
it 'includes one of the markdown files' do
|
255
|
-
path = example_path 'mmd_crazy_keys.mmd'
|
256
|
-
@obj.files_for_tags([ 'test' ]).should include(path)
|
257
|
-
end
|
258
|
-
|
259
|
-
it 'does not include files that lack a tag' do
|
260
|
-
path = example_path 'mmd_with_tag.mmd'
|
261
|
-
@obj.files_for_tags([ 'asdf' ]).should_not include(path)
|
262
|
-
end
|
263
|
-
|
264
|
-
it 'does not include untaggable files' do
|
265
|
-
path = example_path 'untaggable.txt'
|
266
|
-
@obj.files_for_tags([ 'test' ]).should_not include(path)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
context 'with multiple tags' do
|
271
|
-
it 'combines with boolean AND' do
|
272
|
-
path1 = example_path 'mmd_crazy_tags.mmd'
|
273
|
-
path2 = example_path 'mmd_with_tag.mmd'
|
274
|
-
|
275
|
-
files = @obj.files_for_tags([ 'sdfg', 'asdf', 'qwer' ])
|
276
|
-
files.should include(path1)
|
277
|
-
files.should_not include(path2)
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'prints a warning if no files have all those tags' do
|
281
|
-
@obj.should_receive(:say_status).with(:warning, kind_of(String), kind_of(Symbol))
|
282
|
-
@obj.files_for_tags([ 'asdf', 'test' ])
|
283
|
-
end
|
284
|
-
|
285
|
-
it 'returns an empty array if no files have all those tags' do
|
286
|
-
@obj.files_for_tags([ 'asdf', 'test' ]).should be_empty
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
context 'with missing tags' do
|
291
|
-
it "doesn't throw" do
|
292
|
-
expect { @obj.files_for_tags([ 'zuzzax' ]) }.to_not raise_error
|
293
|
-
end
|
294
|
-
|
295
|
-
it 'prints a warning' do
|
296
|
-
@obj.should_receive(:say_status).with(:warning, kind_of(String), kind_of(Symbol))
|
297
|
-
@obj.files_for_tags([ 'zuzzax' ])
|
298
|
-
end
|
299
|
-
|
300
|
-
it 'returns an empty array' do
|
301
|
-
@obj.files_for_tags([ 'zuzzax', 'test' ]).should be_empty
|
302
|
-
end
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
describe '.tag_list' do
|
307
|
-
context 'prior to loading anything into the database' do
|
308
|
-
it 'is empty' do
|
309
|
-
@obj.tag_list.should be_empty
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
context 'after loading files into the database' do
|
314
|
-
before(:each) do
|
315
|
-
@obj.update_database_from_files example_root
|
316
|
-
end
|
317
|
-
|
318
|
-
it 'includes multiply-present tags' do
|
319
|
-
@obj.tag_list.should include('test')
|
320
|
-
end
|
321
|
-
|
322
|
-
it 'includes singly-present tags' do
|
323
|
-
@obj.tag_list.should include('qwer')
|
324
|
-
end
|
325
|
-
|
326
|
-
it 'does not include absent tags' do
|
327
|
-
@obj.tag_list.should_not include('zuzzax')
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|
331
|
-
end
|