ENV or > ENV["key"]
rails generate controller home index --no-helper --no-assets --no-controller-specs --no-view-specs --no-test-framework --skip-test-unit --skip-template-engine
- single quotes
'Hello %{name}' %{name:"World"}
NOTE: If we have something like this
'Hello %{name} got 100% hike`
This will create error so we need to write
'Hello %{name} got 100%%' %{name:"John"}
- double quotes
name="World"
"Hello #{name}"
- Task
@path lib/tasks/upwork.rake
# @author Sibin Xavier
# @use Upwork Data Parsing
# @description RAKE TASK TO PARSE UPWORK
# RSS FIELD AND SAVE TO DATABASE TABLE
#
namespace :admin do
desc 'Get upwork url'
task upwork_url: :environment do
UPWORK_URL= Rails.application.secrets.upwork_url
end
desc 'Parse Upwork RSS feed and save on database'
task upwork_rss_parse: [:upwork_url] do
begin
puts "UPWORK URL #{UPWORK_URL}"
rescue => e
puts e.inspect
end
end
end
- Testing @path : spec/lib/tasks/upwork_spec.rb
require 'spec_helper'
require 'rails_helper'
require 'rake'
describe "upwork rake task" do
before do
# load File.expand_path(Rails.root.join("lib","tasks","upwork.rake"))
MyApp::Application.load_tasks #look at config/application.rb and use module name
Rake::Task.define_task(:environment)
end
it "should find secrets url" do
Rake::Task["admin:upwork_url"].invoke
expect(UPWORK_URL).to eq(Rails.application.secrets.upwork_url)
end
end