eventify 1.5.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.ruby-version +1 -1
- data/.travis.yml +0 -0
- data/Gemfile +0 -0
- data/Guardfile +0 -0
- data/LICENSE +0 -0
- data/README.md +2 -2
- data/Rakefile +0 -0
- data/eventify.gemspec +1 -1
- data/lib/eventify.rb +4 -4
- data/lib/eventify/configuration.rb +0 -0
- data/lib/eventify/database.rb +0 -0
- data/lib/eventify/mail.rb +0 -0
- data/lib/eventify/provider/apollo_kino.rb +21 -0
- data/lib/eventify/provider/base.rb +55 -55
- data/lib/eventify/provider/livenation.rb +21 -0
- data/lib/eventify/provider/piletilevi.rb +0 -0
- data/lib/eventify/version.rb +1 -1
- data/spec/eventify/configuration_spec.rb +51 -51
- data/spec/eventify/database_spec.rb +9 -9
- data/spec/eventify/mail_spec.rb +33 -33
- data/spec/eventify/provider/apollo_kino_spec.rb +25 -0
- data/spec/eventify/provider/base_spec.rb +145 -145
- data/spec/eventify/provider/livenation_spec.rb +25 -0
- data/spec/eventify/provider/piletilevi_spec.rb +46 -46
- data/spec/eventify_spec.rb +155 -155
- data/spec/spec_helper.rb +0 -0
- data/spec/support/apollo_kino.html +1021 -0
- data/spec/support/livenation.html +1444 -0
- data/spec/support/piletilevi.json +0 -0
- metadata +17 -17
- data/lib/eventify/provider/fbi.rb +0 -17
- data/lib/eventify/provider/solaris_kino.rb +0 -30
- data/spec/eventify/provider/fbi_spec.rb +0 -25
- data/spec/eventify/provider/solaris_kino_spec.rb +0 -31
- data/spec/support/fbi.html +0 -802
- data/spec/support/solaris_kino.html +0 -542
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Eventify::Provider::ApolloKino do
|
4
|
+
context "#fetch" do
|
5
|
+
it "fetches events" do
|
6
|
+
stub_request(:get, URI.join(Eventify::Provider::ApolloKino::URL, "eng/soon").to_s).to_return(body: File.read(File.expand_path("../../support/apollo_kino.html", __dir__)))
|
7
|
+
|
8
|
+
events = Eventify::Provider::ApolloKino.fetch
|
9
|
+
expect(events).to eq([
|
10
|
+
Eventify::Provider::ApolloKino.new(
|
11
|
+
title: "Võimlemisklubi Janika TALVEKONTSERT",
|
12
|
+
link: "https://www.apollokino.ee/eng/event/4127/title/v%C3%B5imlemisklubi_janika_talvekontsert/",
|
13
|
+
date: Time.parse("2021-01-31"),
|
14
|
+
id: "https://www.apollokino.ee/eng/event/4127/title/v%C3%B5imlemisklubi_janika_talvekontsert/"
|
15
|
+
),
|
16
|
+
Eventify::Provider::ApolloKino.new(
|
17
|
+
title: "Jurassic World: Dominion",
|
18
|
+
link: "https://www.apollokino.ee/eng/event/4064/title/jurassic_world_dominion/",
|
19
|
+
date: Time.parse("2022-06-10"),
|
20
|
+
id: "https://www.apollokino.ee/eng/event/4064/title/jurassic_world_dominion/",
|
21
|
+
),
|
22
|
+
])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,145 +1,145 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Eventify::Provider::Base do
|
4
|
-
context ".fetch" do
|
5
|
-
it "needs to be implemented" do
|
6
|
-
class Eventify::Provider::CustomEvent < Eventify::Provider::Base; end
|
7
|
-
|
8
|
-
expect {
|
9
|
-
Eventify::Provider::CustomEvent.fetch
|
10
|
-
}.to raise_error(NotImplementedError)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "#initialize" do
|
15
|
-
it "parses raw event" do
|
16
|
-
event = {
|
17
|
-
id: "86362",
|
18
|
-
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
19
|
-
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
20
|
-
date: Time.parse("2013-12-27 12:30:11"),
|
21
|
-
}
|
22
|
-
|
23
|
-
parsed_event = Eventify::Provider::Base.new(event)
|
24
|
-
parsed_event.id.
|
25
|
-
parsed_event.provider.
|
26
|
-
parsed_event.title.
|
27
|
-
parsed_event.link.
|
28
|
-
parsed_event.date.
|
29
|
-
end
|
30
|
-
|
31
|
-
it "raises an error when id is missing" do
|
32
|
-
event = {
|
33
|
-
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
34
|
-
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
35
|
-
date: Time.parse("2013-12-27 12:30:11"),
|
36
|
-
}
|
37
|
-
|
38
|
-
expect {
|
39
|
-
Eventify::Provider::Base.new(event)
|
40
|
-
}.to raise_error(Eventify::Provider::Base::MissingAttributeError)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "raises an error when title is missing" do
|
44
|
-
event = {
|
45
|
-
id: "86362",
|
46
|
-
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
47
|
-
date: Time.parse("2013-12-27 12:30:11"),
|
48
|
-
}
|
49
|
-
|
50
|
-
expect {
|
51
|
-
Eventify::Provider::Base.new(event)
|
52
|
-
}.to raise_error(Eventify::Provider::Base::MissingAttributeError)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "raises an error when link is missing" do
|
56
|
-
event = {
|
57
|
-
id: "86362",
|
58
|
-
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
59
|
-
date: Time.parse("2013-12-27 12:30:11"),
|
60
|
-
}
|
61
|
-
|
62
|
-
expect {
|
63
|
-
Eventify::Provider::Base.new(event)
|
64
|
-
}.to raise_error(Eventify::Provider::Base::MissingAttributeError)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "#provider" do
|
69
|
-
it "uses class name" do
|
70
|
-
class Eventify::Provider::CustomEvent < Eventify::Provider::Base; end
|
71
|
-
Eventify::Provider::CustomEvent.new(id: "123", title: "foo", link: "http://example.org").provider.
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "#==" do
|
76
|
-
it "true when id and provider match" do
|
77
|
-
Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org").
|
78
|
-
end
|
79
|
-
|
80
|
-
it "false when id does not match" do
|
81
|
-
Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org").
|
82
|
-
end
|
83
|
-
|
84
|
-
it "false when class does not match" do
|
85
|
-
class Eventify::Provider::CustomEvent < Eventify::Provider::Base; end
|
86
|
-
Eventify::Provider::CustomEvent.new(id: "123", title: "foo", link: "http://example.org").
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "#save" do
|
91
|
-
it "saves event into database" do
|
92
|
-
event = {
|
93
|
-
id: "86362",
|
94
|
-
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
95
|
-
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
96
|
-
date: Time.parse("2013-12-27 12:30:11"),
|
97
|
-
}
|
98
|
-
Eventify::Provider::Base.new(event).save
|
99
|
-
|
100
|
-
Eventify::Database.events.size.
|
101
|
-
end
|
102
|
-
|
103
|
-
it "returns self" do
|
104
|
-
event = {
|
105
|
-
id: "86362",
|
106
|
-
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
107
|
-
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
108
|
-
date: Time.parse("2013-12-27 12:30:11"),
|
109
|
-
}
|
110
|
-
event_instance = Eventify::Provider::Base.new(event)
|
111
|
-
event_instance.save.
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context "#exists?" do
|
116
|
-
it "true for existing event" do
|
117
|
-
event = {
|
118
|
-
id: "86362",
|
119
|
-
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
120
|
-
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
121
|
-
date: Time.parse("2013-12-27 12:30:11"),
|
122
|
-
}
|
123
|
-
Eventify::Provider::Base.new(event).save
|
124
|
-
|
125
|
-
Eventify::Provider::Base.new(event).
|
126
|
-
end
|
127
|
-
|
128
|
-
it "false for not existing event" do
|
129
|
-
event = {
|
130
|
-
id: "86362",
|
131
|
-
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
132
|
-
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
133
|
-
date: Time.parse("2013-12-27 12:30:11"),
|
134
|
-
}
|
135
|
-
|
136
|
-
Eventify::Provider::Base.new(event).
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
it "sorts by title" do
|
141
|
-
event1 = Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org")
|
142
|
-
event2 = Eventify::Provider::Piletilevi.new(id: "123", title: "bar", link: "http://example.org")
|
143
|
-
[event1, event2].sort.
|
144
|
-
end
|
145
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Eventify::Provider::Base do
|
4
|
+
context ".fetch" do
|
5
|
+
it "needs to be implemented" do
|
6
|
+
class Eventify::Provider::CustomEvent < Eventify::Provider::Base; end
|
7
|
+
|
8
|
+
expect {
|
9
|
+
Eventify::Provider::CustomEvent.fetch
|
10
|
+
}.to raise_error(NotImplementedError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "#initialize" do
|
15
|
+
it "parses raw event" do
|
16
|
+
event = {
|
17
|
+
id: "86362",
|
18
|
+
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
19
|
+
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
20
|
+
date: Time.parse("2013-12-27 12:30:11"),
|
21
|
+
}
|
22
|
+
|
23
|
+
parsed_event = Eventify::Provider::Base.new(event)
|
24
|
+
expect(parsed_event.id).to eq("86362")
|
25
|
+
expect(parsed_event.provider).to eq("Eventify::Provider::Base")
|
26
|
+
expect(parsed_event.title).to eq(event[:title])
|
27
|
+
expect(parsed_event.link).to eq(event[:link])
|
28
|
+
expect(parsed_event.date).to eq(event[:date])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "raises an error when id is missing" do
|
32
|
+
event = {
|
33
|
+
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
34
|
+
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
35
|
+
date: Time.parse("2013-12-27 12:30:11"),
|
36
|
+
}
|
37
|
+
|
38
|
+
expect {
|
39
|
+
Eventify::Provider::Base.new(event)
|
40
|
+
}.to raise_error(Eventify::Provider::Base::MissingAttributeError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises an error when title is missing" do
|
44
|
+
event = {
|
45
|
+
id: "86362",
|
46
|
+
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
47
|
+
date: Time.parse("2013-12-27 12:30:11"),
|
48
|
+
}
|
49
|
+
|
50
|
+
expect {
|
51
|
+
Eventify::Provider::Base.new(event)
|
52
|
+
}.to raise_error(Eventify::Provider::Base::MissingAttributeError)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "raises an error when link is missing" do
|
56
|
+
event = {
|
57
|
+
id: "86362",
|
58
|
+
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
59
|
+
date: Time.parse("2013-12-27 12:30:11"),
|
60
|
+
}
|
61
|
+
|
62
|
+
expect {
|
63
|
+
Eventify::Provider::Base.new(event)
|
64
|
+
}.to raise_error(Eventify::Provider::Base::MissingAttributeError)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "#provider" do
|
69
|
+
it "uses class name" do
|
70
|
+
class Eventify::Provider::CustomEvent < Eventify::Provider::Base; end
|
71
|
+
expect(Eventify::Provider::CustomEvent.new(id: "123", title: "foo", link: "http://example.org").provider).to eq("Eventify::Provider::CustomEvent")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "#==" do
|
76
|
+
it "true when id and provider match" do
|
77
|
+
expect(Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org")).to eq(Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org"))
|
78
|
+
end
|
79
|
+
|
80
|
+
it "false when id does not match" do
|
81
|
+
expect(Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org")).not_to eq(Eventify::Provider::Base.new(id: "321", title: "foo", link: "http://example.org"))
|
82
|
+
end
|
83
|
+
|
84
|
+
it "false when class does not match" do
|
85
|
+
class Eventify::Provider::CustomEvent < Eventify::Provider::Base; end
|
86
|
+
expect(Eventify::Provider::CustomEvent.new(id: "123", title: "foo", link: "http://example.org")).not_to eq(Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org"))
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "#save" do
|
91
|
+
it "saves event into database" do
|
92
|
+
event = {
|
93
|
+
id: "86362",
|
94
|
+
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
95
|
+
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
96
|
+
date: Time.parse("2013-12-27 12:30:11"),
|
97
|
+
}
|
98
|
+
Eventify::Provider::Base.new(event).save
|
99
|
+
|
100
|
+
expect(Eventify::Database.events.size).to eq(1)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "returns self" do
|
104
|
+
event = {
|
105
|
+
id: "86362",
|
106
|
+
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
107
|
+
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
108
|
+
date: Time.parse("2013-12-27 12:30:11"),
|
109
|
+
}
|
110
|
+
event_instance = Eventify::Provider::Base.new(event)
|
111
|
+
expect(event_instance.save).to eq(event_instance)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "#exists?" do
|
116
|
+
it "true for existing event" do
|
117
|
+
event = {
|
118
|
+
id: "86362",
|
119
|
+
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
120
|
+
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
121
|
+
date: Time.parse("2013-12-27 12:30:11"),
|
122
|
+
}
|
123
|
+
Eventify::Provider::Base.new(event).save
|
124
|
+
|
125
|
+
expect(Eventify::Provider::Base.new(event)).to exist
|
126
|
+
end
|
127
|
+
|
128
|
+
it "false for not existing event" do
|
129
|
+
event = {
|
130
|
+
id: "86362",
|
131
|
+
title: "Koit Toome ja Karl-Erik Taukar 17.01.2014 - 21:00 - Rock Cafe, Tallinn, Eesti",
|
132
|
+
link: "http://www.piletilevi.ee/est/piletid/muusika/rock_ja_pop/?concert=138090",
|
133
|
+
date: Time.parse("2013-12-27 12:30:11"),
|
134
|
+
}
|
135
|
+
|
136
|
+
expect(Eventify::Provider::Base.new(event)).not_to exist
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "sorts by title" do
|
141
|
+
event1 = Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org")
|
142
|
+
event2 = Eventify::Provider::Piletilevi.new(id: "123", title: "bar", link: "http://example.org")
|
143
|
+
expect([event1, event2].sort).to eq([event2, event1])
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Eventify::Provider::Livenation do
|
4
|
+
context "#fetch" do
|
5
|
+
it "fetches events" do
|
6
|
+
stub_request(:get, Eventify::Provider::Livenation::URL).to_return(body: File.read(File.expand_path("../../support/livenation.html", __dir__)))
|
7
|
+
|
8
|
+
events = Eventify::Provider::Livenation.fetch
|
9
|
+
expect(events).to eq([
|
10
|
+
Eventify::Provider::Livenation.new(
|
11
|
+
title: "CLANNAD - In A Lifetime Farewell Tour",
|
12
|
+
link: "https://www.livenation.ee/show/1310067/clannad-in-a-lifetime-farewell-tour/tallinn/2021-03-30/ee",
|
13
|
+
date: Time.parse("2021-3-30"),
|
14
|
+
id: "https://www.livenation.ee/show/1310067/clannad-in-a-lifetime-farewell-tour/tallinn/2021-03-30/ee"
|
15
|
+
),
|
16
|
+
Eventify::Provider::Livenation.new(
|
17
|
+
title: "JAMES BLUNT - Once Upon A Mind Tour",
|
18
|
+
link: "https://www.livenation.ee/show/1310003/james-blunt-once-upon-a-mind-tour/tallinn/2021-06-03/ee",
|
19
|
+
date: Time.parse("2021-6-03"),
|
20
|
+
id: "https://www.livenation.ee/show/1310003/james-blunt-once-upon-a-mind-tour/tallinn/2021-06-03/ee"
|
21
|
+
)
|
22
|
+
])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,46 +1,46 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Eventify::Provider::Piletilevi do
|
4
|
-
context "#fetch" do
|
5
|
-
it "fetches events" do
|
6
|
-
stub_request(:get, Eventify::Provider::Piletilevi::URL.to_s).to_return(body: File.read(File.expand_path("../../support/piletilevi.json", __dir__)))
|
7
|
-
|
8
|
-
events = Eventify::Provider::Piletilevi.fetch
|
9
|
-
events.
|
10
|
-
Eventify::Provider::Piletilevi.new(
|
11
|
-
title:"Jelena Vaenga \/ \u0415\u043b\u0435\u043d\u0430 \u0412\u0430\u0435\u043d\u0433\u0430",
|
12
|
-
link:"http:/\/www.piletilevi.ee\/est\/piletid\/muusika\/rock-ja-pop\/jelena-vaenga-elena-vaenga-190326\/",
|
13
|
-
date: Time.at(1484326800),
|
14
|
-
id: "190326"
|
15
|
-
),
|
16
|
-
Eventify::Provider::Piletilevi.new(
|
17
|
-
title:"Head t\u00fc\u00fcbid",
|
18
|
-
link:"http:\/\/www.piletilevi.ee\/est\/piletid\/film\/krimifilm\/head-tuubid-190410\/",
|
19
|
-
date: Time.at(1465405200),
|
20
|
-
id: "190410"
|
21
|
-
),
|
22
|
-
Eventify::Provider::Piletilevi.new(
|
23
|
-
title:"Teismelised ninjakilpkonnad: Varjust v\u00e4lja (3D)",
|
24
|
-
link:"http:\/\/www.piletilevi.ee\/est\/piletid\/film\/marul\/teismelised-ninjakilpkonnad-varjust-valja-3d-190405\/",
|
25
|
-
date: Time.at(1465491600),
|
26
|
-
id: "190405"
|
27
|
-
)
|
28
|
-
]
|
29
|
-
end
|
30
|
-
|
31
|
-
it "works without concerts" do
|
32
|
-
stub_request(:get, Eventify::Provider::Piletilevi::URL.to_s).to_return(body: %q|{"responseData": {}}|)
|
33
|
-
Eventify::Provider::Piletilevi.fetch.
|
34
|
-
end
|
35
|
-
|
36
|
-
it "works without response data" do
|
37
|
-
stub_request(:get, Eventify::Provider::Piletilevi::URL.to_s).to_return(body: %q|{"foo": {}}|)
|
38
|
-
Eventify::Provider::Piletilevi.fetch.
|
39
|
-
end
|
40
|
-
|
41
|
-
it "works without json response" do
|
42
|
-
stub_request(:get, Eventify::Provider::Piletilevi::URL.to_s).to_return(body: %q|foo|)
|
43
|
-
Eventify::Provider::Piletilevi.fetch.
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Eventify::Provider::Piletilevi do
|
4
|
+
context "#fetch" do
|
5
|
+
it "fetches events" do
|
6
|
+
stub_request(:get, Eventify::Provider::Piletilevi::URL.to_s).to_return(body: File.read(File.expand_path("../../support/piletilevi.json", __dir__)))
|
7
|
+
|
8
|
+
events = Eventify::Provider::Piletilevi.fetch
|
9
|
+
expect(events).to eq([
|
10
|
+
Eventify::Provider::Piletilevi.new(
|
11
|
+
title:"Jelena Vaenga \/ \u0415\u043b\u0435\u043d\u0430 \u0412\u0430\u0435\u043d\u0433\u0430",
|
12
|
+
link:"http:/\/www.piletilevi.ee\/est\/piletid\/muusika\/rock-ja-pop\/jelena-vaenga-elena-vaenga-190326\/",
|
13
|
+
date: Time.at(1484326800),
|
14
|
+
id: "190326"
|
15
|
+
),
|
16
|
+
Eventify::Provider::Piletilevi.new(
|
17
|
+
title:"Head t\u00fc\u00fcbid",
|
18
|
+
link:"http:\/\/www.piletilevi.ee\/est\/piletid\/film\/krimifilm\/head-tuubid-190410\/",
|
19
|
+
date: Time.at(1465405200),
|
20
|
+
id: "190410"
|
21
|
+
),
|
22
|
+
Eventify::Provider::Piletilevi.new(
|
23
|
+
title:"Teismelised ninjakilpkonnad: Varjust v\u00e4lja (3D)",
|
24
|
+
link:"http:\/\/www.piletilevi.ee\/est\/piletid\/film\/marul\/teismelised-ninjakilpkonnad-varjust-valja-3d-190405\/",
|
25
|
+
date: Time.at(1465491600),
|
26
|
+
id: "190405"
|
27
|
+
)
|
28
|
+
])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "works without concerts" do
|
32
|
+
stub_request(:get, Eventify::Provider::Piletilevi::URL.to_s).to_return(body: %q|{"responseData": {}}|)
|
33
|
+
expect(Eventify::Provider::Piletilevi.fetch).to eq([])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "works without response data" do
|
37
|
+
stub_request(:get, Eventify::Provider::Piletilevi::URL.to_s).to_return(body: %q|{"foo": {}}|)
|
38
|
+
expect(Eventify::Provider::Piletilevi.fetch).to eq([])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "works without json response" do
|
42
|
+
stub_request(:get, Eventify::Provider::Piletilevi::URL.to_s).to_return(body: %q|foo|)
|
43
|
+
expect(Eventify::Provider::Piletilevi.fetch).to eq([])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/eventify_spec.rb
CHANGED
@@ -1,155 +1,155 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Eventify do
|
4
|
-
before do
|
5
|
-
stub_const "Eventify::Configuration::PATH", File.join(Dir.tmpdir, "eventify-config.yml")
|
6
|
-
File.delete Eventify::Configuration::PATH if File.exists? Eventify::Configuration::PATH
|
7
|
-
end
|
8
|
-
|
9
|
-
context "#initialize" do
|
10
|
-
it "initializes configuration" do
|
11
|
-
Eventify.new.configuration[:subscribers].
|
12
|
-
end
|
13
|
-
|
14
|
-
it "allows to override configuration" do
|
15
|
-
Eventify.new(foo: "bar").configuration[:foo].
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "#configuration" do
|
20
|
-
it "provides access to the configuration instance" do
|
21
|
-
eventify = Eventify.new
|
22
|
-
eventify.configuration.
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "#new_events" do
|
27
|
-
it "all are new" do
|
28
|
-
eventify = Eventify.new
|
29
|
-
events = [
|
30
|
-
Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org"),
|
31
|
-
Eventify::Provider::Base.new(id: "456", title: "bar", link: "http://example.org")
|
32
|
-
]
|
33
|
-
eventify.
|
34
|
-
eventify.new_events.
|
35
|
-
end
|
36
|
-
|
37
|
-
it "old ones are filtered out" do
|
38
|
-
eventify = Eventify.new
|
39
|
-
old_event = Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org").save
|
40
|
-
new_event = Eventify::Provider::Base.new(id: "456", title: "bar", link: "http://example.org")
|
41
|
-
events = [old_event, new_event]
|
42
|
-
eventify.
|
43
|
-
|
44
|
-
eventify.new_events.
|
45
|
-
end
|
46
|
-
|
47
|
-
it "caches the results" do
|
48
|
-
eventify = Eventify.new
|
49
|
-
|
50
|
-
event = Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org")
|
51
|
-
eventify.
|
52
|
-
|
53
|
-
2.times { eventify.new_events.
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "#all_events" do
|
58
|
-
it "fetches all events from all providers" do
|
59
|
-
eventify = Eventify.new
|
60
|
-
eventify.providers.each do |provider|
|
61
|
-
provider.
|
62
|
-
end
|
63
|
-
|
64
|
-
eventify.all_events
|
65
|
-
end
|
66
|
-
|
67
|
-
it "combines all events from all providers" do
|
68
|
-
event1 = Eventify::Provider::Piletilevi.new(id: "123", title: "foo", link: "http://example.org")
|
69
|
-
event2 = Eventify::Provider::Piletilevi.new(id: "456", title: "bar", link: "http://example.org")
|
70
|
-
Eventify::Provider::Piletilevi.
|
71
|
-
|
72
|
-
event3 = Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org")
|
73
|
-
Eventify::Provider::Base.
|
74
|
-
|
75
|
-
eventify = Eventify.new
|
76
|
-
eventify.
|
77
|
-
eventify.all_events.
|
78
|
-
end
|
79
|
-
|
80
|
-
it "caches results" do
|
81
|
-
eventify = Eventify.new
|
82
|
-
eventify.
|
83
|
-
Eventify::Provider::Base.
|
84
|
-
|
85
|
-
eventify.all_events.
|
86
|
-
eventify.all_events.
|
87
|
-
end
|
88
|
-
|
89
|
-
it "removes duplicate entries" do
|
90
|
-
event1 = Eventify::Provider::Piletilevi.new(id: "123", title: "foo", link: "http://example.org")
|
91
|
-
event2 = Eventify::Provider::Piletilevi.new(id: "123", title: "foo", link: "http://example.org")
|
92
|
-
event1.
|
93
|
-
Eventify::Provider::Piletilevi.
|
94
|
-
|
95
|
-
eventify = Eventify.new
|
96
|
-
eventify.
|
97
|
-
eventify.all_events.
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context "#providers" do
|
102
|
-
it "returns all providers" do
|
103
|
-
expected_providers = [
|
104
|
-
Eventify::Provider::Piletilevi,
|
105
|
-
Eventify::Provider::
|
106
|
-
Eventify::Provider::
|
107
|
-
]
|
108
|
-
Eventify.new.providers.
|
109
|
-
end
|
110
|
-
|
111
|
-
it "allows to override" do
|
112
|
-
eventify = Eventify.new
|
113
|
-
eventify.providers = ["foo"]
|
114
|
-
|
115
|
-
eventify.providers.
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "#process_new_events" do
|
120
|
-
it "sends out e-mail for new events" do
|
121
|
-
new_events = [
|
122
|
-
Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org"),
|
123
|
-
Eventify::Provider::Base.new(id: "456", title: "bar", link: "http://example.org")
|
124
|
-
]
|
125
|
-
configuration = double("configuration")
|
126
|
-
eventify = Eventify.new configuration
|
127
|
-
eventify.
|
128
|
-
Eventify::Mail.
|
129
|
-
|
130
|
-
eventify.process_new_events
|
131
|
-
end
|
132
|
-
|
133
|
-
it "does not send e-mail when no new events" do
|
134
|
-
eventify = Eventify.new
|
135
|
-
eventify.
|
136
|
-
Eventify::Mail.
|
137
|
-
|
138
|
-
eventify.process_new_events
|
139
|
-
end
|
140
|
-
|
141
|
-
it "saves new events into database" do
|
142
|
-
new_events = [
|
143
|
-
Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org/1", date: Time.now),
|
144
|
-
Eventify::Provider::Base.new(id: "456", title: "bar", link: "http://example.org/2", date: Time.now)
|
145
|
-
]
|
146
|
-
eventify = Eventify.new
|
147
|
-
eventify.
|
148
|
-
Eventify::Mail.
|
149
|
-
|
150
|
-
eventify.process_new_events
|
151
|
-
|
152
|
-
Eventify::Database.events.size.
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Eventify do
|
4
|
+
before do
|
5
|
+
stub_const "Eventify::Configuration::PATH", File.join(Dir.tmpdir, "eventify-config.yml")
|
6
|
+
File.delete Eventify::Configuration::PATH if File.exists? Eventify::Configuration::PATH
|
7
|
+
end
|
8
|
+
|
9
|
+
context "#initialize" do
|
10
|
+
it "initializes configuration" do
|
11
|
+
expect(Eventify.new.configuration[:subscribers]).to eq(["user@example.org"])
|
12
|
+
end
|
13
|
+
|
14
|
+
it "allows to override configuration" do
|
15
|
+
expect(Eventify.new(foo: "bar").configuration[:foo]).to eq("bar")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "#configuration" do
|
20
|
+
it "provides access to the configuration instance" do
|
21
|
+
eventify = Eventify.new
|
22
|
+
expect(eventify.configuration).to eq(eventify.instance_variable_get(:@configuration))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "#new_events" do
|
27
|
+
it "all are new" do
|
28
|
+
eventify = Eventify.new
|
29
|
+
events = [
|
30
|
+
Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org"),
|
31
|
+
Eventify::Provider::Base.new(id: "456", title: "bar", link: "http://example.org")
|
32
|
+
]
|
33
|
+
allow(eventify).to receive_messages(all_events: events)
|
34
|
+
expect(eventify.new_events).to eq(events)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "old ones are filtered out" do
|
38
|
+
eventify = Eventify.new
|
39
|
+
old_event = Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org").save
|
40
|
+
new_event = Eventify::Provider::Base.new(id: "456", title: "bar", link: "http://example.org")
|
41
|
+
events = [old_event, new_event]
|
42
|
+
allow(eventify).to receive_messages(all_events: events)
|
43
|
+
|
44
|
+
expect(eventify.new_events).to eq([new_event])
|
45
|
+
end
|
46
|
+
|
47
|
+
it "caches the results" do
|
48
|
+
eventify = Eventify.new
|
49
|
+
|
50
|
+
event = Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org")
|
51
|
+
expect(eventify).to receive(:all_events).and_return([event])
|
52
|
+
|
53
|
+
2.times { expect(eventify.new_events).to eq([event]) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "#all_events" do
|
58
|
+
it "fetches all events from all providers" do
|
59
|
+
eventify = Eventify.new
|
60
|
+
eventify.providers.each do |provider|
|
61
|
+
expect(provider).to receive :fetch
|
62
|
+
end
|
63
|
+
|
64
|
+
eventify.all_events
|
65
|
+
end
|
66
|
+
|
67
|
+
it "combines all events from all providers" do
|
68
|
+
event1 = Eventify::Provider::Piletilevi.new(id: "123", title: "foo", link: "http://example.org")
|
69
|
+
event2 = Eventify::Provider::Piletilevi.new(id: "456", title: "bar", link: "http://example.org")
|
70
|
+
allow(Eventify::Provider::Piletilevi).to receive_messages(fetch: [event1, event2])
|
71
|
+
|
72
|
+
event3 = Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org")
|
73
|
+
allow(Eventify::Provider::Base).to receive_messages(fetch: [event3])
|
74
|
+
|
75
|
+
eventify = Eventify.new
|
76
|
+
allow(eventify).to receive_messages(providers: [Eventify::Provider::Piletilevi, Eventify::Provider::Base])
|
77
|
+
expect(eventify.all_events).to eq([event1, event2, event3])
|
78
|
+
end
|
79
|
+
|
80
|
+
it "caches results" do
|
81
|
+
eventify = Eventify.new
|
82
|
+
expect(eventify).to receive(:providers).once.and_return([Eventify::Provider::Base])
|
83
|
+
expect(Eventify::Provider::Base).to receive(:fetch).once.and_return([1])
|
84
|
+
|
85
|
+
expect(eventify.all_events).to eq([1])
|
86
|
+
expect(eventify.all_events).to eq([1])
|
87
|
+
end
|
88
|
+
|
89
|
+
it "removes duplicate entries" do
|
90
|
+
event1 = Eventify::Provider::Piletilevi.new(id: "123", title: "foo", link: "http://example.org")
|
91
|
+
event2 = Eventify::Provider::Piletilevi.new(id: "123", title: "foo", link: "http://example.org")
|
92
|
+
expect(event1).to eq(event2)
|
93
|
+
allow(Eventify::Provider::Piletilevi).to receive_messages(fetch: [event1, event2])
|
94
|
+
|
95
|
+
eventify = Eventify.new
|
96
|
+
allow(eventify).to receive_messages(providers: [Eventify::Provider::Piletilevi])
|
97
|
+
expect(eventify.all_events).to eq([event1])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "#providers" do
|
102
|
+
it "returns all providers" do
|
103
|
+
expected_providers = [
|
104
|
+
Eventify::Provider::Piletilevi,
|
105
|
+
Eventify::Provider::Livenation,
|
106
|
+
Eventify::Provider::ApolloKino
|
107
|
+
]
|
108
|
+
expect(Eventify.new.providers).to eq(expected_providers)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "allows to override" do
|
112
|
+
eventify = Eventify.new
|
113
|
+
eventify.providers = ["foo"]
|
114
|
+
|
115
|
+
expect(eventify.providers).to eq(["foo"])
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "#process_new_events" do
|
120
|
+
it "sends out e-mail for new events" do
|
121
|
+
new_events = [
|
122
|
+
Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org"),
|
123
|
+
Eventify::Provider::Base.new(id: "456", title: "bar", link: "http://example.org")
|
124
|
+
]
|
125
|
+
configuration = double("configuration")
|
126
|
+
eventify = Eventify.new configuration
|
127
|
+
expect(eventify).to receive(:new_events).and_return(new_events)
|
128
|
+
expect(Eventify::Mail).to receive(:deliver).with(new_events, configuration)
|
129
|
+
|
130
|
+
eventify.process_new_events
|
131
|
+
end
|
132
|
+
|
133
|
+
it "does not send e-mail when no new events" do
|
134
|
+
eventify = Eventify.new
|
135
|
+
expect(eventify).to receive(:new_events).and_return([])
|
136
|
+
expect(Eventify::Mail).not_to receive(:deliver)
|
137
|
+
|
138
|
+
eventify.process_new_events
|
139
|
+
end
|
140
|
+
|
141
|
+
it "saves new events into database" do
|
142
|
+
new_events = [
|
143
|
+
Eventify::Provider::Base.new(id: "123", title: "foo", link: "http://example.org/1", date: Time.now),
|
144
|
+
Eventify::Provider::Base.new(id: "456", title: "bar", link: "http://example.org/2", date: Time.now)
|
145
|
+
]
|
146
|
+
eventify = Eventify.new
|
147
|
+
expect(eventify).to receive(:new_events).and_return(new_events)
|
148
|
+
allow(Eventify::Mail).to receive(:deliver)
|
149
|
+
|
150
|
+
eventify.process_new_events
|
151
|
+
|
152
|
+
expect(Eventify::Database.events.size).to eq(2)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|