dbd_data_engine 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -2
  3. data/Guardfile +1 -0
  4. data/HISTORY.txt +7 -0
  5. data/app/assets/stylesheets/dbd_data_engine/application.css +2 -2
  6. data/app/assets/stylesheets/dbd_data_engine/context.css +17 -0
  7. data/app/assets/stylesheets/dbd_data_engine/resource.css +13 -0
  8. data/app/controllers/dbd_data_engine/contexts_controller.rb +3 -1
  9. data/app/controllers/dbd_data_engine/resources_controller.rb +32 -12
  10. data/app/models/dbd_data_engine/context.rb +118 -7
  11. data/app/presenters/context_presenter.rb +18 -0
  12. data/app/presenters/fact_with_context.rb +14 -0
  13. data/app/presenters/resource_with_contexts.rb +14 -0
  14. data/app/views/dbd_data_engine/contexts/_context.html.haml +4 -1
  15. data/app/views/dbd_data_engine/contexts/create.html.haml +3 -1
  16. data/app/views/dbd_data_engine/contexts/index.html.haml +4 -3
  17. data/app/views/dbd_data_engine/contexts/new.html.haml +4 -3
  18. data/app/views/dbd_data_engine/data/index.html.haml +8 -2
  19. data/app/views/dbd_data_engine/resources/_fact_with_context.html.haml +4 -0
  20. data/app/views/dbd_data_engine/resources/_resource_with_contexts.html.haml +3 -0
  21. data/app/views/dbd_data_engine/resources/index.html.haml +4 -3
  22. data/app/views/dbd_data_engine/resources/new.html.haml +3 -0
  23. data/app/views/dbd_data_engine/shared/_links.html.haml +5 -0
  24. data/app/views/layouts/dbd_data_engine/application.html.haml +8 -0
  25. data/dbd_data_engine.gemspec +3 -3
  26. data/lib/dbd_data_engine/version.rb +1 -1
  27. data/spec/controllers/nothing_here_tests_in_features_and_requests +0 -0
  28. data/spec/features/contexts/index_spec.rb +9 -7
  29. data/spec/features/contexts/new_spec.rb +6 -2
  30. data/spec/features/resources/index_spec.rb +8 -7
  31. data/spec/features/resources/new_spec.rb +19 -7
  32. data/spec/models/dbd_data_engine/context/defaults_spec.rb +123 -0
  33. data/spec/models/dbd_data_engine/context/predicates_spec.rb +15 -2
  34. data/spec/presenters/context_presenter/context_summary_spec.rb +20 -0
  35. data/spec/presenters/fact_with_context/new_spec.rb +31 -0
  36. data/spec/presenters/resource_with_contexts/new_spec.rb +32 -0
  37. data/spec/requests/resources/create_spec.rb +26 -36
  38. data/spec/spec_helper.rb +3 -0
  39. data/spec/test_factories/graph.rb +34 -0
  40. data/spec/views/dbd_data_engine/contexts/_context.html.haml_spec.rb +24 -0
  41. data/spec/views/dbd_data_engine/contexts/create.html.haml_spec.rb +11 -3
  42. data/spec/views/dbd_data_engine/contexts/index.html.haml_spec.rb +6 -2
  43. data/spec/views/dbd_data_engine/contexts/new.html.haml_spec.rb +14 -6
  44. data/spec/views/dbd_data_engine/data/index.html.haml_spec.rb +10 -0
  45. data/spec/views/dbd_data_engine/resources/_fact_with_context.html.haml_spec.rb +26 -0
  46. data/spec/views/dbd_data_engine/resources/_resource_with_contexts.html.haml_spec.rb +27 -0
  47. data/spec/views/dbd_data_engine/resources/index.html.haml_spec.rb +13 -3
  48. data/spec/views/dbd_data_engine/resources/new.html.haml_spec.rb +8 -3
  49. metadata +39 -18
  50. data/app/views/dbd_data_engine/resources/_fact.html.haml +0 -3
  51. data/app/views/dbd_data_engine/resources/_resource.html.haml +0 -1
  52. data/app/views/dbd_data_engine/resources/create.html.haml +0 -9
  53. data/app/views/layouts/dbd_data_engine/application.html.erb +0 -12
  54. data/spec/views/dbd_data_engine/resources/create.html.haml_spec.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82f85724f9a57475c424c42dac21fe88581b5bd6
4
- data.tar.gz: d9c19869fa7dcc87a4d0e8c838bd772770109607
3
+ metadata.gz: 197c8d325bba5a9fe3f566a4d7ad4d120b44c5db
4
+ data.tar.gz: 6c17d98cb2ff05c024b000e4a8484dbad82e2cd1
5
5
  SHA512:
6
- metadata.gz: df2e89cf55cd92187eb6fde6e4271eb5b654fbdffcf339aaa97922b202f2b1c3b0c2ca1585edfec549464a6e14447ebbd9758234f468d3dfe16f77f90cfe6efa
7
- data.tar.gz: a9db5852d4904c510126e42a54b6045958aca60353046fc3cac15e59e18ed0bdd9c1a965ca2682968176fb8b79d301c0d134ba9c73495ce52ae03905850b6719
6
+ metadata.gz: 34902f849a16291413b2a7d19e7143e7fa506a5d547777dcfa38795d1b91b1e7d04e2cbb6ce398c98bdb1f03ff2e9bdc1bb12e3106d18a1d871f5fa9fa782d89
7
+ data.tar.gz: b7b77ce9e4e58b3424e8cd0dc831a5d7c8baf5ca877a9b465465ee09a9a075519380939759a243d68fab0151b9ce2fb96e011e61b617141b0087ef646a02775f
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
-
5
- # gem 'dbd', '>= 0.0.18', :path => '../dbd'
data/Guardfile CHANGED
@@ -7,6 +7,7 @@ guard 'rspec', :all_on_start => true, :all_after_pass => true do
7
7
  watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
8
  watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
9
9
  watch(%r{^app/models/(.*)\.rb$}) { |m| "spec/models/#{m[1]}" }
10
+ watch(%r{^app/presenters/(.*)\.rb$}) { |m| "spec/presenters/#{m[1]}" }
10
11
  watch(%r{^app/controllers/dbd_data_engine/(.+)_(controller)\.rb$}) do |m|
11
12
  ["spec/routing/#{m[1]}_routing_spec.rb",
12
13
  "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
data/HISTORY.txt CHANGED
@@ -26,3 +26,10 @@
26
26
  * add a naive DbdDataEngine::Context model
27
27
  * add a naive ContextsController
28
28
  * it takes the predicates for the "new" screen from DbdOnto::Context
29
+
30
+ 0.0.6 (2013-10-25)
31
+ =====
32
+
33
+ * upgrade to dbd 0.1.0
34
+ * stylsheets
35
+ * default contexts ("public today" etc.)
@@ -1,5 +1,5 @@
1
1
  /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
2
+ * This is a manifest file that will be compiled into application.css, which will include all the files
3
3
  * listed below.
4
4
  *
5
5
  * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
@@ -9,5 +9,5 @@
9
9
  * compiled file, but it's generally better to create a new file per style scope.
10
10
  *
11
11
  *= require_self
12
- *= require_tree .
12
+ *= require_tree '../dbd_data_engine'
13
13
  */
@@ -0,0 +1,17 @@
1
+ .context table {
2
+ margin-top: 5px;
3
+ margin-bottom: 15px;
4
+ margin-left: 5px;
5
+ border: 1px solid darkgray;
6
+ color: darkblue;
7
+ border-collapse:collapse;
8
+ }
9
+
10
+ .context td {
11
+ padding: 3px;
12
+ border: 1px dotted darkgray;
13
+ }
14
+
15
+ .context_color{
16
+ color: darkblue;
17
+ }
@@ -0,0 +1,13 @@
1
+ .resource table {
2
+ margin-top: 5px;
3
+ margin-bottom: 15px;
4
+ margin-left: 5px;
5
+ border: 1px solid darkgray;
6
+ color: darkgreen;
7
+ border-collapse:collapse;
8
+ }
9
+
10
+ .resource td {
11
+ padding: 3px;
12
+ border: 1px dotted darkgray;
13
+ }
@@ -5,7 +5,7 @@ module DbdDataEngine
5
5
  def index
6
6
  graph = Dbd::Graph.new
7
7
  graph = graph.from_unsorted_CSV_file(filename)
8
- @contexts = graph.subjects.map{ |s| graph.by_subject(s) }
8
+ @contexts = graph.contexts
9
9
  end
10
10
 
11
11
  def new
@@ -17,10 +17,12 @@ module DbdDataEngine
17
17
  @context = Dbd::Context.new()
18
18
  [params[:predicate], params[:object]].transpose.each do |predicate, object|
19
19
  context_fact = Dbd::ContextFact.new(predicate: predicate,
20
+ object_type: 's',
20
21
  object: object)
21
22
  @context << context_fact
22
23
  end
23
24
  graph << @context
25
+ # TODO move this to graph
24
26
  new_data = graph.to_CSV
25
27
  File.open(filename, 'a') do |f|
26
28
  f.syswrite new_data
@@ -1,30 +1,39 @@
1
- require_dependency "dbd_data_engine/application_controller"
1
+ require_dependency 'dbd_data_engine/application_controller'
2
2
 
3
3
  module DbdDataEngine
4
4
  class ResourcesController < ApplicationController
5
+
5
6
  def index
6
- graph = Dbd::Graph.new
7
- graph = graph.from_unsorted_CSV_file(filename)
8
- @resources = graph.subjects.map{ |s| graph.by_subject(s) }
7
+ @resources_with_contexts = resources_with_contexts(current_graph)
9
8
  end
10
9
 
11
10
  def new
11
+ @contexts = ['public today', 'personal today', 'business today']
12
12
  @predicates = ['schema:givenName','schema:familyName']
13
13
  end
14
14
 
15
15
  def create
16
- graph = Dbd::Graph.new
17
- @resource = Dbd::Resource.new(context_subject: Dbd::Context.new_subject)
16
+ # FIXME refactor to smaller function (green first, refactor next)
17
+ @context = Context.default_from_params(params[:context], current_graph)
18
+ @resource = Dbd::Resource.new(context_subject: @context.subject)
18
19
  [params[:predicate], params[:object]].transpose.each do |predicate, object|
19
- fact = Dbd::Fact.new(predicate: predicate,
20
- object: object)
21
- @resource << fact
20
+ @resource << Dbd::Fact.new(
21
+ predicate: predicate,
22
+ object_type: 's',
23
+ object: object)
22
24
  end
23
- graph << @resource
24
- new_data = graph.to_CSV
25
+
26
+ # prepare the graph to append
27
+ append_graph = Dbd::Graph.new
28
+ append_graph << @context unless @context.first.time_stamp # only if not yet persisted?
29
+ append_graph << @resource
30
+ # TODO this can probably move to Dbd::Graph#append_to_file(filename)
31
+ append_csv = append_graph.to_CSV
25
32
  File.open(filename, 'a') do |f|
26
- f.syswrite new_data
33
+ f.syswrite append_csv
27
34
  end
35
+
36
+ redirect_to('/data/resources')
28
37
  end
29
38
 
30
39
  private
@@ -33,5 +42,16 @@ module DbdDataEngine
33
42
  DbdDataEngine.default_CSV_location
34
43
  end
35
44
 
45
+ def current_graph
46
+ Dbd::Graph.new.from_unsorted_CSV_file(filename)
47
+ end
48
+
49
+ def resources_with_contexts(graph)
50
+ graph.resources.map do |resource|
51
+ ResourceWithContexts.new(
52
+ resource: resource,
53
+ graph: graph)
54
+ end
55
+ end
36
56
  end
37
57
  end
@@ -1,13 +1,124 @@
1
1
  module DbdDataEngine
2
2
  class Context
3
+
3
4
  def self.predicates
4
- ::DbdOnto::Context.new.
5
- select do |fact|
6
- fact.predicate == 'meta:defines_predicate'
7
- end.
8
- map do |fact|
9
- fact.object
5
+ resources = ::DbdOnto::Context.new.resources
6
+ predicate_defining_resources = select_with_defines_predicate(resources)
7
+ make_predicate_label_hash(predicate_defining_resources)
8
+ end
9
+
10
+ def self.public_today
11
+ context_from_context_facts(public_today_context_facts)
12
+ end
13
+
14
+ def self.personal_today
15
+ context_from_context_facts(personal_today_context_facts)
16
+ end
17
+
18
+ def self.business_today
19
+ context_from_context_facts(business_today_context_facts)
20
+ end
21
+
22
+ def self.default_from_params(context_param, current_graph)
23
+ find_context(context_param, current_graph) || create_context(context_param)
24
+ end
25
+
26
+ private
27
+
28
+ def self.find_context(context_param, current_graph)
29
+ if current_graph
30
+ # the first occurrence is OK (no drama if multiple)
31
+ current_graph.contexts.detect do |context|
32
+ (cv = single_fact_on_predicate(context, 'context:visibility')) &&
33
+ cv.object == visibility(context_param) &&
34
+ (dc = single_fact_on_predicate(context, 'dcterms:created')) &&
35
+ dc.object == today.to_s
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.create_context(context_param)
41
+ case context_param
42
+ when 'public today'
43
+ public_today
44
+ when 'personal today'
45
+ personal_today
46
+ when 'business today'
47
+ business_today
48
+ else
49
+ raise "A valid context must be given (was given: #{context_param})"
50
+ end
51
+ end
52
+
53
+ def self.visibility(context_param)
54
+ context_param.split(/ /).first
55
+ end
56
+
57
+ def self.today
58
+ Date.today
59
+ end
60
+
61
+ def self.context_from_context_facts(context_fact_array)
62
+ Dbd::Context.new.tap do |context|
63
+ context_fact_array.each do |predicate, object_type, object| # splat
64
+ context << Dbd::ContextFact.new(
65
+ predicate: predicate,
66
+ object_type: object_type,
67
+ object: object)
10
68
  end
69
+ end
70
+ end
71
+
72
+ def self.public_today_context_facts
73
+ [['context:visibility','s','public'],
74
+ ['context:encryption','s','clear'],
75
+ ['context:license','s',"CC BY, Copyright #{today.year} Peter Vandenabeele"]] +
76
+ common_today_context_facts
77
+ end
78
+
79
+ def self.personal_today_context_facts
80
+ [['context:visibility','s','personal']] +
81
+ encrypted_and_rights_reserved_and_common
82
+ end
83
+
84
+ def self.business_today_context_facts
85
+ [['context:visibility','s','business']] +
86
+ encrypted_and_rights_reserved_and_common
87
+ end
88
+
89
+ def self.encrypted_and_rights_reserved_and_common
90
+ [['context:encryption','s','encrypted'],
91
+ ['context:license','s',"All rights reserved, Copyright #{today.year} Peter Vandenabeele"]] +
92
+ common_today_context_facts
93
+ end
94
+
95
+ def self.common_today_context_facts
96
+ [['dc:source','s','manual by Peter Vandenabeele'],
97
+ ['dc:creator','s','Peter Vandenabeele'],
98
+ ['dcterms:created','s',today.to_s]]
99
+ end
100
+
101
+ # TODO implement some of these methods on Dbd gem to clean-up
102
+
103
+ def self.select_with_defines_predicate(resources)
104
+ resources.select do |resource|
105
+ single_fact_on_predicate(resource, 'meta:defines_predicate')
106
+ end
107
+ end
108
+
109
+ def self.make_predicate_label_hash(resources)
110
+ resources.map do |resource|
111
+ predicate = single_fact_on_predicate(resource, 'meta:defines_predicate').object
112
+ label = single_fact_on_predicate(resource, 'rdfs:label').object
113
+ { predicate: predicate,
114
+ label: label }
115
+ end
116
+ end
117
+
118
+ def self.single_fact_on_predicate(resource, predicate)
119
+ resource.select do |fact|
120
+ fact.predicate == predicate
121
+ end.single
11
122
  end
12
123
  end
13
- end
124
+ end
@@ -0,0 +1,18 @@
1
+ class ContextPresenter
2
+ def initialize(options)
3
+ @context = options.fetch(:context)
4
+ end
5
+
6
+ def context_summary
7
+ visibility = get_objects_for_predicate(@context, 'context:visibility')
8
+ created = get_objects_for_predicate(@context, 'dcterms:created')
9
+ "#{visibility.join(', ')} #{created.join(', ')}"
10
+ end
11
+
12
+ private
13
+
14
+ def get_objects_for_predicate(context, predicate)
15
+ context.select{ |cf| cf.predicate == predicate }.map(&:object)
16
+ end
17
+
18
+ end
@@ -0,0 +1,14 @@
1
+ class FactWithContext
2
+ attr_reader :fact
3
+
4
+ def initialize(options)
5
+ @fact = options.fetch(:fact)
6
+ @graph = options.fetch(:graph)
7
+ end
8
+
9
+ def context_summary
10
+ context = @graph.by_subject(@fact.context_subject)
11
+ ContextPresenter.new(context: context).context_summary
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ class ResourceWithContexts
2
+ include Enumerable
3
+
4
+ def initialize(options)
5
+ @resource = options.fetch(:resource)
6
+ @graph = options.fetch(:graph)
7
+ end
8
+
9
+ def each
10
+ @resource.each do |fact|
11
+ yield FactWithContext.new(fact: fact, graph: @graph)
12
+ end
13
+ end
14
+ end
@@ -1 +1,4 @@
1
- %table= render partial: 'context_fact', collection: context
1
+ %div.context
2
+ %h3= ContextPresenter.new(context: context).context_summary
3
+ %table
4
+ = render partial: 'dbd_data_engine/contexts/context_fact', collection: context.to_a
@@ -1,9 +1,11 @@
1
1
  %h2 New context was created
2
2
 
3
+ =render partial: 'dbd_data_engine/shared/links'
4
+
3
5
  %p content is:
4
6
  %table
5
7
  %tr
6
8
  %th predicate
7
9
  %th object
8
- =render :partial => 'context_fact', collection: @context.to_a
10
+ =render partial: 'context', object: @context.to_a
9
11
 
@@ -1,4 +1,5 @@
1
- %h1 Contexts#index
1
+ %h1 Contexts
2
2
 
3
- - @contexts.each do |context|
4
- = render partial: 'context', object: context
3
+ = render partial: 'dbd_data_engine/shared/links'
4
+
5
+ = render partial: 'context', collection: @contexts
@@ -3,11 +3,12 @@
3
3
  = form_tag('/data/contexts', method: :post) do # engine controller route not loaded in view tests
4
4
  %table
5
5
  %tr
6
- %th predicate
7
- %th object
6
+ %th Predicate
7
+ %th Object
8
8
  - @predicates.each do |predicate|
9
9
  %tr
10
- %td= text_field_tag('predicate[]', predicate)
10
+ %td= label_tag("#{predicate[:label]} (#{predicate[:predicate]})")
11
11
  %td= text_field_tag('object[]')
12
+ %td= text_field_tag('predicate[]', predicate[:predicate], hidden: true)
12
13
 
13
14
  %p= submit_tag('Submit')
@@ -1,2 +1,8 @@
1
- %h1 Data#index
2
- %p Find me in app/views/dbd_data_engine/data/index.html.haml
1
+ %h1 Data
2
+
3
+ = render partial: 'dbd_data_engine/shared/links'
4
+
5
+ %h2 See and create #{link_to('contexts','/data/contexts')}
6
+ %h2 See and create #{link_to('resources','/data/resources')}
7
+
8
+
@@ -0,0 +1,4 @@
1
+ %tr
2
+ %td= fact_with_context.fact.predicate
3
+ %td= fact_with_context.fact.object
4
+ %td.context_color= fact_with_context.context_summary
@@ -0,0 +1,3 @@
1
+ %div.resource
2
+ %table
3
+ = render partial: 'fact_with_context', collection: resource_with_contexts.to_a
@@ -1,4 +1,5 @@
1
- %h1 Resources#index
1
+ %h1 Resources
2
2
 
3
- - @resources.each do |resource|
4
- = render partial: 'resource', object: resource
3
+ = render partial: 'dbd_data_engine/shared/links'
4
+
5
+ = render partial: 'resource_with_contexts', collection: @resources_with_contexts
@@ -1,6 +1,9 @@
1
1
  %h1 Create a new resource
2
2
 
3
3
  = form_tag('/data/resources', method: :post) do # engine controller route not loaded in view tests
4
+ %p
5
+ =label_tag('Context')
6
+ =select_tag('context', options_for_select(@contexts)) #@contexts))
4
7
  %table
5
8
  %tr
6
9
  %th predicate
@@ -0,0 +1,5 @@
1
+ %p
2
+ =link_to 'resources', '/data/resources'
3
+ =link_to 'contexts', '/data/contexts'
4
+ =link_to 'new resource', '/data/resources/new'
5
+ =link_to 'new context', '/data/contexts/new'
@@ -0,0 +1,8 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title DbdDataEngine
5
+ = stylesheet_link_tag 'dbd_data_engine/application'
6
+ = csrf_meta_tags
7
+ %body
8
+ = yield
@@ -21,10 +21,10 @@ Gem::Specification.new do |s|
21
21
  s.require_paths = ['lib']
22
22
 
23
23
  s.add_development_dependency 'rake'
24
- s.add_dependency 'rails', '>= 4.0.0'
24
+ s.add_dependency 'rails', '>= 4.0.1.rc3'
25
25
  s.add_dependency 'haml'
26
- s.add_dependency 'dbd', '>= 0.0.18'
27
- s.add_dependency 'dbd_onto'
26
+ s.add_dependency 'dbd', '~> 0.1.0'
27
+ s.add_dependency 'dbd_onto', '~> 0.0.12'
28
28
 
29
29
  s.add_development_dependency 'haml-rails'
30
30
  s.add_development_dependency 'rspec-rails'
@@ -1,3 +1,3 @@
1
1
  module DbdDataEngine
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -13,11 +13,8 @@ module DbdDataEngine
13
13
  ::RSpec::Mocks.setup(self)
14
14
 
15
15
  before(:each) do
16
- graph = Dbd::Graph.new
17
- graph << Dbd::ContextFact.new(subject: Dbd::Fact.factory.new_subject,
18
- predicate: 'foobar',
19
- object: 'tuxping')
20
- Dbd::Graph.any_instance.stub(:from_unsorted_CSV_file).and_return(graph)
16
+ Dbd::Graph.any_instance.stub(:from_unsorted_CSV_file).
17
+ and_return(TestFactories::Graph.full)
21
18
  end
22
19
 
23
20
  context 'page content' do
@@ -31,8 +28,13 @@ module DbdDataEngine
31
28
  end
32
29
 
33
30
  it 'shows a test context' do
34
- expect(page).to have_text('foobar')
35
- expect(page).to have_text('tuxping')
31
+ expect(page).to have_text('context:visibility')
32
+ expect(page).to have_text('public')
33
+ end
34
+
35
+ it 'does not show Facts (only Contexts)' do
36
+ expect(page).to_not have_text('fact_predicate')
37
+ expect(page).to_not have_text('whooha')
36
38
  end
37
39
  end
38
40
  end
@@ -19,11 +19,15 @@ module DbdDataEngine
19
19
  expect(page.text).to match(/new context/i)
20
20
  end
21
21
 
22
- it 'has a label array with context:visibility as value' do
22
+ it 'has a field array with predicates' do
23
23
  expect(page).to have_field('predicate[]', type: 'text', count: 6)
24
24
  end
25
25
 
26
- it 'has a field array' do
26
+ it 'has a field array with predicate context:visibility' do
27
+ expect(page).to have_field('predicate[]', type: 'text', with: 'context:visibility')
28
+ end
29
+
30
+ it 'has a field array with objects' do
27
31
  expect(page).to have_field('object[]', count: 6)
28
32
  end
29
33
  end
@@ -13,11 +13,8 @@ module DbdDataEngine
13
13
  ::RSpec::Mocks.setup(self)
14
14
 
15
15
  before(:each) do
16
- graph = Dbd::Graph.new
17
- graph << Dbd::ContextFact.new(subject: Dbd::Fact.factory.new_subject,
18
- predicate: 'foobar',
19
- object: 'tuxping')
20
- Dbd::Graph.any_instance.stub(:from_unsorted_CSV_file).and_return(graph)
16
+ Dbd::Graph.any_instance.stub(:from_unsorted_CSV_file).
17
+ and_return(TestFactories::Graph.full)
21
18
  end
22
19
 
23
20
  context 'page content' do
@@ -30,9 +27,13 @@ module DbdDataEngine
30
27
  expect(page).to have_text('Resources')
31
28
  end
32
29
 
30
+ it 'does not show Contexts (only Facts)' do
31
+ expect(page).to_not have_text('context:visibility')
32
+ end
33
+
33
34
  it 'shows a test resource' do
34
- expect(page).to have_text('foobar')
35
- expect(page).to have_text('tuxping')
35
+ expect(page).to have_text('fact_predicate')
36
+ expect(page).to have_text('whooha')
36
37
  end
37
38
  end
38
39
  end
@@ -15,16 +15,28 @@ module DbdDataEngine
15
15
  visit(dbd_data_engine.new_resource_path)
16
16
  end
17
17
 
18
- it 'talks about a new resource' do
19
- expect(page.text).to match(/new resource/i)
20
- end
18
+ context 'resource' do
19
+ it 'talks about a new resource' do
20
+ expect(page).to have_css('h1', text: 'Create a new resource')
21
+ end
22
+
23
+ it 'has a select box array with schema:givenName as option' do
24
+ expect(page).to have_select('predicate[]', options: ['schema:givenName','schema:familyName'])
25
+ end
21
26
 
22
- it 'has a select box array with schema:givenName as option' do
23
- expect(page).to have_select('predicate[]', options: ['schema:givenName','schema:familyName'])
27
+ it 'has a field array' do
28
+ expect(page).to have_field('object[]')
29
+ end
24
30
  end
25
31
 
26
- it 'has a field array' do
27
- expect(page).to have_field('object[]')
32
+ context 'select a context' do
33
+ it 'has a label "context"' do
34
+ expect(page).to have_css('label', text: 'Context')
35
+ end
36
+
37
+ it 'has a select box for the context' do
38
+ expect(page).to have_select('context', [])
39
+ end
28
40
  end
29
41
  end
30
42
  end