talia_core 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/VERSION.yml +1 -1
  2. data/generators/generator_helpers.rb +35 -2
  3. data/generators/talia_admin/talia_admin_generator.rb +6 -0
  4. data/generators/talia_admin/templates/controllers/admin/background_controller.rb +2 -0
  5. data/generators/talia_admin/templates/controllers/admin/roles_controller.rb +8 -0
  6. data/generators/talia_admin/templates/controllers/admin/sources_controller.rb +2 -64
  7. data/generators/talia_admin/templates/controllers/admin/users_controller.rb +3 -41
  8. data/generators/talia_admin/templates/controllers/admin_controller.rb +1 -1
  9. data/generators/talia_admin/templates/helpers/admin/roles_helper.rb +2 -0
  10. data/generators/talia_admin/templates/helpers/admin/users_helper.rb +9 -0
  11. data/generators/talia_admin/templates/helpers/admin_helper.rb +19 -0
  12. data/generators/{talia_base → talia_admin}/templates/migrations/populate_users.rb +5 -2
  13. data/generators/talia_admin/templates/models/role.rb +3 -0
  14. data/generators/talia_admin/templates/public/stylesheets/backend.css +1 -4
  15. data/generators/talia_admin/templates/views/admin/index.html.erb +3 -3
  16. data/generators/talia_admin/templates/views/admin/sources/_show.html.erb +13 -0
  17. data/generators/talia_admin/templates/views/layouts/admin.html.erb +5 -5
  18. data/generators/talia_base/talia_base_generator.rb +11 -18
  19. data/generators/talia_base/templates/README +15 -0
  20. data/generators/talia_base/templates/app/controllers/sources_controller.rb +125 -7
  21. data/generators/talia_base/templates/app/helpers/sources_helper.rb +19 -35
  22. data/generators/talia_base/templates/app/views/sources/index.html.erb +12 -1
  23. data/generators/talia_base/templates/app/views/sources/semantic_templates/default/default.html.erb +21 -0
  24. data/generators/talia_base/templates/app/views/sources/semantic_templates/default/province.html.erb +19 -0
  25. data/generators/talia_base/templates/config/routes.rb +24 -4
  26. data/generators/talia_base/templates/script/setup_talia_backend +35 -0
  27. data/lib/loader_helper.rb +8 -1
  28. data/lib/talia_core/active_source.rb +9 -6
  29. data/lib/talia_core/active_source_parts/class_methods.rb +2 -1
  30. data/lib/talia_core/active_source_parts/predicate_handler.rb +12 -0
  31. data/lib/talia_core/active_source_parts/rdf.rb +1 -1
  32. data/lib/talia_core/data_types/iip_loader.rb +2 -0
  33. data/lib/talia_core/dc_resource.rb +1 -1
  34. data/lib/talia_core/initializer.rb +2 -0
  35. data/lib/talia_core/semantic_relation.rb +1 -1
  36. data/lib/talia_util/rake_tasks.rb +2 -2
  37. data/lib/talia_util/util.rb +1 -1
  38. data/test/talia_core/active_source_predicate_test.rb +2 -6
  39. data/test/talia_core/active_source_rdf_test.rb +9 -5
  40. data/test/talia_core/active_source_test.rb +50 -44
  41. data/test/talia_core/data_types/data_loader_test.rb +2 -2
  42. data/test/talia_core/data_types/data_record_test.rb +1 -1
  43. data/test/talia_core/data_types/file_record_test.rb +4 -3
  44. data/test/talia_core/data_types/iip_data_test.rb +2 -2
  45. data/test/talia_core/data_types/image_data_test.rb +1 -1
  46. data/test/talia_core/data_types/pdf_data_test.rb +1 -1
  47. data/test/talia_core/data_types/xml_data_test.rb +3 -2
  48. data/test/talia_core/initializer_test.rb +1 -1
  49. data/test/talia_core/ordered_source_test.rb +1 -5
  50. data/test/talia_core/rdf_resource_test.rb +1 -5
  51. data/test/talia_core/semantic_collection_item_test.rb +3 -7
  52. data/test/talia_core/source_test.rb +7 -12
  53. data/test/talia_core/workflow/publication_workflow_test.rb +36 -23
  54. data/test/talia_util/import_job_helper_test.rb +1 -5
  55. data/test/test_helper.rb +18 -5
  56. metadata +11 -52
  57. data/generators/talia_admin/templates/test/fixtures/users.yml +0 -32
  58. data/generators/talia_admin/templates/test/unit/user_test.rb +0 -134
  59. data/generators/talia_admin/templates/views/admin/sources/_data.html.erb +0 -6
  60. data/generators/talia_admin/templates/views/admin/sources/_data_form.html.erb +0 -15
  61. data/generators/talia_admin/templates/views/admin/sources/_form.html.erb +0 -7
  62. data/generators/talia_admin/templates/views/admin/sources/_list.html.erb +0 -3
  63. data/generators/talia_admin/templates/views/admin/sources/_notice.html.erb +0 -1
  64. data/generators/talia_admin/templates/views/admin/sources/_predicate.html.erb +0 -22
  65. data/generators/talia_admin/templates/views/admin/sources/_predicates.html.erb +0 -15
  66. data/generators/talia_admin/templates/views/admin/sources/_sources.html.erb +0 -17
  67. data/generators/talia_admin/templates/views/admin/sources/_upload.html.erb +0 -6
  68. data/generators/talia_admin/templates/views/admin/sources/edit.html.erb +0 -6
  69. data/generators/talia_admin/templates/views/admin/sources/index.html.erb +0 -5
  70. data/generators/talia_admin/templates/views/admin/users/_form.html.erb +0 -10
  71. data/generators/talia_admin/templates/views/admin/users/_form_roles.html.erb +0 -8
  72. data/generators/talia_admin/templates/views/admin/users/edit.html.erb +0 -12
  73. data/generators/talia_admin/templates/views/admin/users/index.html.erb +0 -22
  74. data/generators/talia_admin/templates/views/admin/users/new.html.erb +0 -5
  75. data/generators/talia_admin/templates/views/admin/users/show.html.erb +0 -6
  76. data/generators/talia_base/templates/app/controllers/sessions_controller.rb +0 -90
  77. data/generators/talia_base/templates/app/controllers/source_data/show.html.erb +0 -2
  78. data/generators/talia_base/templates/app/helpers/source_data/show.html.erb +0 -2
  79. data/generators/talia_base/templates/app/views/sessions/new.html.erb +0 -33
  80. data/generators/talia_base/templates/migrations/create_open_id.rb +0 -26
  81. data/generators/talia_base/templates/migrations/create_roles.rb +0 -20
  82. data/generators/talia_base/templates/migrations/create_sessions.rb +0 -16
  83. data/generators/talia_base/templates/migrations/create_users.rb +0 -20
  84. data/lib/role.rb +0 -12
  85. data/lib/talia_cl/command_line.rb +0 -39
  86. data/lib/talia_cl/commands/standalone/cl_options.rb +0 -9
  87. data/lib/talia_cl/commands/standalone/standalone_generate.rb +0 -75
  88. data/lib/talia_cl/commands/standalone.rb +0 -25
  89. data/lib/talia_cl/commands/talia_console/cl_options.rb +0 -55
  90. data/lib/talia_cl/commands/talia_console/console_commands.rb +0 -37
  91. data/lib/talia_cl/commands/talia_console/talia_commands.rb +0 -131
  92. data/lib/talia_cl/commands/talia_console.rb +0 -47
  93. data/lib/talia_cl/core_commands.rb +0 -11
  94. data/lib/talia_cl.rb +0 -47
  95. data/lib/user.rb +0 -116
@@ -0,0 +1,21 @@
1
+ <div class="back"><%= index_link %></div>
2
+
3
+ <h2><%= @source.uri.to_name_s %></h2>
4
+ <table>
5
+ <% for attribute, value in @source.attributes %>
6
+ <tr>
7
+ <td><%= attribute %></td>
8
+ <td><%= value %></td>
9
+ </tr>
10
+ <% end %>
11
+ <% for predicate in @source.direct_predicates %>
12
+ <tr>
13
+ <td><%= predicate %></td>
14
+ <td>
15
+ <% @source[predicate].each do |val| %>
16
+ <%= val %><br/>
17
+ <% end %>
18
+ </td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
@@ -0,0 +1,19 @@
1
+ <h2>PROVINCE <%= @source.uri.to_name_s %></h2>
2
+ <table>
3
+ <% for attribute, value in @source.attributes %>
4
+ <tr>
5
+ <td><%= attribute %></td>
6
+ <td><%= value %></td>
7
+ </tr>
8
+ <% end %>
9
+ <% for predicate in @source.direct_predicates %>
10
+ <tr>
11
+ <td><%= predicate %></td>
12
+ <td>
13
+ <% @source[predicate].each do |val| %>
14
+ <%= val %><br/>
15
+ <% end %>
16
+ </td>
17
+ </tr>
18
+ <% end %>
19
+ </table>
@@ -1,4 +1,20 @@
1
1
  ActionController::Routing::Routes.draw do |map|
2
+ map.logout '/logout', :controller => 'sessions', :action => 'destroy'
3
+ map.login '/login', :controller => 'sessions', :action => 'new'
4
+ map.register '/register', :controller => 'users', :action => 'create'
5
+ map.signup '/signup', :controller => 'users', :action => 'new'
6
+ map.resources :users
7
+
8
+ map.resource :session
9
+
10
+ map.logout '/logout', :controller => 'sessions', :action => 'destroy'
11
+ map.login '/login', :controller => 'sessions', :action => 'new'
12
+ map.register '/register', :controller => 'users', :action => 'create'
13
+ map.signup '/signup', :controller => 'users', :action => 'new'
14
+ map.resources :users
15
+
16
+ map.resource :session
17
+
2
18
  # The priority is based upon order of creation: first created -> highest priority.
3
19
 
4
20
  # Sample of regular route:
@@ -31,8 +47,8 @@ ActionController::Routing::Routes.draw do |map|
31
47
 
32
48
  map.namespace :admin do |admin|
33
49
  admin.resources :translations, :collection => { :search => :get }
34
- admin.resources :users
35
- admin.resources :sources
50
+ admin.resources :users, :active_scaffold => true
51
+ admin.resources :sources, :active_scaffold => true
36
52
  admin.resources :locales
37
53
  admin.resources :background, :active_scaffold => true
38
54
  admin.resources :custom_templates, :active_scaffold => true
@@ -76,8 +92,12 @@ ActionController::Routing::Routes.draw do |map|
76
92
  # Routes for import
77
93
  map.connect 'import/:action', :controller => 'import', :action => 'start_import'
78
94
 
79
- map.connect ':controller/:action/:id.:format'
80
- map.connect ':controller/:action/:id'
95
+ # Default semantic dispatch
96
+ map.connect ':dispatch_uri.:format', :controller => 'sources', :action => 'dispatch',
97
+ :requirements => { :dispatch_uri => /[^\.]+/ }
98
+
99
+ # map.connect ':controller/:action/:id.:format'
100
+ map.connect ':controller/:action/:id'
81
101
 
82
102
 
83
103
  end
@@ -0,0 +1,35 @@
1
+ #!/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../config/boot'
4
+ require "#{RAILS_ROOT}/config/environment"
5
+ require 'rails_generator'
6
+ require 'rails_generator/scripts/generate'
7
+
8
+ puts "Install and configure restful authentication"
9
+ # First time plugin, has to be done this way since it can not be loaded in
10
+ # a different way
11
+ ARGV = ['install', 'git://github.com/technoweenie/restful-authentication.git']
12
+ require 'commands/plugin'
13
+ orig_name = $0
14
+ $0 = 'generate'
15
+ Rails::Generator::Scripts::Generate.new.run(%w(authenticated user sessions))
16
+
17
+ puts "Install and configure role-requirements"
18
+ Commands::Plugin.parse!(['install', 'git://github.com/timcharper/role_requirement.git'])
19
+ Rails::Generator::Scripts::Generate.new.run(%w(roles Role User))
20
+
21
+ if(Rails::VERSION::MAJOR > 2 ||(Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR > 2))
22
+ # TODO: Needed only as long as ActiveScaffold depends on it
23
+ puts "Install the render_component plugin for ActiveScaffold (optional since Rails 2.2)"
24
+ Commands::Plugin.parse!(['install', 'git://github.com/lackac/render_component.git', '-r', 'rails-edge'])
25
+ end
26
+
27
+
28
+ puts "Install the adminstration backend"
29
+ Rails::Generator::Scripts::Generate.new.run(%w(talia_admin))
30
+
31
+ puts "Migrating the database"
32
+ system("rake db:migrate")
33
+
34
+ migration_path = File.join(RAILS_ROOT, 'db', 'migrate')
35
+ ActiveRecord::Migrator.migrate(migration_path)
data/lib/loader_helper.rb CHANGED
@@ -42,7 +42,14 @@ module TLoad
42
42
  require_module("actionpack", "action_controller", "/../../../rails/actionpack", RAILS_GEM_VERSION)
43
43
  # This sets the automatic loader path for Talia, allowing the ActiveSupport
44
44
  # classes to automatically load classes from this directory.
45
- ActiveSupport::Dependencies.load_paths << TLoad.start_dir unless(ActiveSupport::Dependencies.load_paths.include?(TLoad.start_dir))
45
+ load_paths = ActiveSupport::Dependencies.load_paths
46
+ load_paths << TLoad.start_dir unless(load_paths.include?(TLoad.start_dir))
47
+ # Add the other plugins to the path, if we have a Rails root
48
+ if(defined?(RAILS_ROOT))
49
+ Dir["#{RAILS_ROOT}/vendor/plugins/*/lib"].each do |plugin_dir|
50
+ load_paths << plugin_dir if(File.directory?(plugin_dir) || !load_paths.include?(plugin_dir))
51
+ end
52
+ end
46
53
  end
47
54
 
48
55
  # Sets up the ActiveSupport autoload path
@@ -217,11 +217,6 @@ module TaliaCore
217
217
  rels = SemanticRelation.find_by_sql("SELECT DISTINCT predicate_uri FROM semantic_relations WHERE object_id = #{self.id}")
218
218
  rels.collect { |rel| N::Predicate.new(rel.predicate_uri) }
219
219
  end
220
-
221
- # Returns if the Facsimile is of the given type
222
- def has_type?(type)
223
- (self.types.include?(type))
224
- end
225
220
 
226
221
  # True if the given attribute is a database attribute
227
222
  def db_attr?(attribute)
@@ -271,9 +266,12 @@ module TaliaCore
271
266
  #
272
267
  # This will check the existing types to avoid duplication
273
268
  def add_additional_rdf_types
274
- return if(self.class.additional_rdf_types.size == 0) # Avoid database access if there's nothing to do
269
+ # return if(self.class.additional_rdf_types.empty?)
275
270
  type_hash = {}
276
271
  self.types.each { |type| type_hash[type.respond_to?(:uri) ? type.uri.to_s : type.to_s] = true }
272
+ # Add the "class" default type type (unless this is the source for the self type itself).0
273
+ self.types << rdf_selftype unless(type_hash[rdf_selftype.to_s] || (rdf_selftype.to_s == self.uri.to_s))
274
+ # Add the user-configured types
277
275
  self.class.additional_rdf_types.each do |type|
278
276
  self.types << type unless(type_hash[type.respond_to?(:uri) ? type.uri.to_s : type.to_s])
279
277
  end
@@ -312,6 +310,11 @@ module TaliaCore
312
310
  data_records.find(find_type, options)
313
311
  end
314
312
 
313
+ # The RDF type that is used for objects of the current class
314
+ def rdf_selftype
315
+ (N::TALIA + self.class.name.demodulize)
316
+ end
317
+
315
318
  private
316
319
 
317
320
  # Extracts the semantic attributes from the attribute hash and passes them
@@ -126,7 +126,7 @@ module TaliaCore
126
126
  # [*:find_through*] accepts and array with an predicate name and an object
127
127
  # value/uri, to search for predicates that match the given predicate/value
128
128
  # combination
129
- # [*:type] specifically looks for sources with the given type.
129
+ # [*:type*] specifically looks for sources with the given type.
130
130
  # [*:find_through_inv*] like :find_through, but for the "inverse" lookup
131
131
  # [*:prefetch_relations*] if set to "true", this will pre-load all semantic
132
132
  # relations for the sources (experimental, not fully implemented yet)
@@ -298,6 +298,7 @@ module TaliaCore
298
298
  # that method exists; otherwise it'll return nil
299
299
  def uri_string_for(value)
300
300
  result = if value.is_a? String
301
+ return nil if(value =~ /\A\d+\Z/) # This looks like a record id, encoded as a string
301
302
  # if this is a local name, prepend the local namespace
302
303
  (value =~ /:/) ? value : (N::LOCAL + value).uri
303
304
  elsif(value.respond_to?(:uri))
@@ -31,6 +31,7 @@ module TaliaCore
31
31
  # Set all as loaded
32
32
  sources.each do |src|
33
33
  src.each_cached_wrapper { |wrap| wrap.instance_variable_set(:'@loaded', true) }
34
+ src.instance_variable_set(:'@prefetched', true)
34
35
  end
35
36
  end
36
37
 
@@ -40,15 +41,26 @@ module TaliaCore
40
41
  def types
41
42
  get_objects_on(N::RDF.type.to_s)
42
43
  end
44
+
45
+ # Returns if the Facsimile is of the given type
46
+ def has_type?(type)
47
+ (self.types.include?(type))
48
+ end
43
49
 
44
50
  # Returns the objects on the given predicate. This will be cached internally
45
51
  # so that the object will always be the same as long as the parent source
46
52
  # lives.
47
53
  def get_objects_on(predicate)
54
+ TaliaCore::logger.warn "GETTING OBJECTS (#{predicate}) #{@type_cache.inspect}"
48
55
  @type_cache ||= {}
49
56
  active_wrapper = @type_cache[predicate.to_s]
50
57
 
58
+
51
59
  if(active_wrapper.nil?)
60
+ # If this is a prefetched source we have everything - no use looking further
61
+ # TODO: Returns an Array instead of a wrapper
62
+ return [] if(@prefetched)
63
+
52
64
  active_wrapper = SemanticCollectionWrapper.new(self, predicate)
53
65
  @type_cache[predicate.to_s] = active_wrapper
54
66
  end
@@ -61,7 +61,7 @@ module TaliaCore
61
61
  value = obj.is_a?(SemanticProperty) ? obj.value : obj
62
62
  my_rdf.direct_write_predicate(N::URI.new(sem_ref.predicate_uri), value)
63
63
  end
64
- my_rdf.direct_write_predicate(N::RDF.type, (N::TALIA + self.class.name.demodulize))
64
+ my_rdf.direct_write_predicate(N::RDF.type, rdf_selftype)
65
65
  my_rdf.save
66
66
  end
67
67
  end
@@ -1,3 +1,5 @@
1
+ require 'tmpdir'
2
+
1
3
  module TaliaCore
2
4
  module DataTypes
3
5
 
@@ -11,7 +11,7 @@ module TaliaCore
11
11
  singular_property :description, N::DCNS.description
12
12
  simple_property :publishers, N::DCNS.publisher
13
13
  singular_property :language, N::DCNS.language
14
- simple_property :subjects, N::DCNS.subject
14
+ simple_property :dc_subjects, N::DCNS.subject
15
15
  singular_property :rights, N::DCNS.rights
16
16
  singular_property :title, N::DCNS.title
17
17
 
@@ -287,6 +287,8 @@ module TaliaCore
287
287
  ActiveRecord::Base.logger = talia_logger
288
288
  end
289
289
  end
290
+ talia_logger.info("Setting Active Record to full STI use.") unless(ActiveRecord::Base.store_full_sti_class)
291
+ ActiveRecord::Base.store_full_sti_class = true
290
292
  end
291
293
 
292
294
  # Get the RDF configuration options
@@ -1,6 +1,6 @@
1
1
  module TaliaCore
2
2
  class SemanticRelation < ActiveRecord::Base
3
- belongs_to :subject, :class_name => 'ActiveSource'
3
+ belongs_to :subject, :class_name => 'TaliaCore::ActiveSource'
4
4
  belongs_to :object, :polymorphic => true
5
5
  before_destroy :discard_property
6
6
 
@@ -18,7 +18,7 @@ namespace :talia_core do
18
18
  task :talia_init do
19
19
  Util::title
20
20
  Util::init_talia
21
- TLoad::force_rails_parts
21
+ TLoad::force_rails_parts unless(defined?(ActiveRecord))
22
22
  Util::talia_config if(Util::flag?('verbose'))
23
23
  # Add load paths to allow autoloading of all class from this tasks
24
24
  ActiveSupport::Dependencies.load_paths << File.join(TALIA_ROOT, 'lib')
@@ -53,7 +53,7 @@ namespace :talia_core do
53
53
  Rake::TestTask.new(:test) do |t|
54
54
  t.libs << 'lib'
55
55
  # This will always take the files from the talia_core directory
56
- t.test_files = FileList["#{File.dirname(__FILE__)}/../test/**/*_test.rb"]
56
+ t.test_files = FileList["#{File.dirname(__FILE__)}/../../test/**/*_test.rb"]
57
57
  t.verbose = true
58
58
  end
59
59
 
@@ -94,7 +94,7 @@ module TaliaUtil
94
94
 
95
95
  # Flush the database. This only flushes the main data tables!
96
96
  def flush_db
97
- [ 'active_sources', 'data_records', 'semantic_properties', 'semantic_relations'].reverse.each { |f| ActiveRecord::Base.connection.execute "DELETE FROM #{f}" }
97
+ [ 'active_sources', 'data_records', 'semantic_properties', 'semantic_relations', 'workflows'].reverse.each { |f| ActiveRecord::Base.connection.execute "DELETE FROM #{f}" }
98
98
  # Also remove the "unsaved cache" for the wrappers (may be important during testing)
99
99
  TaliaCore::SemanticCollectionWrapper.instance_variable_set(:'@unsaved_source_cache', {})
100
100
  end
@@ -7,11 +7,7 @@ module TaliaCore
7
7
  class ActiveSourcePredicateTest < Test::Unit::TestCase
8
8
 
9
9
  def setup
10
- setup_once(:flush) do
11
- TaliaUtil::Util.flush_rdf
12
- TaliaUtil::Util.flush_db
13
- true
14
- end
10
+ setup_once(:flush) { TestHelper::flush_store }
15
11
  end
16
12
 
17
13
  def test_each_cached
@@ -21,7 +17,7 @@ module TaliaCore
21
17
  src.each_cached_wrapper do |w|
22
18
  cached << w
23
19
  end
24
- assert_equal(1, cached.size)
20
+ assert_equal(2, cached.size)
25
21
  end
26
22
 
27
23
  def test_cached_predicate
@@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
4
4
  module TaliaCore
5
5
 
6
6
  # Test the ActiveSource
7
- class ActiveSourceRdfTest < Test::Unit::TestCase
7
+ class ActiveSourceRdfTest < ActiveSupport::TestCase
8
8
  fixtures :active_sources, :semantic_properties, :semantic_relations
9
9
 
10
10
  def setup
@@ -31,11 +31,11 @@ module TaliaCore
31
31
  src[N::RDF.rew] << 'value'
32
32
  src.save!
33
33
  # Test that there is 1 element now
34
- assert_equal(1, (vals = SemanticRelation.find(:all, :conditions => {'subject_id' => src.id })).size, "Expected 1 value, got [#{print_rels(vals)}]")
35
- assert_equal(1, src.semantic_relations.size)
34
+ assert_equal(2, (vals = SemanticRelation.find(:all, :conditions => {'subject_id' => src.id })).size, "Expected 1 value, got [#{print_rels(vals)}]")
35
+ assert_equal(2, src.semantic_relations.size)
36
36
  # Test if the element can be removed
37
37
  src[N::RDF.rew].remove
38
- assert_equal(0, (vals = SemanticRelation.find(:all, :conditions => {'subject_id' => src.id })).size, "Expected 0 values, got [#{print_rels(vals)}]")
38
+ assert_equal(1, (vals = SemanticRelation.find(:all, :conditions => {'subject_id' => src.id })).size, "Expected 0 values, got [#{print_rels(vals)}]")
39
39
  assert_equal(0, src[N::RDF.rew].size)
40
40
  end
41
41
 
@@ -82,7 +82,11 @@ module TaliaCore
82
82
  protected
83
83
 
84
84
  def print_rels(relations)
85
- relations.collect { |relation| "<#{relation.subject.uri} - #{relation.predicate_uri} - #{relation.object.is_a?(ActiveSource) ? relation.object.uri : relation.object.value}> | " }
85
+ begin
86
+ relations.collect { |relation| "<#{relation.subject.uri} - #{relation.predicate_uri} - #{relation.object.is_a?(ActiveSource) ? relation.object.uri : relation.object.value}> | " }
87
+ rescue
88
+ relations.inspect
89
+ end
86
90
  end
87
91
 
88
92
  end
@@ -8,37 +8,21 @@ module TaliaCore
8
8
  end
9
9
 
10
10
  # Test the ActiveSource
11
- class ActiveSourceTest < Test::Unit::TestCase
12
- fixtures :active_sources, :semantic_properties, :semantic_relations
11
+ class ActiveSourceTest < ActiveSupport::TestCase
12
+ fixtures :active_sources, :semantic_properties, :semantic_relations, :data_records
13
13
 
14
14
  N::Namespace.shortcut(:as_test_preds, 'http://testvalue.org/')
15
-
16
- def setup
17
- setup_once(:flush) do
18
- TaliaUtil::Util.flush_rdf
19
- true
20
- end
21
-
22
- setup_once(:data_source) do
23
- data_source = ActiveSource.new("http://www.test.org/source_with_data")
24
- text = DataTypes::SimpleText.new
25
- text.location = "text.txt"
26
- image = DataTypes::ImageData.new
27
- image.location = "image.jpg"
28
- data_source.data_records << text
29
- data_source.data_records << image
30
- data_source.save!
31
- data_source
32
- end
33
-
34
- end
35
15
 
36
16
  def test_has_type
37
- facs = ActiveSource.new('http://facsimile/has_type_test')
38
- facs.types << N::HYPER.testtype
39
- assert(facs.has_type?(N::HYPER.testtype))
17
+ src = ActiveSource.new('http://xsource/has_type_test')
18
+ src.types << N::HYPER.testtype
19
+ assert(src.has_type?(N::HYPER.testtype))
20
+ end
21
+
22
+ def test_type_field
23
+ src = DummySource.new('http://xsource/has_type_test')
24
+ assert_equal(src.type, 'TaliaCore::DummySource')
40
25
  end
41
-
42
26
 
43
27
  def test_exists
44
28
  assert_not_nil(ActiveSource.find(:first))
@@ -237,6 +221,13 @@ module TaliaCore
237
221
  assert_equal(0, active_sources(:predicate_search_b).direct_predicates.size)
238
222
  end
239
223
 
224
+ def test_default_type
225
+ src = ActiveSource.new('http://testy.com/testme/test_default_type')
226
+ src.save!
227
+ assert_equal(1, src.types.size)
228
+ assert_property(src.types, src.rdf_selftype)
229
+ end
230
+
240
231
  def test_types
241
232
  src = ActiveSource.new
242
233
  src.uri = 'http://testy.com/testme/type_test'
@@ -244,7 +235,7 @@ module TaliaCore
244
235
  src.types << N::SourceClass.new(active_sources(:type_a).uri)
245
236
  src.types << N::SourceClass.new(active_sources(:type_b).uri)
246
237
  src.save!
247
- assert_equal(2, src.types.size)
238
+ assert_property(src.types, active_sources(:type_a).uri, active_sources(:type_b).uri, src.rdf_selftype)
248
239
  assert_kind_of(N::SourceClass, src.types[0])
249
240
  assert(src.types.include?(active_sources(:type_b).uri))
250
241
  end
@@ -495,13 +486,13 @@ module TaliaCore
495
486
 
496
487
  def test_rewrite_type
497
488
  src = ActiveSource.new('http://as_test/test_update_rewrite_type')
498
- src.rewrite_attributes!({}) { |src| src.type = 'SingularAccessorTest' }
489
+ src.rewrite_attributes!({}) { |src| src.type = 'TaliaCore::SingularAccessorTest' }
499
490
  assert_kind_of(SingularAccessorTest, ActiveSource.find(src.uri))
500
491
  end
501
492
 
502
493
  def test_rewrite_type
503
494
  src = ActiveSource.new('http://as_test/test_update_type')
504
- src.update_attributes!({}) { |src| src.type = 'SingularAccessorTest' }
495
+ src.update_attributes!({}) { |src| src.type = 'TaliaCore::SingularAccessorTest' }
505
496
  assert_kind_of(SingularAccessorTest, ActiveSource.find(src.uri))
506
497
  end
507
498
 
@@ -531,15 +522,15 @@ module TaliaCore
531
522
  end
532
523
 
533
524
  def test_create_source
534
- src = ActiveSource.create_source(:uri => 'http://as_test/create_with_type', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'SingularAccessorTest')
525
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_with_type', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'TaliaCore::SingularAccessorTest')
535
526
  assert_kind_of(SingularAccessorTest, src)
536
527
  assert_equal('value', src[N::LOCAL.localthi].first)
537
528
  assert_property(src[N::RDF.relatit], N::LOCAL.as_create_attr_dummy_1, N::LOCAL.as_create_attr_dummy_1)
538
- assert_property(src.types, N::TALIA.foo)
529
+ assert_property(src.types, N::TALIA.foo, src.rdf_selftype)
539
530
  end
540
531
 
541
532
  def test_create_for_existing
542
- src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_existing', ':localthi' => 'valueFOOOO', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'SingularAccessorTest')
533
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_existing', ':localthi' => 'valueFOOOO', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'TaliaCore::SingularAccessorTest')
543
534
  src.save!
544
535
  assert_equal('valueFOOOO', src[N::LOCAL.localthi].first)
545
536
  xml = src.to_xml
@@ -550,13 +541,13 @@ module TaliaCore
550
541
  assert_equal(src.uri.to_s, new_src.uri.to_s)
551
542
  assert_equal('valorz', new_src[N::LOCAL.localthi].first)
552
543
  assert_property(new_src[N::RDF.relatit], N::LOCAL.as_create_attr_dummy_1, N::LOCAL.as_create_attr_dummy_1)
553
- assert_property(new_src.types, N::TALIA.foo)
544
+ assert_property(new_src.types, N::TALIA.foo, new_src.rdf_selftype)
554
545
  end
555
546
 
556
547
  def test_create_multi
557
548
  src_attribs = [
558
- { :uri => N::LOCAL.test_create_multi_stuff, 'rdf:relatit' => [ "<#{N::LOCAL.test_create_multi_stuff_two}>" ], 'type' => 'SingularAccessorTest' },
559
- { :uri => N::LOCAL.test_create_multi_stuff_two, ':localthi' => 'valueFOOOO', 'rdf:relatit' => ["<#{N::LOCAL.test_create_multi_stuff}>"], 'type' => 'SingularAccessorTest' }
549
+ { :uri => N::LOCAL.test_create_multi_stuff, 'rdf:relatit' => [ "<#{N::LOCAL.test_create_multi_stuff_two}>" ], 'type' => 'TaliaCore::SingularAccessorTest' },
550
+ { :uri => N::LOCAL.test_create_multi_stuff_two, ':localthi' => 'valueFOOOO', 'rdf:relatit' => ["<#{N::LOCAL.test_create_multi_stuff}>"], 'type' => 'TaliaCore::SingularAccessorTest' }
560
551
  ]
561
552
  ActiveSource.create_multi_from(src_attribs)
562
553
  src = TaliaCore::ActiveSource.find(N::LOCAL.test_create_multi_stuff)
@@ -571,7 +562,7 @@ module TaliaCore
571
562
 
572
563
 
573
564
  def test_xml_forth_and_back
574
- src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_back', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'DummySource')
565
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_back', ':localthi' => 'value', 'rdf:relatit' => ["<:as_create_attr_dummy_1>", "<:as_create_attr_dummy_1>"], 'type' => 'TaliaCore::DummySource')
575
566
  xml = src.to_xml
576
567
  assert_kind_of(TaliaCore::DummySource, src)
577
568
  # Quickly change the URI for the new thing
@@ -583,12 +574,12 @@ module TaliaCore
583
574
  assert_equal('http://as_test/create_forth_and_forth', new_src.uri.to_s)
584
575
  assert_equal('value', new_src[N::LOCAL.localthi].first)
585
576
  assert_property(new_src[N::RDF.relatit], N::LOCAL.as_create_attr_dummy_1, N::LOCAL.as_create_attr_dummy_1)
586
- assert_property(new_src.types, N::TALIA.foo)
577
+ assert_property(new_src.types, N::TALIA.foo, new_src.rdf_selftype)
587
578
  end
588
579
 
589
580
  def test_create_with_file
590
- test_file = File.join(Test::Unit::TestCase.fixture_path, 'generic_test.xml')
591
- src = ActiveSource.create_source(:uri => 'http://as_test/create_forth_and_back', 'type' => 'Source', 'files' => {'url' => test_file })
581
+ test_file = File.join(ActiveSupport::TestCase.fixture_path, 'generic_test.xml')
582
+ src = ActiveSource.create_source(:uri => 'http://as_test/create_with_file', 'type' => 'TaliaCore::Source', 'files' => {'url' => test_file })
592
583
  assert_equal(1, src.data_records.size)
593
584
  src.save!
594
585
  assert(!src.data_records.first.new_record?)
@@ -600,31 +591,46 @@ module TaliaCore
600
591
 
601
592
  # Test if accessing the data on a Source works
602
593
  def test_data_access
603
- data = @data_source.data
594
+ data = make_data_source.data
604
595
  assert_equal(2, data.size)
605
596
  end
606
597
 
607
598
  # Test if accessing the data on a Source works
608
599
  def test_data_access_by_type
609
- data = @data_source.data("SimpleText")
600
+ data = make_data_source.data("TaliaCore::DataTypes::SimpleText")
610
601
  assert_equal(1, data.size)
611
602
  assert_kind_of(DataTypes::SimpleText, data.first)
612
603
  end
613
604
 
614
605
  # Test if accessing the data on a Source works
615
606
  def test_data_access_by_type_and_location
616
- data = @data_source.data("ImageData", "image.jpg")
607
+ data = make_data_source.data("TaliaCore::DataTypes::ImageData", "image.jpg")
617
608
  assert_kind_of(DataTypes::ImageData, data)
618
609
  end
619
610
 
620
611
  # Test accessing inexistent data
621
612
  def test_data_access_inexistent
622
- data = @data_source.data("Foo")
613
+ data_source = make_data_source
614
+ data = data_source.data("Foo")
623
615
  assert_equal(0, data.size)
624
- data = @data_source.data("SimpleText", "noop.txt")
616
+ data = data_source.data("SimpleText", "noop.txt")
625
617
  assert_nil(data)
626
618
  end
627
619
 
620
+ private
621
+
622
+ def make_data_source
623
+ data_source = ActiveSource.new("http://www.test.org/source_with_data")
624
+ text = DataTypes::SimpleText.new
625
+ text.location = "text.txt"
626
+ image = DataTypes::ImageData.new
627
+ image.location = "image.jpg"
628
+ data_source.data_records << text
629
+ data_source.data_records << image
630
+ data_source.save!
631
+ data_source
632
+ end
633
+
628
634
 
629
635
  end
630
636
 
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
3
3
 
4
4
  module TaliaCore
5
5
  # Test the DataRecord storage class
6
- class DataLoaderTest < Test::Unit::TestCase
6
+ class DataLoaderTest < ActiveSupport::TestCase
7
7
 
8
8
  fixtures :active_sources, :data_records
9
9
 
@@ -116,7 +116,7 @@ module TaliaCore
116
116
  private
117
117
 
118
118
  def fixture_file(name)
119
- @fixture_files = File.join(Test::Unit::TestCase.fixture_path, name)
119
+ @fixture_files = File.join(ActiveSupport::TestCase.fixture_path, name)
120
120
  end
121
121
 
122
122
  end
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
3
3
 
4
4
  module TaliaCore
5
5
  # Test the DataRecord storage class
6
- class DataRecordTest < Test::Unit::TestCase
6
+ class DataRecordTest < ActiveSupport::TestCase
7
7
 
8
8
  fixtures :active_sources, :data_records
9
9
 
@@ -1,5 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'fileutils'
3
+ require 'tempfile'
3
4
 
4
5
  # Load the helper class
5
6
  require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
@@ -17,7 +18,7 @@ end
17
18
  module TaliaCore
18
19
 
19
20
  # Test the DataRecord storage class
20
- class FileRecordTest < Test::Unit::TestCase
21
+ class FileRecordTest < ActiveSupport::TestCase
21
22
 
22
23
  fixtures :active_sources, :data_records
23
24
 
@@ -59,7 +60,7 @@ module TaliaCore
59
60
 
60
61
  def test_full_filename
61
62
  data_record = DataTypes::FileRecord.new do |dr|
62
- dr.source_id = 1
63
+ dr.source = active_sources(:something)
63
64
  dr.location = 'image.jpg'
64
65
  dr.assign_type 'image/jpeg'
65
66
  end
@@ -141,7 +142,7 @@ module TaliaCore
141
142
 
142
143
 
143
144
  def source_id
144
- Source.find(:first)[:id]
145
+ active_sources(:something).id
145
146
  end
146
147
 
147
148
  def create_from(expected_content = 'abc')
@@ -7,7 +7,7 @@ module TaliaCore
7
7
  module DataType
8
8
 
9
9
  # Test the DataRecord storage class
10
- class IipDataTest < Test::Unit::TestCase
10
+ class IipDataTest < ActiveSupport::TestCase
11
11
 
12
12
  fixtures :active_sources, :data_records
13
13
 
@@ -105,7 +105,7 @@ module TaliaCore
105
105
  def creation_test
106
106
  new_record = DataTypes::IipData.new
107
107
  new_record.location = ''
108
- new_record.source_id = "something"
108
+ new_record.source = active_sources(:something)
109
109
  yield(new_record)
110
110
  new_record.save!
111
111
 
@@ -6,7 +6,7 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
6
6
  module TaliaCore
7
7
 
8
8
  # Test the DataRecord storage class
9
- class ImageDataTest < Test::Unit::TestCase
9
+ class ImageDataTest < ActiveSupport::TestCase
10
10
 
11
11
  fixtures :active_sources, :data_records
12
12