alexandria-book-collection-manager 0.7.1 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +9 -0
- data/.gitignore +5 -2
- data/.hound.yml +2 -0
- data/.rubocop.yml +113 -45
- data/.rubocop_todo.yml +82 -170
- data/.simplecov +5 -1
- data/.travis.yml +45 -0
- data/.yardopts +1 -1
- data/CHANGELOG.md +60 -0
- data/ChangeLog.0 +33 -35
- data/Gemfile +6 -5
- data/INSTALL.md +164 -0
- data/README.md +52 -42
- data/Rakefile +95 -109
- data/TODO.md +9 -1
- data/alexandria-book-collection-manager.gemspec +52 -45
- data/bin/alexandria +31 -53
- data/doc/AUTHORS +61 -0
- data/doc/BUGS +31 -0
- data/doc/FAQ +365 -0
- data/doc/HACKING +19 -0
- data/doc/NEWS +341 -0
- data/doc/alexandria.1 +120 -0
- data/doc/cuecat_support.rdoc +67 -0
- data/doc/dependency_decisions.yml +80 -0
- data/lib/alexandria.rb +29 -37
- data/lib/alexandria/about.rb +52 -51
- data/lib/alexandria/book_providers.rb +94 -101
- data/lib/alexandria/book_providers/adlibris.rb +45 -85
- data/lib/alexandria/book_providers/amazon_aws.rb +105 -113
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +293 -324
- data/lib/alexandria/book_providers/barnes_and_noble.rb +54 -53
- data/lib/alexandria/book_providers/douban.rb +29 -51
- data/lib/alexandria/book_providers/proxis.rb +42 -59
- data/lib/alexandria/book_providers/pseudomarc.rb +79 -99
- data/lib/alexandria/book_providers/siciliano.rb +68 -70
- data/lib/alexandria/book_providers/thalia.rb +46 -45
- data/lib/alexandria/book_providers/web.rb +17 -33
- data/lib/alexandria/book_providers/worldcat.rb +74 -102
- data/lib/alexandria/book_providers/z3950.rb +170 -174
- data/lib/alexandria/config.rb +5 -3
- data/lib/alexandria/console.rb +10 -21
- data/lib/alexandria/default_preferences.rb +37 -0
- data/lib/alexandria/execution_queue.rb +17 -15
- data/lib/alexandria/export_format.rb +47 -0
- data/lib/alexandria/export_library.rb +188 -302
- data/lib/alexandria/import_library.rb +114 -155
- data/lib/alexandria/import_library_csv.rb +46 -96
- data/lib/alexandria/library_collection.rb +79 -0
- data/lib/alexandria/library_sort_order.rb +45 -0
- data/lib/alexandria/library_store.rb +233 -0
- data/lib/alexandria/logging.rb +15 -19
- data/lib/alexandria/models/book.rb +15 -20
- data/lib/alexandria/models/library.rb +81 -363
- data/lib/alexandria/net.rb +7 -6
- data/lib/alexandria/preferences.rb +73 -91
- data/lib/alexandria/scanners.rb +4 -2
- data/lib/alexandria/scanners/{cuecat.rb → cue_cat.rb} +24 -20
- data/lib/alexandria/scanners/keyboard.rb +10 -8
- data/lib/alexandria/smart_library.rb +135 -171
- data/lib/alexandria/ui.rb +17 -15
- data/lib/alexandria/ui/about_dialog.rb +49 -0
- data/lib/alexandria/ui/{dialogs/acquire_dialog.rb → acquire_dialog.rb} +129 -152
- data/lib/alexandria/ui/alert_dialog.rb +64 -0
- data/lib/alexandria/ui/bad_isbns_dialog.rb +41 -0
- data/lib/alexandria/ui/{dialogs/barcode_animation.rb → barcode_animation.rb} +18 -15
- data/lib/alexandria/ui/{dialogs/book_properties_dialog.rb → book_properties_dialog.rb} +44 -61
- data/lib/alexandria/ui/{dialogs/book_properties_dialog_base.rb → book_properties_dialog_base.rb} +84 -89
- data/lib/alexandria/ui/builder_base.rb +9 -27
- data/lib/alexandria/ui/callbacks.rb +188 -186
- data/lib/alexandria/ui/columns.rb +2 -0
- data/lib/alexandria/ui/completion_models.rb +12 -23
- data/lib/alexandria/ui/confirm_erase_dialog.rb +33 -0
- data/lib/alexandria/ui/conflict_while_copying_dialog.rb +34 -0
- data/lib/alexandria/ui/dndable.rb +10 -8
- data/lib/alexandria/ui/error_dialog.rb +25 -0
- data/lib/alexandria/ui/export_dialog.rb +139 -0
- data/lib/alexandria/ui/icons.rb +49 -65
- data/lib/alexandria/ui/iconview.rb +15 -13
- data/lib/alexandria/ui/iconview_tooltips.rb +43 -58
- data/lib/alexandria/ui/import_dialog.rb +157 -0
- data/lib/alexandria/ui/init.rb +23 -33
- data/lib/alexandria/ui/keep_bad_isbn_dialog.rb +36 -0
- data/lib/alexandria/ui/libraries_combo.rb +18 -14
- data/lib/alexandria/ui/listview.rb +77 -88
- data/lib/alexandria/ui/main_app.rb +26 -26
- data/lib/alexandria/ui/misc_dialogs.rb +10 -0
- data/lib/alexandria/ui/multi_drag_treeview.rb +30 -41
- data/lib/alexandria/ui/{dialogs/new_book_dialog.rb → new_book_dialog.rb} +168 -215
- data/lib/alexandria/ui/new_book_dialog_manual.rb +139 -0
- data/lib/alexandria/ui/new_provider_dialog.rb +100 -0
- data/lib/alexandria/ui/new_smart_library_dialog.rb +74 -0
- data/lib/alexandria/ui/preferences_dialog.rb +313 -0
- data/lib/alexandria/ui/provider_preferences_base_dialog.rb +95 -0
- data/lib/alexandria/ui/provider_preferences_dialog.rb +35 -0
- data/lib/alexandria/ui/really_delete_dialog.rb +53 -0
- data/lib/alexandria/ui/{sidepane.rb → sidepane_manager.rb} +62 -72
- data/lib/alexandria/ui/skip_entry_dialog.rb +33 -0
- data/lib/alexandria/ui/smart_library_properties_dialog.rb +60 -0
- data/lib/alexandria/ui/{dialogs/smart_library_properties_dialog_base.rb → smart_library_properties_dialog_base.rb} +96 -172
- data/lib/alexandria/ui/smart_library_rule_box.rb +119 -0
- data/lib/alexandria/ui/sound.rb +13 -13
- data/lib/alexandria/ui/ui_manager.rb +262 -283
- data/lib/alexandria/undo_manager.rb +3 -0
- data/lib/alexandria/version.rb +6 -19
- data/lib/alexandria/web_themes.rb +24 -21
- data/po/Makefile +2 -2
- data/po/cs.po +993 -880
- data/po/cy.po +957 -874
- data/po/de.po +990 -869
- data/po/el.po +989 -869
- data/po/es.po +985 -865
- data/po/fr.po +986 -870
- data/po/ga.po +907 -823
- data/po/gl.po +981 -865
- data/po/it.po +986 -868
- data/po/ja.po +969 -853
- data/po/mk.po +983 -863
- data/po/nb.po +979 -863
- data/po/nl.po +983 -864
- data/po/pl.po +1020 -969
- data/po/pt.po +988 -861
- data/po/pt_BR.po +984 -868
- data/po/ru.po +992 -873
- data/po/sk.po +987 -869
- data/po/sv.po +977 -861
- data/po/uk.po +975 -865
- data/po/zh_TW.po +976 -860
- data/schemas/alexandria.schemas +25 -3
- data/share/alexandria/glade/acquire_dialog__builder.glade +15 -12
- data/share/alexandria/glade/book_properties_dialog__builder.glade +171 -299
- data/share/alexandria/glade/main_app__builder.glade +24 -33
- data/share/alexandria/glade/new_book_dialog__builder.glade +27 -59
- data/share/alexandria/glade/preferences_dialog__builder.glade +250 -290
- data/share/gnome/help/alexandria/C/introduction.xml +0 -8
- data/share/gnome/help/alexandria/C/searching.xml +1 -1
- data/share/gnome/help/alexandria/C/smart-libraries.xml +2 -2
- data/share/gnome/help/alexandria/C/working-with-libraries.xml +1 -1
- data/share/gnome/help/alexandria/fr/alexandria.xml +1 -1
- data/share/gnome/help/alexandria/ja/introduction.xml +0 -8
- data/share/gnome/help/alexandria/ja/smart-libraries.xml +1 -1
- data/spec/alexandria/book_providers/world_cat_provider_spec.rb +160 -0
- data/spec/alexandria/book_providers_spec.rb +77 -210
- data/spec/alexandria/book_spec.rb +16 -12
- data/spec/alexandria/console_spec.rb +27 -0
- data/spec/alexandria/export_library_spec.rb +130 -0
- data/spec/alexandria/library_spec.rb +130 -172
- data/spec/alexandria/library_store_spec.rb +37 -0
- data/spec/alexandria/preferences_spec.rb +46 -17
- data/spec/alexandria/scanners/cue_cat_spec.rb +52 -0
- data/spec/alexandria/smart_library_spec.rb +32 -25
- data/spec/alexandria/ui/about_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/acquire_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/alert_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/bad_isbns_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/book_properties_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/confirm_erase_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/conflict_while_copying_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/error_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/export_dialog_spec.rb +15 -0
- data/spec/alexandria/ui/icons_spec.rb +26 -0
- data/spec/alexandria/ui/iconview_spec.rb +9 -21
- data/spec/alexandria/ui/import_dialog_spec.rb +41 -0
- data/spec/alexandria/ui/keep_bad_isbn_dialog_spec.rb +17 -0
- data/spec/alexandria/ui/main_app_spec.rb +8 -33
- data/spec/alexandria/ui/new_book_dialog_manual_spec.rb +15 -0
- data/spec/alexandria/ui/new_book_dialog_spec.rb +22 -0
- data/spec/alexandria/ui/new_provider_dialog_spec.rb +30 -0
- data/spec/alexandria/ui/new_smart_library_dialog_spec.rb +39 -0
- data/spec/alexandria/ui/preferences_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/provider_preferences_dialog_spec.rb +34 -0
- data/spec/alexandria/ui/really_delete_dialog_spec.rb +16 -0
- data/spec/alexandria/ui/sidepane_manager_spec.rb +15 -0
- data/spec/alexandria/ui/skip_entry_dialog_spec.rb +14 -0
- data/spec/alexandria/ui/smart_library_properties_dialog_spec.rb +32 -0
- data/spec/alexandria/ui/sound_spec.rb +4 -2
- data/spec/alexandria/ui/ui_manager_spec.rb +45 -20
- data/spec/end_to_end/basic_run_spec.rb +57 -0
- data/spec/spec_helper.rb +66 -33
- data/tasks/setup.rb +5 -3
- data/tasks/spec.rake +18 -3
- data/util/rake/fileinstall.rb +38 -40
- data/util/rake/gettextgenerate.rb +15 -70
- data/util/rake/omfgenerate.rb +10 -10
- metadata +176 -60
- data/INSTALL.rdoc +0 -148
- data/dogtail/basic_run_test.py +0 -9
- data/lib/alexandria/book_providers/bol_it.rb +0 -160
- data/lib/alexandria/book_providers/deastore.rb +0 -273
- data/lib/alexandria/book_providers/ibs_it.rb +0 -147
- data/lib/alexandria/book_providers/mcu.rb +0 -169
- data/lib/alexandria/book_providers/renaud.rb +0 -140
- data/lib/alexandria/book_providers/webster_it.rb +0 -167
- data/lib/alexandria/ui/dialogs/about_dialog.rb +0 -59
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +0 -70
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +0 -43
- data/lib/alexandria/ui/dialogs/export_dialog.rb +0 -171
- data/lib/alexandria/ui/dialogs/import_dialog.rb +0 -196
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +0 -85
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +0 -154
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +0 -74
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +0 -578
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +0 -57
- data/spec/alexandria/scanners/cuecat_spec.rb +0 -65
- data/spec/alexandria/ui/dialogs_spec.rb +0 -94
- data/spec/alexandria/ui/sidepane_spec.rb +0 -27
- data/spec/alexandria/ui/ui_utilities_spec.rb +0 -60
- data/spec/alexandria/utilities_spec.rb +0 -50
- data/tasks/dogtail.rake +0 -4
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright (C) 2007 Joseph Method
|
2
4
|
# Copyright (C) 2011, 2015 Matijs van Zuijlen
|
3
5
|
#
|
@@ -16,42 +18,44 @@
|
|
16
18
|
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
17
19
|
# Fifth Floor, Boston, MA 02110-1301 USA.
|
18
20
|
|
19
|
-
require
|
21
|
+
require "spec_helper"
|
20
22
|
|
21
23
|
describe Alexandria::Book do
|
22
|
-
it
|
24
|
+
it "is a thing" do
|
23
25
|
an_artist_of_the_floating_world
|
24
26
|
end
|
25
27
|
|
26
|
-
it
|
28
|
+
it "establishes equality only with books with the same identity" do
|
27
29
|
book = an_artist_of_the_floating_world
|
28
30
|
same_book = an_artist_of_the_floating_world
|
29
31
|
expect(same_book).to eq book
|
30
32
|
different_book = an_artist_of_the_floating_world
|
31
|
-
different_book.isbn =
|
33
|
+
different_book.isbn = "9780571147999"
|
32
34
|
expect(different_book).not_to eq book
|
33
35
|
end
|
34
36
|
|
35
|
-
describe
|
37
|
+
describe "#rating" do
|
36
38
|
let(:book) { an_artist_of_the_floating_world }
|
37
|
-
|
39
|
+
|
40
|
+
it "returns 0 by default" do
|
38
41
|
expect(book.rating).to eq 0
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
42
|
-
describe
|
45
|
+
describe "#rating=" do
|
43
46
|
let(:book) { an_artist_of_the_floating_world }
|
44
|
-
|
47
|
+
|
48
|
+
it "assigns rating" do
|
45
49
|
book.rating = 5
|
46
50
|
expect(book.rating).to eq 5
|
47
51
|
end
|
48
52
|
|
49
|
-
it
|
50
|
-
expect { book.rating = 6 }.to raise_error
|
53
|
+
it "does not allow higher rating than 5 to be assigned" do
|
54
|
+
expect { book.rating = 6 }.to raise_error ArgumentError
|
51
55
|
end
|
52
56
|
|
53
|
-
it
|
54
|
-
expect { book.rating = -1 }.to raise_error
|
57
|
+
it "does not allow lower rating than 0 to be assigned" do
|
58
|
+
expect { book.rating = -1 }.to raise_error ArgumentError
|
55
59
|
end
|
56
60
|
end
|
57
61
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is part of Alexandria.
|
4
|
+
#
|
5
|
+
# See the file README.md for authorship and licensing information.
|
6
|
+
|
7
|
+
require "spec_helper"
|
8
|
+
|
9
|
+
RSpec.describe Alexandria do
|
10
|
+
let(:lib_version) { File.join(LIBDIR, "0.6.2") }
|
11
|
+
|
12
|
+
before do
|
13
|
+
FileUtils.cp_r(lib_version, TESTDIR)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".list_books_on_console" do
|
17
|
+
it "returns a string containing a list of all books" do
|
18
|
+
expect(described_class.list_books_on_console).to eq <<~LIST
|
19
|
+
Pattern Recognition, William Gibson
|
20
|
+
Bonjour Tristesse, Francoise Sagan & Irene Ash
|
21
|
+
An Artist of the Floating World, Kazuo Ishiguro
|
22
|
+
The Dispossessed, Ursula Le Guin
|
23
|
+
Neverwhere, Neil Gaiman
|
24
|
+
LIST
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is part of Alexandria.
|
4
|
+
#
|
5
|
+
# See the file README.md for authorship and licensing information.
|
6
|
+
|
7
|
+
require "spec_helper"
|
8
|
+
|
9
|
+
RSpec.describe Alexandria::ExportLibrary do
|
10
|
+
let(:my_library) do
|
11
|
+
loader = Alexandria::LibraryStore.new(TESTDIR)
|
12
|
+
loader.load_library("My Library")
|
13
|
+
end
|
14
|
+
let(:format) { Alexandria::ExportFormat.all.find { |it| it.message == message } }
|
15
|
+
let(:outfile) do
|
16
|
+
outfile_base = format.ext ? "my-library.#{format.ext}" : "my-library"
|
17
|
+
File.join(Dir.tmpdir, outfile_base)
|
18
|
+
end
|
19
|
+
let(:unsorted) { Alexandria::LibrarySortOrder::Unsorted.new }
|
20
|
+
|
21
|
+
before do
|
22
|
+
test_library = File.join(LIBDIR, "0.6.2")
|
23
|
+
FileUtils.cp_r(test_library, TESTDIR)
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
FileUtils.rm_rf(outfile) if File.exist? outfile
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#export_as_csv_list" do
|
31
|
+
let(:message) { :export_as_csv_list }
|
32
|
+
|
33
|
+
def load_rows_from_csv
|
34
|
+
CSV.read(outfile, col_sep: ";", headers: true)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "can sort by title" do
|
38
|
+
sort_by_title = Alexandria::LibrarySortOrder.new(:title)
|
39
|
+
format.invoke(my_library, sort_by_title, outfile)
|
40
|
+
rows = load_rows_from_csv
|
41
|
+
titles = rows.map { |it| it["Title"] }
|
42
|
+
expect(titles).to eq titles.sort
|
43
|
+
end
|
44
|
+
|
45
|
+
it "can sort in descending order" do
|
46
|
+
sort_by_date_desc = Alexandria::LibrarySortOrder.new(:publishing_year, false)
|
47
|
+
format.invoke(my_library, sort_by_date_desc, outfile)
|
48
|
+
rows = load_rows_from_csv
|
49
|
+
dates = rows.map { |it| it["Year Published"] }
|
50
|
+
expect(dates).to eq dates.sort.reverse
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#export_as_html" do
|
55
|
+
let(:message) { :export_as_html }
|
56
|
+
|
57
|
+
it "can export unsorted" do
|
58
|
+
format.invoke(my_library, unsorted, outfile, Alexandria::WebTheme.all.first)
|
59
|
+
index = File.join(outfile, "index.html")
|
60
|
+
|
61
|
+
aggregate_failures do
|
62
|
+
expect(File.exist?(outfile)).to be_truthy
|
63
|
+
expect(File.exist?(index)).to be_truthy
|
64
|
+
expect(File.size(index)).to be_nonzero
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#export_as_onix_xml_archive" do
|
70
|
+
let(:message) { :export_as_onix_xml_archive }
|
71
|
+
|
72
|
+
it "can export unsorted" do
|
73
|
+
format.invoke(my_library, unsorted, outfile)
|
74
|
+
aggregate_failures do
|
75
|
+
expect(File.exist?(outfile)).to be_truthy
|
76
|
+
expect(File.size(outfile)).to be_nonzero
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#export_as_tellico_xml_archive" do
|
82
|
+
let(:message) { :export_as_tellico_xml_archive }
|
83
|
+
|
84
|
+
it "can export unsorted" do
|
85
|
+
format.invoke(my_library, unsorted, outfile)
|
86
|
+
aggregate_failures do
|
87
|
+
expect(File.exist?(outfile)).to be_truthy
|
88
|
+
expect(File.size(outfile)).to be_nonzero
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#export_as_bibtex" do
|
94
|
+
let(:message) { :export_as_bibtex }
|
95
|
+
|
96
|
+
it "can export unsorted" do
|
97
|
+
format.invoke(my_library, unsorted, outfile)
|
98
|
+
aggregate_failures do
|
99
|
+
expect(File.exist?(outfile)).to be_truthy
|
100
|
+
expect(File.size(outfile)).to be_nonzero
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#export_as_isbn_list" do
|
106
|
+
let(:message) { :export_as_isbn_list }
|
107
|
+
|
108
|
+
it "can export unsorted" do
|
109
|
+
format.invoke(my_library, unsorted, outfile)
|
110
|
+
aggregate_failures do
|
111
|
+
expect(File.exist?(outfile)).to be_truthy
|
112
|
+
expect(File.size(outfile)).to be_nonzero
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#export_as_ipod_notes" do
|
118
|
+
let(:message) { :export_as_ipod_notes }
|
119
|
+
|
120
|
+
it "can export unsorted" do
|
121
|
+
format.invoke(my_library, unsorted, outfile, nil)
|
122
|
+
index = File.join(outfile, "index.linx")
|
123
|
+
|
124
|
+
aggregate_failures do
|
125
|
+
expect(File.exist?(outfile)).to be_truthy
|
126
|
+
expect(File.size(index)).to be_nonzero
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -1,105 +1,92 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright (C) 2011, 2014-2016 Matijs van Zuijlen
|
5
|
-
#
|
6
|
-
# Alexandria is free software; you can redistribute it and/or
|
7
|
-
# modify it under the terms of the GNU General Public License as
|
8
|
-
# published by the Free Software Foundation; either version 2 of the
|
9
|
-
# License, or (at your option) any later version.
|
10
|
-
#
|
11
|
-
# Alexandria is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
-
# General Public License for more details.
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is part of Alexandria.
|
15
4
|
#
|
16
|
-
#
|
17
|
-
# License along with Alexandria; see the file COPYING. If not,
|
18
|
-
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
19
|
-
# Fifth Floor, Boston, MA 02110-1301 USA.
|
5
|
+
# See the file README.md for authorship and licensing information.
|
20
6
|
|
21
|
-
require
|
7
|
+
require "spec_helper"
|
22
8
|
|
23
9
|
describe Alexandria::Library do
|
24
|
-
|
25
|
-
|
10
|
+
let(:loader) { Alexandria::LibraryStore.new(TESTDIR) }
|
11
|
+
|
12
|
+
describe "::EXT" do
|
13
|
+
it "has symbolic references to file extensions" do
|
26
14
|
extensions = Alexandria::Library::EXT
|
27
15
|
expect(extensions[:book]).not_to be_nil
|
28
16
|
expect(extensions[:cover]).not_to be_nil
|
29
17
|
end
|
30
18
|
end
|
31
19
|
|
32
|
-
describe
|
33
|
-
it
|
34
|
-
|
35
|
-
expect(
|
20
|
+
describe "#valid_isbn?" do
|
21
|
+
it "returns a true value for valid isbns" do
|
22
|
+
["014143984X", "0-345-43192-8"].each do |x|
|
23
|
+
expect(described_class.valid_isbn?(x)).to be_truthy
|
36
24
|
end
|
37
25
|
end
|
38
26
|
end
|
39
27
|
|
40
|
-
describe
|
41
|
-
it
|
42
|
-
expect(
|
43
|
-
expect(
|
28
|
+
describe "#valid_ean?" do
|
29
|
+
it "returns a true value for valid EANs" do
|
30
|
+
expect(described_class.valid_ean?("9780345431929")).to be_truthy
|
31
|
+
expect(described_class.valid_ean?("978034543192912345")).to be_truthy
|
44
32
|
|
45
33
|
# Regression test: this EAN has a checksum of 10, which should be
|
46
34
|
# treated like a checksum of 0.
|
47
|
-
expect(
|
35
|
+
expect(described_class.valid_ean?("9784047041790")).to be_truthy
|
48
36
|
end
|
49
37
|
|
50
|
-
it
|
51
|
-
expect(
|
52
|
-
expect(
|
53
|
-
expect(
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
expect(
|
38
|
+
it "returns a false value for invalid EANs" do
|
39
|
+
expect(described_class.valid_ean?("780345431929")).to be_falsey
|
40
|
+
expect(described_class.valid_ean?("97803454319290")).to be_falsey
|
41
|
+
expect(described_class.valid_ean?("97803454319291234")).to be_falsey
|
42
|
+
expect(described_class.valid_ean?("9780345431929123456")).to be_falsey
|
43
|
+
expect(described_class.valid_ean?("9780345431928")).to be_falsey
|
44
|
+
expect(described_class.valid_ean?("9780345431929A")).to be_falsey
|
57
45
|
|
58
|
-
expect(
|
46
|
+
expect(described_class.valid_ean?("9784047041791")).to be_falsey
|
59
47
|
end
|
60
48
|
end
|
61
49
|
|
62
|
-
describe
|
63
|
-
it
|
64
|
-
expect(
|
50
|
+
describe "#valid_upc?" do
|
51
|
+
it "returns a true value for valid UPCs" do
|
52
|
+
expect(described_class.valid_upc?("97803454319312356")).to be_truthy
|
65
53
|
end
|
66
54
|
|
67
|
-
it
|
68
|
-
expect(
|
69
|
-
expect(
|
55
|
+
it "returns a false value for invalid UPCs" do
|
56
|
+
expect(described_class.valid_upc?("978034543193123567")).to be_falsey
|
57
|
+
expect(described_class.valid_upc?("9780345431931235")).to be_falsey
|
70
58
|
|
71
|
-
expect(
|
72
|
-
expect(
|
59
|
+
expect(described_class.valid_upc?("97803454319412356")).to be_falsey
|
60
|
+
expect(described_class.valid_upc?("97803454319212356")).to be_falsey
|
73
61
|
end
|
74
62
|
end
|
75
63
|
|
76
|
-
describe
|
77
|
-
it
|
78
|
-
expect(
|
79
|
-
expect(
|
80
|
-
expect(
|
64
|
+
describe "#canonicalise_isbn" do
|
65
|
+
it "returns the correct value for several examples" do
|
66
|
+
expect(described_class.canonicalise_isbn("014143984X")).to eq "014143984X"
|
67
|
+
expect(described_class.canonicalise_isbn("0-345-43192-8")).to eq "0345431928"
|
68
|
+
expect(described_class.canonicalise_isbn("3522105907")).to eq "3522105907"
|
81
69
|
# EAN number
|
82
|
-
expect(
|
70
|
+
expect(described_class.canonicalise_isbn("9780345431929")).to eq "0345431928"
|
83
71
|
end
|
84
72
|
end
|
85
73
|
|
86
|
-
context
|
87
|
-
|
74
|
+
context "with an empty library" do
|
75
|
+
let(:my_library) { loader.load_library("Empty") }
|
76
|
+
|
77
|
+
before do
|
88
78
|
FileUtils.mkdir(TESTDIR) unless File.exist? TESTDIR
|
89
79
|
end
|
90
80
|
|
91
|
-
it
|
92
|
-
my_library = Alexandria::Library.loadall[0]
|
81
|
+
it "disallows multiple deletion of the same copy of a book" do
|
93
82
|
first_copy = an_artist_of_the_floating_world
|
94
83
|
my_library << first_copy
|
95
84
|
my_library.delete(first_copy)
|
96
85
|
expect { my_library.delete(first_copy) }.to raise_error ArgumentError
|
97
86
|
end
|
98
87
|
|
99
|
-
it
|
100
|
-
my_library = Alexandria::Library.loadall[0]
|
88
|
+
it "allows multiple copies of a book to be added and deleted in turn" do
|
101
89
|
first_copy = an_artist_of_the_floating_world
|
102
|
-
# puts "first_copy #{first_copy.object_id}"
|
103
90
|
my_library << first_copy
|
104
91
|
my_library.delete(first_copy)
|
105
92
|
|
@@ -108,169 +95,140 @@ describe Alexandria::Library do
|
|
108
95
|
third_copy = an_artist_of_the_floating_world
|
109
96
|
my_library << third_copy
|
110
97
|
|
111
|
-
# puts "AAA my_library.size #{my_library.size}"
|
112
|
-
|
113
|
-
# puts "second_copy #{second_copy.object_id}"
|
114
98
|
expect { my_library.delete(second_copy) }.not_to raise_error
|
115
|
-
|
116
|
-
# puts "BBB my_library.size #{my_library.size}"
|
117
|
-
# my_library.size.should == 1 # not yet an established feature...
|
118
|
-
end
|
119
|
-
|
120
|
-
after(:each) do
|
121
|
-
FileUtils.rm_rf(TESTDIR)
|
122
99
|
end
|
123
100
|
end
|
124
101
|
|
125
|
-
describe
|
126
|
-
before
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
def __test_fake_import_isbns
|
131
|
-
libraries = Alexandria::Libraries.instance
|
132
|
-
library = Alexandria::Library.new('Test Library')
|
102
|
+
describe ".import_as_isbn_list" do
|
103
|
+
before do
|
104
|
+
libraries = Alexandria::LibraryCollection.instance
|
105
|
+
library = described_class.new("Test Library")
|
133
106
|
libraries.add_library(library)
|
134
|
-
|
107
|
+
|
108
|
+
allow(Alexandria::BookProviders)
|
109
|
+
.to receive(:isbn_search)
|
110
|
+
.and_raise Alexandria::BookProviders::SearchEmptyError
|
111
|
+
allow(Alexandria::BookProviders)
|
112
|
+
.to receive(:isbn_search).with("0595371086")
|
113
|
+
.and_return(an_artist_of_the_floating_world)
|
135
114
|
end
|
136
115
|
|
137
|
-
it "
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
116
|
+
it "imports books with correct isbn and search result" do
|
117
|
+
library, bad_isbns, failed_lookup_isbns =
|
118
|
+
described_class.import_as_isbn_list("Test Library", "spec/data/isbns.txt",
|
119
|
+
proc {}, proc {})
|
120
|
+
|
121
|
+
aggregate_failures do
|
122
|
+
expect(library.to_a).to eq [an_artist_of_the_floating_world]
|
123
|
+
expect(bad_isbns).to eq ["0911826449"]
|
124
|
+
expect(failed_lookup_isbns).to eq ["0740704923"]
|
125
|
+
end
|
145
126
|
end
|
146
127
|
end
|
147
128
|
|
148
|
-
context
|
149
|
-
|
150
|
-
|
129
|
+
context "when importing from 0.6.1 data files" do
|
130
|
+
let(:libs) { loader.load_all_libraries }
|
131
|
+
let(:my_library) { libs[0] }
|
132
|
+
|
133
|
+
before do
|
134
|
+
lib_version = File.join(LIBDIR, "0.6.1")
|
151
135
|
FileUtils.cp_r(lib_version, TESTDIR)
|
152
136
|
end
|
153
137
|
|
154
|
-
it
|
155
|
-
libs = Alexandria::Library.loadall
|
138
|
+
it "can be loaded" do
|
156
139
|
expect(libs.size).to eq(1)
|
157
|
-
my_library = libs[0]
|
158
140
|
expect(my_library.size).to eq(3)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "imports cleanly from version 0.6.1 data format" do
|
159
144
|
# Malory
|
160
|
-
malory_book = my_library.
|
161
|
-
expect(malory_book.publisher).to eq(
|
162
|
-
expect(malory_book.authors.include?(
|
145
|
+
malory_book = my_library.find { |b| b.isbn == "9780192812179" }
|
146
|
+
expect(malory_book.publisher).to eq("Oxford University Press")
|
147
|
+
expect(malory_book.authors.include?("Vinaver")).to be_truthy
|
163
148
|
expect(malory_book.version).to eq(Alexandria::DATA_VERSION)
|
164
149
|
|
165
150
|
# Guide to LaTeX
|
166
|
-
latex_book = my_library.
|
167
|
-
expect(latex_book.isbn).to eq(
|
168
|
-
expect(latex_book.publisher).to eq(
|
169
|
-
end
|
170
|
-
|
171
|
-
after(:each) do
|
172
|
-
FileUtils.rm_rf(TESTDIR)
|
151
|
+
latex_book = my_library.find { |b| b.title.include? "Latex" }
|
152
|
+
expect(latex_book.isbn).to eq("9780201398250")
|
153
|
+
expect(latex_book.publisher).to eq("Addison Wesley") # note, no Ruby-Amazon cruft
|
173
154
|
end
|
174
155
|
end
|
175
156
|
|
176
|
-
context
|
177
|
-
|
178
|
-
|
157
|
+
context "when importing from 0.6.1 with books without an ISBN" do
|
158
|
+
let(:libs) { loader.load_all_libraries }
|
159
|
+
let(:my_library) { libs[0] }
|
160
|
+
|
161
|
+
before do
|
162
|
+
lib_version = File.join(LIBDIR, "0.6.1-noisbn")
|
179
163
|
FileUtils.cp_r(lib_version, TESTDIR)
|
180
164
|
end
|
181
165
|
|
182
|
-
|
183
|
-
|
166
|
+
after do
|
167
|
+
FileUtils.rm_rf(TESTDIR)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "can be loaded" do
|
184
171
|
expect(libs.size).to eq(1)
|
185
|
-
my_library = libs[0]
|
186
172
|
expect(my_library.size).to eq(2)
|
173
|
+
end
|
187
174
|
|
175
|
+
it "loads a book with ISBN" do
|
188
176
|
# Guide to LaTeX
|
189
|
-
latex_book = my_library.
|
190
|
-
expect(latex_book.isbn).to eq(
|
191
|
-
expect(latex_book.publisher).to eq(
|
177
|
+
latex_book = my_library.find { |b| b.title.include? "Latex" }
|
178
|
+
expect(latex_book.isbn).to eq("9780201398250")
|
179
|
+
expect(latex_book.publisher).to eq("Addison Wesley") # note, no Ruby-Amazon cruft
|
192
180
|
expect(latex_book.version).to eq(Alexandria::DATA_VERSION)
|
181
|
+
end
|
193
182
|
|
183
|
+
it "loads a book without ISBN" do
|
194
184
|
# Lex and Yacc
|
195
|
-
lex_and_yacc_book = my_library.
|
185
|
+
lex_and_yacc_book = my_library.find { |b| b.title.include? "Lex" }
|
196
186
|
expect(lex_and_yacc_book.publisher).to eq("O'Reilley")
|
187
|
+
end
|
197
188
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
my_library.save(book, true)
|
202
|
-
end
|
203
|
-
|
204
|
-
libraries_reloaded = Alexandria::Library.loadall
|
205
|
-
my_library_reloaded = libraries_reloaded[0]
|
206
|
-
|
189
|
+
it "saves loaded books properly" do
|
190
|
+
my_library.each { |book| my_library.save(book, true) }
|
191
|
+
my_library_reloaded = loader.load_all_libraries[0]
|
207
192
|
expect(my_library_reloaded.size).to eq(2)
|
208
193
|
|
209
|
-
latex_book = my_library_reloaded.
|
210
|
-
expect(latex_book).
|
211
|
-
expect(latex_book.publisher).to eq('Addison Wesley')
|
212
|
-
# puts latex_book.title
|
194
|
+
latex_book = my_library_reloaded.find { |b| b.title.include? "Latex" }
|
195
|
+
expect(latex_book.publisher).to eq("Addison Wesley")
|
213
196
|
|
214
|
-
lex_and_yacc_book = my_library_reloaded.
|
215
|
-
expect(lex_and_yacc_book).not_to be_nil
|
197
|
+
lex_and_yacc_book = my_library_reloaded.find { |b| b.title.include? "Lex" }
|
216
198
|
expect(lex_and_yacc_book.publisher).to eq("O'Reilley")
|
217
|
-
# puts lex_and_yacc_book.title
|
218
|
-
end
|
219
|
-
|
220
|
-
after(:each) do
|
221
|
-
FileUtils.rm_rf(TESTDIR)
|
222
199
|
end
|
223
200
|
end
|
224
201
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
end
|
202
|
+
describe ".move" do
|
203
|
+
let(:source) { loader.load_library("My Library") }
|
204
|
+
let(:target) { loader.load_library("Target") }
|
205
|
+
let(:book) { source.first }
|
230
206
|
|
231
|
-
before
|
232
|
-
lib_version = File.join(LIBDIR,
|
207
|
+
before do
|
208
|
+
lib_version = File.join(LIBDIR, "0.6.2")
|
233
209
|
FileUtils.cp_r(lib_version, TESTDIR)
|
234
|
-
@format = Alexandria::ExportFormat.new('CSV list', 'csv', :export_as_csv_list)
|
235
|
-
@outfile = File.join(Dir.tmpdir, 'my_library-0.6.2.csv')
|
236
|
-
@my_library = Alexandria::Library.loadall[0]
|
237
210
|
end
|
238
211
|
|
239
|
-
|
240
|
-
|
241
|
-
end
|
212
|
+
it "changes the number of books in the source and target libraries" do
|
213
|
+
count = source.count
|
242
214
|
|
243
|
-
|
244
|
-
sort_by_title = Alexandria::LibrarySortOrder.new(:title)
|
245
|
-
@format.invoke(@my_library, sort_by_title, @outfile)
|
246
|
-
expect(File.exist?(@outfile)).to be_truthy
|
247
|
-
rows = load_rows_from_csv
|
248
|
-
rows.shift
|
249
|
-
expect(rows.size).to eq(@my_library.size)
|
250
|
-
TITLE = 0
|
251
|
-
comparisons = rows.size - 1
|
252
|
-
comparisons.times do |index|
|
253
|
-
expect(rows[index][TITLE]).to be <= rows[index + 1][TITLE]
|
254
|
-
end
|
255
|
-
end
|
215
|
+
described_class.move(source, target, book)
|
256
216
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
expect(File.exist?(@outfile)).to be_truthy
|
261
|
-
rows = load_rows_from_csv
|
262
|
-
rows.shift
|
263
|
-
expect(rows.size).to eq(@my_library.size)
|
264
|
-
DATE = 5
|
265
|
-
comparisons = rows.size - 1
|
266
|
-
comparisons.times do |index|
|
267
|
-
expect(rows[index][DATE]).to be >= rows[index + 1][DATE]
|
217
|
+
aggregate_failures do
|
218
|
+
expect(source.count).to eq count - 1
|
219
|
+
expect(target.count).to eq 1
|
268
220
|
end
|
269
221
|
end
|
270
222
|
|
271
|
-
|
272
|
-
|
273
|
-
|
223
|
+
it "moves the book files from source to target" do
|
224
|
+
described_class.move(source, target, book)
|
225
|
+
|
226
|
+
aggregate_failures do
|
227
|
+
expect(File.exist?(source.yaml(book))).to be_falsey
|
228
|
+
expect(File.exist?(source.cover(book))).to be_falsey
|
229
|
+
expect(File.exist?(target.yaml(book))).to be_truthy
|
230
|
+
expect(File.exist?(target.cover(book))).to be_truthy
|
231
|
+
end
|
274
232
|
end
|
275
233
|
end
|
276
234
|
end
|