Repository URL to install this package:
Version:
2.23.0 ▾
|
require 'spec_helper'
describe JPlatform::Project::Post, :type => :model do
post_message = JPlatform::Project::Post::Message.new(social_account_id: 1, message: "foo")
before(:each) do
subject.messages = [post_message] # Is there a better way to set the attribute of the implicit subject?
end
context "validation" do
describe "checks the format of the scheduled_time if present" do
it "returns invalid when time is not valid" do
subject.post_time = "24:70 AM"
expect(subject.valid?).to be_falsey
end
it "returns valid when time is valid" do
subject.post_time = "23:24 AM"
expect(subject.valid?).to be_truthy
end
end
describe "message text" do
after(:each) do
#Sanatize (since this parameter won't reset after tests (not part of subject?))
post_message.message = "foo"
end
it "must not be blank" do
subject.messages.first.message = " "
expect(subject.valid?).to be_falsey
end
end
end
describe "set_scheduled_time_to_utc" do
before(:each) do
subject.post_time = "23:24 PM"
stub_post("/api/v1/posts.json").to_return(body: fixture("post.json"), headers: {content_type: "application/json; charset=utf-8"})
end
it "returns false if scheduled time is less than current time" do
subject.post_time = 1.hour.ago.to_s
subject.save
expect(subject.errors.full_messages.first).to eq(I18n.t('schedule.date_time_less_than_now'))
end
it "returns utc time" do
subject.save
expect(subject.scheduled_time).is_a? Time
expect(subject.scheduled_time).to eq(Time.zone.parse("23:24 PM").utc.to_s)
end
it "returns utc time with time zone" do
subject.post_timezone = "Pacific Time (US & Canada)"
subject.save
pt = ActiveSupport::TimeZone.new("Pacific Time (US & Canada)")
expect(subject.scheduled_time).is_a? Time
expect(subject.scheduled_time).to eq(pt.parse("23:24 PM").utc.to_s)
end
end
end