Skip to content

Instantly share code, notes, and snippets.

@khadzhinov
Created August 23, 2018 09:06
Show Gist options
  • Save khadzhinov/5b12dfc3e69ca287992a7e4ef28991c1 to your computer and use it in GitHub Desktop.
Save khadzhinov/5b12dfc3e69ca287992a7e4ef28991c1 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
describe Calendar::Icalendar do
subject :ical do
Calendar::Icalendar.new(account,
start: start,
stop: stop,
filter: filter&.params || {},
filter_name: filter&.name).get_items.to_ical
end
let(:start) { Date.new(2017, 10, 1) }
let(:stop) { Date.new(2017, 11, 1) }
let(:milestone_date) { Date.new(2017, 10, 2) }
let(:posted_date) { Date.new(2017, 10, 5) }
let!(:account) { create(:account, owner_id: 1, name: 'New IT', level: 7) }
let!(:article_1) do
create(:article, id: 1, name: 'test article 1', milestone4: milestone_date,
account_id: account.id, status: 'approved')
end
let!(:article_2) do
create :article, id: 2, name: 'test article 2', milestone4: Date.new(2017, 10, 10),
account_id: account.id, story_id: story_1.id
end
let!(:story_1) do
create :story, id: 1, name: 'test story 1', date_begin: milestone_date, date_end: posted_date,
account_id: account.id, topic_id: topic_1.id
end
let!(:story_2) do
create :story, id: 2, name: 'test story 2', date_begin: Date.new(2017, 10, 6), date_end: Date.new(2017, 10, 15),
account_id: account.id, topic_id: 2
end
let!(:soc_blueprint) do
create :blueprint, id: 1, postable_id: 1, postable_type: 'Article', message: 'test message', posted_at: posted_date,
scheduled_at: posted_date, post_type: text, data: {}, account_id: account.id
end
let!(:message) do
create :general_message, service_id: 1, message: 'test message', posted_at: posted_date,
blueprint_id: soc_blueprint.id, type: 'Social::Twitter::Message', auto_post: true,
postable_type: 'Test', account_id: account.id
end
let!(:task) do
create :task, start: milestone_date, due: posted_date, account_id: account.id, title: 'test task'
end
let!(:topic_1) do
create :topic, id: 1, name: 'test Topic 1', date_begin: milestone_date, date_end: posted_date,
account_id: account.id, category_id: 1
end
let!(:topic_2) do
create :topic, id: 2, name: 'test Topic 2', date_begin: Date.new(2017, 10, 8),
date_end: Date.new(2017, 10, 20), account_id: account.id, category_id: 2
end
let!(:issue) do
create :issue, id: 1, name: 'test Issue', start: milestone_date, stop: posted_date, account_id: account.id
end
let!(:issue_2) do
create :issue, id: 2, name: 'test Issue 2', start: posted_date,
stop: Date.new(2017, 10, 18), account_id: account.id, articles: [article_1]
end
let!(:text) do
create :text, content: 'test text', language_id: 1, textable_id: 1, textable_type: 'Article', account_id: account.id
end
let!(:persona_value) { create :persona_value, persona_id: 1, personaable_id: 1, personaable_type: 'Article' }
context 'when there are active articles' do
let(:filter) { create :filter, params: { 'type': { 'Article': 'active' } } }
it 'active articles' do
expect(ical.scan('test message').size).to eq 1
expect(ical.scan('article').size).to eq 5
expect(ical.scan('test story').size).to eq 0
expect(ical.scan(task.name).size).to eq 0
expect(ical.scan(issue.name).size).to eq 0
end
end
context 'when there are active stories' do
let(:filter) { create :filter, params: { 'type': { 'Story': 'active' } } }
it 'active stories' do
expect(ical.scan('test message').size).to eq 0
expect(ical.scan('test story').size).to eq 4
expect(ical.scan('test article').size).to eq 0
expect(ical.scan(task.name).size).to eq 0
expect(ical.scan(issue.name).size).to eq 0
end
end
context 'when there are active tasks' do
let(:filter) { create :filter, params: { 'type': { 'Task': 'active' } } }
it 'active tasks' do
expect(ical.scan('test message').size).to eq 0
expect(ical.scan(task.name).size).to eq 2
expect(ical.scan('test article').size).to eq 0
expect(ical.scan('test story').size).to eq 0
expect(ical.scan(issue.name).size).to eq 0
end
end
context 'when there are active issues' do
let(:filter) { create :filter, params: { 'type': { 'Issue': 'active' } } }
it 'active issues' do
expect(ical.scan('test message').size).to eq 0
expect(ical.scan(issue.name).size).to eq 2
expect(ical.scan('test article').size).to eq 0
expect(ical.scan('test story').size).to eq 0
expect(ical.scan(task.name).size).to eq 0
end
end
context 'when there are active messages' do
let(:filter) { create :filter, params: { 'type': { 'Message': 'active' } } }
it 'active messages' do
expect(ical.scan('test message').size).to eq 2
expect(ical.scan(issue.name).size).to eq 0
expect(ical.scan('test article').size).to eq 0
expect(ical.scan('test story').size).to eq 0
expect(ical.scan(task.name).size).to eq 0
end
end
context 'when rejecting all' do
let :filter do
create :filter, params: { 'type': { 'Story': 'reject', 'Task': 'reject', 'Topic': 'reject',
'Article': 'reject', 'Message': 'reject', 'Issue': 'reject' } }
end
it 'reject all elements' do
expect(ical.scan('test message').size).to eq 0
expect(ical.scan(issue.name).size).to eq 0
expect(ical.scan('test article').size).to eq 0
expect(ical.scan('test story').size).to eq 0
expect(ical.scan(task.name).size).to eq 0
end
end
context 'when rejecting approved articles' do
let :filter do
create :filter, params: { 'articleStatus': { 'approved': 'reject' }, 'type': { 'Article': 'active' } }
end
it 'active articles and reject approved status' do
expect(ical.scan('test message').size).to eq 0
expect(ical.scan('test article').size).to eq 1
expect(ical.scan('test story').size).to eq 0
expect(ical.scan(task.name).size).to eq 0
expect(ical.scan(issue.name).size).to eq 0
end
end
context 'when there is active category' do
let(:filter) { create :filter, params: { 'category': { '1': 'active' } } }
it 'active category' do
expect(ical.scan('test message').size).to eq 0
expect(ical.scan('test article').size).to eq 1
expect(ical.scan('test story').size).to eq 2
expect(ical.scan(task.name).size).to eq 0
expect(ical.scan(issue.name).size).to eq 0
expect(ical.scan('test Topic').size).to eq 2
end
end
context 'when rejecting topic, language and personas' do
let :filter do
create :filter, params: { 'topic': { '1': 'active', '2': 'reject' },
'language': { '1': 'reject' }, 'personas': { '1': 'reject' } }
end
it 'reject topic_1, language, personas, active topic_2' do
expect(ical.scan('test message').size).to eq 0
expect(ical.scan('test article').size).to eq 0
expect(ical.scan('test story').size).to eq 2
expect(ical.scan(task.name).size).to eq 0
expect(ical.scan('test Topic').size).to eq 2
expect(ical.scan(issue.name).size).to eq 0
end
end
context 'when rejecting issues' do
let(:filter) { create :filter, params: { 'issue': { '2': 'active', '1': 'reject' } } }
it 'reject issue_1 active, issue_2 reject' do
expect(ical.scan('test message').size).to eq 1
expect(ical.scan('test article').size).to eq 1
expect(ical.scan('test story').size).to eq 0
expect(ical.scan(task.name).size).to eq 0
expect(ical.scan('test Topic').size).to eq 0
expect(ical.scan(issue.name).size).to eq 1
end
end
context 'when there is active service' do
let(:filter){ create :filter, params: { 'service': { '1': 'active' } } }
it 'active service' do
expect(ical.scan('test message').size).to eq 3
expect(ical.scan('test article').size).to eq 1
expect(ical.scan('test story').size).to eq 0
expect(ical.scan(task.name).size).to eq 0
expect(ical.scan('test Topic').size).to eq 0
expect(ical.scan(issue.name).size).to eq 0
end
end
context 'when there are active campaign' do
let(:filter) { create :filter, params: { 'story': { '1': 'active' } } }
it 'active campaign' do
expect(ical.scan('test message').size).to eq 0
expect(ical.scan(article_2.name).size).to eq 1
expect(ical.scan(story_1.name).size).to eq 2
expect(ical.scan(task.name).size).to eq 0
expect(ical.scan('test Topic').size).to eq 0
expect(ical.scan(issue.name).size).to eq 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment