Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/filestack_rails/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def filestack_image(url, options = {})
transform_object.add_external_url url
image_tag transform_object.fs_url, options
else
image_tag url
image_tag url, options
end
end

Expand Down
2 changes: 1 addition & 1 deletion filestack-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]

s.add_dependency 'rails', '>= 4.0'
s.add_dependency "filestack", '~> 2.6.0'
s.add_dependency "filestack", '~> 2.6.5'

s.add_development_dependency 'coveralls'
s.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.6'
Expand Down
6 changes: 5 additions & 1 deletion lib/filestack_rails/filestack_js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ def initialize
end

def filestack_js_url
"https://static.filestackapi.com/filestack-js/#{version}/filestack.min.js"
"https://static.#{domain}/filestack-js/#{version}/filestack.min.js"
end

def version
::Rails.application.config.filestack_rails.version
end

def domain
::Rails.application.config.filestack_rails.cname || 'filestackapi.com'
end

def picker(client_name, api_key, options, callback, other_callbacks = nil)
options_string = options[1..-2] # removed curly brackets help to generate pickerOptions in js

Expand Down
8 changes: 7 additions & 1 deletion spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@
end

describe "#filestack_image" do
it "returns the correct tag" do
it "returns the image tag with transformation" do
image = filestack_image 'www.example.com', transform: filestack_transform.resize(width: 100, height: 100)
correct = '<img src="https://cdn.filestackcontent.com/API_KEY/resize=width:100,height:100/www.example.com" />'
expect(image).to eq(correct)
end

it "returns the image tag with attributes" do
image = filestack_image 'https://cdn.filestackcontent.com/7Djkxw9TPyEWdjxILnUQ', size: '16x10'
correct = '<img src="https://cdn.filestackcontent.com/7Djkxw9TPyEWdjxILnUQ" width="16" height="10" />'
expect(image).to eq(correct)
end
end

describe "#get_policy_and_signature" do
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/filestack_js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,18 @@
expect(security).to eq({ security: { signature: signature, policy: policy } }.to_json)
end
end

context 'when cname is configured' do
before do
configuration.cname = 'fs.domain.com'
configuration.version = '3.x.x'
end

it 'returns filestack-js url with cname' do
expect(get_filestack_js.url).to eq(
"https://static.#{configuration.cname}/filestack-js/#{configuration.version}/filestack.min.js"
)
end
end
end
end