rivendell-import 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -9,5 +9,4 @@ gem 'capistrano'
9
9
 
10
10
  if RUBY_PLATFORM =~ /linux/
11
11
  gem 'libnotify'
12
- gem 'rb-inotify'
13
12
  end
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rivendell-import (0.6)
4
+ rivendell-import (0.7)
5
5
  SyslogLogger (~> 2.0)
6
6
  activerecord (~> 3.2.8)
7
7
  activesupport (~> 3.2.8)
8
8
  daemons
9
9
  httmultiparty
10
10
  httparty (= 0.11.0)
11
- listen (~> 1.2.1)
11
+ listen (~> 1.3.1)
12
12
  mail
13
13
  rivendell-api (~> 0.0.5)
14
- rivendell-db
14
+ rivendell-db (~> 0.2)
15
15
  sinatra
16
16
  sqlite3
17
17
  trollop
@@ -21,20 +21,20 @@ GEM
21
21
  remote: https://rubygems.org/
22
22
  specs:
23
23
  SyslogLogger (2.0)
24
- activemodel (3.2.14)
25
- activesupport (= 3.2.14)
24
+ activemodel (3.2.16)
25
+ activesupport (= 3.2.16)
26
26
  builder (~> 3.0.0)
27
- activerecord (3.2.14)
28
- activemodel (= 3.2.14)
29
- activesupport (= 3.2.14)
27
+ activerecord (3.2.16)
28
+ activemodel (= 3.2.16)
29
+ activesupport (= 3.2.16)
30
30
  arel (~> 3.0.2)
31
31
  tzinfo (~> 0.3.29)
32
- activesupport (3.2.14)
32
+ activesupport (3.2.16)
33
33
  i18n (~> 0.6, >= 0.6.4)
34
34
  multi_json (~> 1.0)
35
35
  addressable (2.3.5)
36
- arel (3.0.2)
37
- bcrypt-ruby (3.0.1)
36
+ arel (3.0.3)
37
+ bcrypt-ruby (3.1.2)
38
38
  builder (3.0.3)
39
39
  capistrano (2.14.2)
40
40
  highline
@@ -79,7 +79,7 @@ GEM
79
79
  do_mysql (0.10.13)
80
80
  data_objects (= 0.10.13)
81
81
  fastercsv (1.5.5)
82
- ffi (1.9.0)
82
+ ffi (1.9.3)
83
83
  gherkin (2.11.2)
84
84
  json (>= 1.4.6)
85
85
  guard (1.4.0)
@@ -98,20 +98,20 @@ GEM
98
98
  httparty (0.11.0)
99
99
  multi_json (~> 1.0)
100
100
  multi_xml (>= 0.5.2)
101
- i18n (0.6.5)
102
- json (1.7.5)
103
- json_pure (1.8.0)
104
- libnotify (0.8.0)
101
+ i18n (0.6.9)
102
+ json (1.8.1)
103
+ json_pure (1.8.1)
104
+ libnotify (0.8.2)
105
105
  ffi (>= 1.0.11)
106
- listen (1.2.2)
106
+ listen (1.3.1)
107
107
  rb-fsevent (>= 0.9.3)
108
108
  rb-inotify (>= 0.9)
109
109
  rb-kqueue (>= 0.2)
110
110
  mail (2.5.4)
111
111
  mime-types (~> 1.16)
112
112
  treetop (~> 1.4.8)
113
- mime-types (1.25)
114
- multi_json (1.7.7)
113
+ mime-types (1.25.1)
114
+ multi_json (1.8.2)
115
115
  multi_xml (0.5.5)
116
116
  multipart-post (1.2.0)
117
117
  net-scp (1.1.0)
@@ -124,19 +124,21 @@ GEM
124
124
  null_logger (0.0.1)
125
125
  polyglot (0.3.3)
126
126
  rack (1.5.2)
127
- rack-protection (1.5.0)
127
+ rack-protection (1.5.1)
128
128
  rack
129
129
  rake (0.9.2.2)
130
130
  rb-fsevent (0.9.3)
131
- rb-inotify (0.9.0)
131
+ rb-inotify (0.9.2)
132
132
  ffi (>= 0.5.0)
133
133
  rb-kqueue (0.2.0)
134
134
  ffi (>= 0.5.0)
135
+ rdoc (3.12.2)
136
+ json (~> 1.4)
135
137
  rivendell-api (0.0.5)
136
138
  activesupport
137
139
  httmultiparty
138
140
  null_logger
139
- rivendell-db (0.0.1)
141
+ rivendell-db (0.2)
140
142
  dm-core
141
143
  dm-mysql-adapter
142
144
  dm-serializer
@@ -154,7 +156,7 @@ GEM
154
156
  multi_json (~> 1.0)
155
157
  simplecov-html (~> 0.5.3)
156
158
  simplecov-html (0.5.3)
157
- sinatra (1.4.3)
159
+ sinatra (1.4.4)
158
160
  rack (~> 1.4)
159
161
  rack-protection (~> 1.4)
160
162
  tilt (~> 1.3, >= 1.3.4)
@@ -166,9 +168,9 @@ GEM
166
168
  polyglot
167
169
  polyglot (>= 0.3.1)
168
170
  trollop (2.0)
169
- tzinfo (0.3.37)
171
+ tzinfo (0.3.38)
170
172
  uuidtools (2.1.4)
171
- will_paginate (3.0.4)
173
+ will_paginate (3.0.5)
172
174
 
173
175
  PLATFORMS
174
176
  ruby
@@ -182,7 +184,7 @@ DEPENDENCIES
182
184
  guard-rspec
183
185
  libnotify
184
186
  rake
185
- rb-inotify
187
+ rdoc
186
188
  rivendell-import!
187
189
  rspec
188
190
  simplecov
@@ -12,6 +12,8 @@ Mail.defaults do
12
12
  delivery_method :smtp, { :address => "smtp.free.fr" }
13
13
  end
14
14
 
15
+ # Rivendell::API::Xport.debug_output $stdout
16
+
15
17
  Rivendell::Import::Notifier::Mail.from = "root@tryphon.eu"
16
18
 
17
19
  Rivendell::Import.config do |config|
@@ -19,6 +21,8 @@ Rivendell::Import.config do |config|
19
21
  config.rivendell.login_name = "user"
20
22
  config.rivendell.password = ""
21
23
 
24
+ config.rivendell.db_url = 'mysql://rduser:letmein@localhost/Rivendell'
25
+
22
26
  config.to_prepare do |file|
23
27
  cart.default_title = file.basename
24
28
 
@@ -27,8 +31,14 @@ Rivendell::Import.config do |config|
27
31
  end
28
32
 
29
33
  file.in("pad") do
34
+ name = file.basename
35
+ if name.match /-lundi$/
36
+ cart.cut.days = %w{mon}
37
+ name.gsub! /-lundi$/, ""
38
+ end
39
+
30
40
  cart.clear_cuts!
31
- cart.find_by_title file.basename
41
+ cart.find_by_title name
32
42
  end
33
43
 
34
44
  cart.group ||= "TEST"
@@ -40,6 +40,7 @@ require "rivendell/import/worker"
40
40
  require "rivendell/import/task"
41
41
  require "rivendell/import/tasks"
42
42
  require "rivendell/import/base"
43
+ require "rivendell/import/database"
43
44
  require "rivendell/import/cart_finder"
44
45
  require "rivendell/import/cart"
45
46
  require "rivendell/import/context"
@@ -22,17 +22,16 @@ module Rivendell::Import
22
22
  workers << Worker.new(self).start unless options[:dry_run]
23
23
 
24
24
  Rivendell::Import.logger.info "Listen files in #{directory}"
25
-
26
25
  callback = Proc.new do |modified, added, removed|
27
26
  # Rivendell::Import.logger.debug [modified, added, removed].inspect
28
- begin
29
- added.each do |file|
27
+ added.each do |file|
28
+ begin
30
29
  Rivendell::Import.logger.debug "Detected file '#{file}'"
31
30
  file(file, directory)
31
+ rescue Exception => e
32
+ Rivendell::Import.logger.error "Task creation failed : #{e}"
33
+ Rivendell::Import.logger.debug e.backtrace.join("\n")
32
34
  end
33
- rescue Exception => e
34
- Rivendell::Import.logger.error "Task creation failed : #{e}"
35
- Rivendell::Import.logger.debug e.backtrace.join("\n")
36
35
  end
37
36
  end
38
37
 
@@ -4,16 +4,30 @@ module Rivendell::Import
4
4
  include ActiveModel::Serialization
5
5
  include ActiveModel::Serializers::JSON
6
6
 
7
+ def as_json(options = {})
8
+ super options.merge(:root => false)
9
+ end
10
+
7
11
  def attributes
8
- %w{number group clear_cuts? title default_title}.inject({}) do |map, attribute|
12
+ attributes = {}
13
+ %w{number group clear_cuts title default_title import_options}.each do |attribute|
9
14
  value = send attribute
10
- map[attribute] = value if value
11
- map
15
+ attributes[attribute] = value if value.present?
16
+ end
17
+ if (cut_attributes = cut.attributes).present?
18
+ attributes["cut"] = cut_attributes
12
19
  end
20
+ attributes
13
21
  end
14
22
 
15
23
  def attributes=(attributes)
16
- attributes.each { |k,v| send "#{k}=", v }
24
+ attributes.each do |k,v|
25
+ unless k == "cut"
26
+ send "#{k}=", v
27
+ else
28
+ cut.attributes = v
29
+ end
30
+ end
17
31
  end
18
32
 
19
33
  delegate :blank?, :to => :attributes
@@ -53,18 +67,31 @@ module Rivendell::Import
53
67
  @cut ||= Cut.new(self)
54
68
  end
55
69
 
70
+ attr_accessor :import_options
71
+ def import_options
72
+ @import_options ||= {}
73
+ end
74
+
56
75
  def import(file)
57
76
  raise "File #{file.path} not found" unless file.exists?
58
77
 
78
+ if clear_cuts?
79
+ Rivendell::Import.logger.debug "Clear cuts of Cart #{number}"
80
+ xport.clear_cuts number
81
+ end
59
82
  cut.create
60
- xport.clear_cuts number if clear_cuts?
61
- xport.import number, cut.number, file.path
83
+
84
+ Rivendell::Import.logger.debug "Import #{file.path} in Cut #{cut.number}"
85
+ xport.import number, cut.number, file.path, import_options
62
86
  cut.update
63
87
  end
64
88
 
65
89
  def find_by_title(string, options = {})
90
+ Rivendell::Import.logger.debug "Looking for a Cart '#{string}'"
66
91
  if remote_cart = cart_finder.find_by_title(string, options)
92
+ Rivendell::Import.logger.debug "Found Cart #{remote_cart.number}"
67
93
  self.number = remote_cart.number
94
+ self.import_options[:use_metadata] = false
68
95
  end
69
96
  end
70
97
 
@@ -75,18 +102,12 @@ module Rivendell::Import
75
102
  self.clear_cuts = true
76
103
  end
77
104
 
78
- @db_url = nil
79
- cattr_accessor :db_url
80
-
81
105
  def cart_finder
82
106
  @cart_finder ||=
83
- begin
84
- unless db_url
85
- Rivendell::Import::CartFinder::ByApi.new xport
86
- else
87
- Rivendell::DB.establish_connection(db_url)
88
- Rivendell::Import::CartFinder::ByDb.new
89
- end
107
+ unless Database.enabled?
108
+ Rivendell::Import::CartFinder::ByApi.new xport
109
+ else
110
+ Rivendell::Import::CartFinder::ByDb.new
90
111
  end
91
112
  end
92
113
 
@@ -1,18 +1,20 @@
1
1
  # Find Carts using a direct database access.
2
- #
2
+ #
3
3
  # Provided to workaround actual accent problems experienced with Rivendell API.
4
4
  module Rivendell::Import
5
5
  class CartFinder::ByDb < CartFinder
6
-
6
+
7
7
  def carts(options = {})
8
+ Database.init
9
+
8
10
  query_options = { :fields => [ :number, :title ] }
9
-
10
- if options[:group]
11
- query_options[:group_name] = options[:group]
11
+
12
+ if options[:group]
13
+ query_options[:group_name] = options[:group]
12
14
  end
13
15
 
14
16
  Rivendell::DB::Cart.all(query_options)
15
17
  end
16
-
18
+
17
19
  end
18
20
  end
@@ -126,12 +126,15 @@ module Rivendell::Import
126
126
  end
127
127
 
128
128
  config_loader.load
129
+
129
130
  daemonize
130
131
 
131
132
  config_loader.listen_file
133
+ sleep 1
132
134
 
133
135
  if listen_mode?
134
136
  start_webserver
137
+ sleep 1
135
138
 
136
139
  listen_options = {}
137
140
  listen_options[:dry_run] = true if dry_run?
@@ -25,6 +25,10 @@ module Rivendell::Import
25
25
  Task.default_xport_options[:password] = password
26
26
  end
27
27
 
28
+ def db_url=(url)
29
+ Database.url = url
30
+ end
31
+
28
32
  end
29
33
 
30
34
  end
@@ -7,13 +7,28 @@ module Rivendell::Import
7
7
  attr_reader :cart
8
8
 
9
9
  attr_accessor :number
10
+ attr_accessor :datetime
11
+ attr_accessor :daypart
12
+ attr_accessor :days
10
13
 
11
14
  def initialize(cart)
12
15
  @cart = cart
13
16
  end
14
17
 
18
+ def as_json(options = {})
19
+ super options.merge(:root => false)
20
+ end
21
+
15
22
  def attributes
16
- {}
23
+ %w{datetime daypart days}.inject({}) do |map, attribute|
24
+ value = send attribute
25
+ map[attribute] = value if value
26
+ map
27
+ end
28
+ end
29
+
30
+ def attributes=(attributes)
31
+ attributes.each { |k,v| send "#{k}=", v }
17
32
  end
18
33
 
19
34
  def xport
@@ -21,12 +36,38 @@ module Rivendell::Import
21
36
  end
22
37
 
23
38
  def create
24
- # xport.delete_cuts # if clean cuts is required
39
+ Rivendell::Import.logger.debug "Create Cut for Cart #{cart.number}"
25
40
  self.number = xport.add_cut(cart.number).number unless number
26
41
  end
27
42
 
43
+ def name
44
+ "%06d_%03d" % [cart.number, number]
45
+ end
46
+
47
+ def db_attributes?
48
+ [datetime, daypart, days].any? &:present?
49
+ end
50
+
28
51
  def update
29
- # xport.edit_cut # to define attributes
52
+ if db_attributes?
53
+ Rivendell::Import.logger.debug "Save Cut db attributes #{inspect}"
54
+ Database.init
55
+
56
+ db_cut = Rivendell::DB::Cut.get(name)
57
+ if datetime
58
+ db_cut.start_datetime, db_cut.end_datetime = datetime.begin, datetime.end
59
+ end
60
+ if daypart
61
+ db_cut.start_daypart, db_cut.end_daypart = daypart.begin, daypart.end
62
+ end
63
+ if days
64
+ db_cut.days = days
65
+ end
66
+
67
+ Rivendell::Import.logger.debug "Change Cut #{number} in DB #{db_cut.inspect}"
68
+
69
+ db_cut.save
70
+ end
30
71
  end
31
72
 
32
73
  end
@@ -0,0 +1,21 @@
1
+ module Rivendell::Import
2
+ module Database
3
+
4
+ mattr_accessor :url
5
+
6
+ def self.enabled?
7
+ url.present?
8
+ end
9
+
10
+ @@initialized = false
11
+ def self.init
12
+ raise "Database not enabled (no config.rivendell.db_url defined)" unless enabled?
13
+
14
+ unless @@initialized
15
+ Rivendell::DB.establish_connection(url)
16
+ @@initialized = true
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -7,7 +7,7 @@ module Rivendell::Import::Tasking
7
7
 
8
8
  def cart
9
9
  @cast ||= Rivendell::Import::Cart.new(self).tap do |cart|
10
- cart.from_json raw_cart if raw_cart
10
+ cart.from_json(raw_cart, false) if raw_cart
11
11
  end
12
12
  end
13
13
 
@@ -1,5 +1,5 @@
1
1
  module Rivendell
2
2
  module Import
3
- VERSION = "0.6"
3
+ VERSION = "0.7"
4
4
  end
5
5
  end
@@ -15,7 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Rivendell::Import::VERSION
17
17
 
18
- gem.add_runtime_dependency 'listen', '~> 1.2.1'
18
+ # 2.0 requires ruby 1.9.3
19
+ gem.add_runtime_dependency 'listen', '~> 1.3.1'
19
20
  gem.add_runtime_dependency 'httmultiparty'
20
21
  # 0.12.0 requires ruby 1.9.3
21
22
  gem.add_runtime_dependency 'httparty', '0.11.0'
@@ -32,7 +33,7 @@ Gem::Specification.new do |gem|
32
33
 
33
34
  gem.add_runtime_dependency 'daemons'
34
35
 
35
- gem.add_runtime_dependency 'rivendell-db'
36
+ gem.add_runtime_dependency 'rivendell-db', '~> 0.2'
36
37
 
37
38
  gem.add_development_dependency "simplecov"
38
39
  gem.add_development_dependency "rspec"
@@ -40,6 +41,7 @@ Gem::Specification.new do |gem|
40
41
  gem.add_development_dependency "guard-rspec"
41
42
  gem.add_development_dependency "guard-cucumber"
42
43
  gem.add_development_dependency "rake"
44
+ gem.add_development_dependency "rdoc"
43
45
  gem.add_development_dependency "cucumber"
44
46
  gem.add_development_dependency "database_cleaner"
45
47
  # gem.add_development_dependency "remarkable_activerecord"
@@ -16,7 +16,7 @@ describe Rivendell::Import::CartFinder do
16
16
  before do
17
17
  subject.stub(:carts).and_return(carts)
18
18
  end
19
-
19
+
20
20
  it "should use carts with given options" do
21
21
  subject.should_receive(:carts).with(options).and_return(carts)
22
22
  subject.find_all_by_title("dummy", options)
@@ -53,7 +53,7 @@ describe Rivendell::Import::CartFinder do
53
53
  it "should remove accents" do
54
54
  subject.call("Ç'est évident").should == "c est evident"
55
55
  end
56
-
56
+
57
57
  end
58
58
 
59
59
  describe "#find_by_title" do
@@ -61,7 +61,7 @@ describe Rivendell::Import::CartFinder do
61
61
  before do
62
62
  subject.stub(:carts).and_return(carts)
63
63
  end
64
-
64
+
65
65
  it "should try an exact match" do
66
66
  subject.find_by_title(cart.title).should == cart
67
67
  end
@@ -98,7 +98,7 @@ describe Rivendell::Import::CartFinder::ByApi do
98
98
  before do
99
99
  subject.xport.stub :list_carts => carts
100
100
  end
101
-
101
+
102
102
  it "should return Xport#list_carts result" do
103
103
  subject.carts.should == carts
104
104
  end
@@ -131,9 +131,10 @@ describe Rivendell::Import::CartFinder::ByDb do
131
131
  describe "#carts" do
132
132
 
133
133
  before do
134
+ Rivendell::Import::Database.stub :init
134
135
  Rivendell::DB::Cart.stub :all => carts
135
136
  end
136
-
137
+
137
138
  it "should return Carts found in database" do
138
139
  subject.carts.should == carts
139
140
  end
@@ -10,7 +10,7 @@ describe Rivendell::Import::Cart do
10
10
  it "should use the given task" do
11
11
  Rivendell::Import::Cart.new(task).task.should == task
12
12
  end
13
-
13
+
14
14
  end
15
15
 
16
16
  describe "#xport" do
@@ -18,7 +18,7 @@ describe Rivendell::Import::Cart do
18
18
  before(:each) do
19
19
  task.stub :xport => mock
20
20
  end
21
-
21
+
22
22
  it "should be task xport" do
23
23
  subject.xport.should == subject.task.xport
24
24
  end
@@ -64,7 +64,7 @@ describe Rivendell::Import::Cart do
64
64
  subject.group = nil
65
65
  lambda { subject.create }.should raise_error
66
66
  end
67
-
67
+
68
68
  end
69
69
 
70
70
  end
@@ -85,14 +85,20 @@ describe Rivendell::Import::Cart do
85
85
  subject.number = 123
86
86
  subject.stub :cut => mock.as_null_object, :xport => mock.as_null_object
87
87
  end
88
-
88
+
89
89
  it "should create Cut" do
90
90
  subject.cut.should_receive :create
91
91
  subject.import file
92
92
  end
93
93
 
94
94
  it "should import file via xport with Cart and Cut numbers" do
95
- subject.xport.should_receive(:import).with(subject.number, subject.cut.number, file.path)
95
+ subject.xport.should_receive(:import).with(subject.number, subject.cut.number, file.path, {})
96
+ subject.import file
97
+ end
98
+
99
+ it "should use import options if specified" do
100
+ subject.import_options[:dummy] = true
101
+ subject.xport.should_receive(:import).with(subject.number, subject.cut.number, file.path, subject.import_options)
96
102
  subject.import file
97
103
  end
98
104
 
@@ -145,6 +151,11 @@ describe Rivendell::Import::Cart do
145
151
  subject.find_by_title("dummy", :group => "TEST")
146
152
  end
147
153
 
154
+ it "should add the import option :use_metadata => false" do
155
+ subject.find_by_title(cart.title)
156
+ subject.import_options[:use_metadata].should be_false
157
+ end
158
+
148
159
  end
149
160
 
150
161
  describe "#clear_cuts!" do
@@ -152,7 +163,7 @@ describe Rivendell::Import::Cart do
152
163
  before do
153
164
  subject.number = 123
154
165
  end
155
-
166
+
156
167
  it "should set flag clear_cuts" do
157
168
  subject.clear_cuts!
158
169
  subject.clear_cuts.should be_true
@@ -160,4 +171,42 @@ describe Rivendell::Import::Cart do
160
171
 
161
172
  end
162
173
 
174
+ describe "#attributes" do
175
+
176
+ it "should include clear_cuts value" do
177
+ subject.clear_cuts = true
178
+ subject.attributes["clear_cuts"].should == subject.clear_cuts
179
+ end
180
+
181
+ it "should include import_options value" do
182
+ subject.import_options = { :use_metadata => false }
183
+ subject.attributes["import_options"].should == { :use_metadata => false }
184
+ end
185
+
186
+ it "should include cut attributes" do
187
+ subject.cut.days = %{mon}
188
+ subject.attributes["cut"].should == { "days" => %{mon} }
189
+ end
190
+
191
+ end
192
+
193
+ describe "#to_json" do
194
+
195
+ it "should not include root" do
196
+ subject.cut.days = %{mon}
197
+ subject.to_json.should == '{"cut":{"days":"mon"}}'
198
+ end
199
+
200
+ end
201
+
202
+ describe "#attributes=" do
203
+
204
+ it "should set cut attributes" do
205
+ subject.attributes = { "cut" => { "days" => %{mon} } }
206
+ subject.cut.days.should == %{mon}
207
+ end
208
+
209
+ end
210
+
211
+
163
212
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rivendell::Import::Config do
4
-
4
+
5
5
  let(:config) { Rivendell::Import::Config.new }
6
6
 
7
7
  describe "#to_prepare" do
8
8
 
9
9
  let(:user_block) { Proc.new {} }
10
-
10
+
11
11
  it "should define Base.default_to_prepare with given block" do
12
12
  subject.to_prepare(&user_block)
13
13
  Rivendell::Import::Base.default_to_prepare.should == user_block
@@ -32,7 +32,17 @@ describe Rivendell::Import::Config do
32
32
  it_should_define_task_default_xport_option :host
33
33
  it_should_define_task_default_xport_option :login_name
34
34
  it_should_define_task_default_xport_option :password
35
-
35
+
36
+ it "should define Database.url" do
37
+ subject.db_url = "dummy"
38
+ Rivendell::Import::Database.url.should == "dummy"
39
+ end
40
+
41
+ after do
42
+ Rivendell::Import::Database.url = nil
43
+ end
44
+
45
+
36
46
  end
37
47
 
38
48
  end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rivendell::Import::Cut do
4
+
5
+ let(:task) { mock }
6
+ let(:cart) { Rivendell::Import::Cart.new task }
7
+ subject { Rivendell::Import::Cut.new cart }
8
+
9
+ describe "initialization" do
10
+
11
+ it "should use the given cart" do
12
+ Rivendell::Import::Cut.new(cart).cart.should == cart
13
+ end
14
+
15
+ end
16
+
17
+ describe "#create" do
18
+
19
+ before(:each) do
20
+ subject.stub :xport => mock
21
+ end
22
+
23
+ it "should use Xport#add_cut with Cart number" do
24
+ subject.cart.number = 123
25
+ subject.xport.should_receive(:add_cut).with(123).and_return(mock(:number => "000123_001"))
26
+ subject.create
27
+ end
28
+
29
+ it "should use the number returned by Xport#add_cut" do
30
+ subject.cart.number = 123
31
+ subject.xport.should_receive(:add_cut).with(123).and_return(mock(:number => "000123_001"))
32
+ subject.create
33
+ subject.number.should == "000123_001"
34
+ end
35
+
36
+ end
37
+
38
+ describe "#update" do
39
+
40
+ before do
41
+ subject.number = 1
42
+ end
43
+
44
+ context "when DB attributes are defined" do
45
+
46
+ let(:db_cut) do
47
+ Struct.new(:start_datetime, :end_datetime, :start_daypart, :end_daypart, :days) do
48
+ def save; true; end
49
+ end.new
50
+ end
51
+
52
+ before do
53
+ subject.stub :db_attributes? => true
54
+ Rivendell::DB::Cut.stub :get => db_cut
55
+ Rivendell::Import::Database.stub :init
56
+ end
57
+
58
+ it "should retrieve the DB Cut with number" do
59
+ Rivendell::DB::Cut.should_receive(:get).with(subject.name).and_return(db_cut)
60
+ subject.update
61
+ end
62
+
63
+ it "should save the DB Cut" do
64
+ db_cut.should_receive(:save)
65
+ subject.update
66
+ end
67
+
68
+ it "should define DB Cut start_datetime and end_datetime when datetime range is defined" do
69
+ begin_of_december = Time.parse("1 December 2013")
70
+ end_of_december = Time.parse("31 December 2013")
71
+ subject.datetime = begin_of_december..end_of_december
72
+
73
+ subject.update
74
+
75
+ db_cut.start_datetime.should == begin_of_december
76
+ db_cut.end_datetime.should == end_of_december
77
+ end
78
+
79
+ it "should define DB Cut start_daypart and end_daypart when daypart range is defined" do
80
+ subject.daypart = "12:00:00".."14:00:00"
81
+
82
+ subject.update
83
+
84
+ db_cut.start_daypart.should == "12:00:00"
85
+ db_cut.end_daypart.should == "14:00:00"
86
+ end
87
+
88
+ it "should define DB Cut days when defined" do
89
+ subject.days = %{mon}
90
+ subject.update
91
+ db_cut.days.should == subject.days
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+
98
+ describe "#name" do
99
+
100
+ it "should return 001015_001 for cart number 1015 and number 1" do
101
+ subject.number = 1
102
+ subject.cart.number = 1015
103
+ subject.name.should == "001015_001"
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rivendell::Import::Database do
4
+
5
+ it "should be enabled when url is defined" do
6
+ Rivendell::Import::Database.url = "dummy"
7
+ Rivendell::Import::Database.should be_enabled
8
+ end
9
+
10
+ after do
11
+ Rivendell::Import::Database.url = nil
12
+ end
13
+
14
+ end
@@ -1,10 +1,4 @@
1
- begin
2
- require 'rdoc/task'
3
- rescue LoadError
4
- require 'rdoc/rdoc'
5
- require 'rake/rdoctask'
6
- RDoc::Task = Rake::RDocTask
7
- end
1
+ require 'rdoc/task'
8
2
 
9
3
  Rake::RDocTask.new do |rdoc|
10
4
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rivendell-import
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
9
- version: "0.6"
8
+ - 7
9
+ version: "0.7"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alban Peignier
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2013-10-13 00:00:00 Z
17
+ date: 2013-12-12 00:00:00 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  requirement: &id001 !ruby/object:Gem::Requirement
@@ -22,12 +22,12 @@ dependencies:
22
22
  requirements:
23
23
  - - ~>
24
24
  - !ruby/object:Gem::Version
25
- hash: 29
25
+ hash: 25
26
26
  segments:
27
27
  - 1
28
- - 2
28
+ - 3
29
29
  - 1
30
- version: 1.2.1
30
+ version: 1.3.1
31
31
  prerelease: false
32
32
  name: listen
33
33
  type: :runtime
@@ -215,12 +215,13 @@ dependencies:
215
215
  requirement: &id014 !ruby/object:Gem::Requirement
216
216
  none: false
217
217
  requirements:
218
- - - ">="
218
+ - - ~>
219
219
  - !ruby/object:Gem::Version
220
- hash: 3
220
+ hash: 15
221
221
  segments:
222
222
  - 0
223
- version: "0"
223
+ - 2
224
+ version: "0.2"
224
225
  prerelease: false
225
226
  name: rivendell-db
226
227
  type: :runtime
@@ -320,7 +321,7 @@ dependencies:
320
321
  - 0
321
322
  version: "0"
322
323
  prerelease: false
323
- name: cucumber
324
+ name: rdoc
324
325
  type: :development
325
326
  version_requirements: *id021
326
327
  - !ruby/object:Gem::Dependency
@@ -334,9 +335,23 @@ dependencies:
334
335
  - 0
335
336
  version: "0"
336
337
  prerelease: false
337
- name: database_cleaner
338
+ name: cucumber
338
339
  type: :development
339
340
  version_requirements: *id022
341
+ - !ruby/object:Gem::Dependency
342
+ requirement: &id023 !ruby/object:Gem::Requirement
343
+ none: false
344
+ requirements:
345
+ - - ">="
346
+ - !ruby/object:Gem::Version
347
+ hash: 3
348
+ segments:
349
+ - 0
350
+ version: "0"
351
+ prerelease: false
352
+ name: database_cleaner
353
+ type: :development
354
+ version_requirements: *id023
340
355
  description: Import sound in our Rivendell system
341
356
  email:
342
357
  - alban@tryphon.eu
@@ -379,6 +394,7 @@ files:
379
394
  - lib/rivendell/import/config_loader.rb
380
395
  - lib/rivendell/import/context.rb
381
396
  - lib/rivendell/import/cut.rb
397
+ - lib/rivendell/import/database.rb
382
398
  - lib/rivendell/import/file.rb
383
399
  - lib/rivendell/import/notification.rb
384
400
  - lib/rivendell/import/notifier/base.rb
@@ -407,6 +423,8 @@ files:
407
423
  - spec/rivendell/import/cli_spec.rb
408
424
  - spec/rivendell/import/config_spec.rb
409
425
  - spec/rivendell/import/context_spec.rb
426
+ - spec/rivendell/import/cut_spec.rb
427
+ - spec/rivendell/import/database_spec.rb
410
428
  - spec/rivendell/import/file_spec.rb
411
429
  - spec/rivendell/import/notifier/base_spec.rb
412
430
  - spec/rivendell/import/notifier/mail_spec.rb
@@ -470,6 +488,8 @@ test_files:
470
488
  - spec/rivendell/import/cli_spec.rb
471
489
  - spec/rivendell/import/config_spec.rb
472
490
  - spec/rivendell/import/context_spec.rb
491
+ - spec/rivendell/import/cut_spec.rb
492
+ - spec/rivendell/import/database_spec.rb
473
493
  - spec/rivendell/import/file_spec.rb
474
494
  - spec/rivendell/import/notifier/base_spec.rb
475
495
  - spec/rivendell/import/notifier/mail_spec.rb