spec/features/datastreams/show.html.erb_spec.rb in fcrepo_admin-0.4.1 vs spec/features/datastreams/show.html.erb_spec.rb in fcrepo_admin-0.5.0
- old
+ new
@@ -4,35 +4,67 @@
Warden.test_mode!
end
describe "datastreams/show.html.erb" do
let!(:object) { FactoryGirl.create(:item) }
- let(:dsid) { "descMetadata" }
- before { visit fcrepo_admin.object_datastream_path(object, dsid) }
after { object.delete }
- it "should display all attributes of the datastream profile" do
- profile = object.datastreams[dsid].profile
- profile.each do |key, value|
- # TODO use paths
- page.should have_content(I18n.t("fcrepo_admin.datastream.profile.#{key}"))
+ context "user can read" do
+ before { visit fcrepo_admin.object_datastream_path(object, datastream) }
+ context "content is text" do
+ let(:datastream) { object.descMetadata }
+ it "should display all attributes of the datastream profile" do
+ datastream.profile.each do |key, value|
+ page.should have_content(I18n.t("fcrepo_admin.datastream.profile.keys.#{key}"))
+ end
+ end
+ it "should have a link to download the datastream content" do
+ page.should have_link(I18n.t("fcrepo_admin.datastream.nav.items.content"), :href => fcrepo_admin.content_object_datastream_path(object, datastream))
+ end
+ it "should have a link to view the content" do
+ page.should have_link(I18n.t("fcrepo_admin.datastream.nav.items.content"), :href => fcrepo_admin.content_object_datastream_path(object, datastream))
+ end
end
+ context "content is not text" do
+ let(:datastream) { object.content }
+ before do
+ datastream.content = File.read(File.join(Rails.root, "spec", "fixtures", "files", "hydra.jpg"), {mode: 'rb'})
+ object.save
+ end
+ it "should not have a link to view the content" do
+ page.should_not have_link(I18n.t("fcrepo_admin.datastream.nav.items.content"), :href => fcrepo_admin.content_object_datastream_path(object, datastream))
+ end
+ end
end
- it "should have a link to download the datastream content" do
- page.should have_link(I18n.t("fcrepo_admin.datastream.download"), :href => fcrepo_admin.download_object_datastream_path(object, dsid))
+ context "user cannot edit" do
+ let(:datastream) { object.descMetadata }
+ before { visit fcrepo_admin.object_datastream_path(object, datastream) }
+ it "should not have links to edit or upload" do
+ page.should_not have_link(I18n.t("fcrepo_admin.datastream.nav.items.edit"), :href => fcrepo_admin.edit_object_datastream_path(object, datastream))
+ page.should_not have_link(I18n.t("fcrepo_admin.datastream.nav.items.upload"), :href => fcrepo_admin.upload_object_datastream_path(object, datastream))
+ end
end
context "user can edit" do
let(:user) { FactoryGirl.create(:user) }
before do
object.permissions = [{type: 'user', name: user.email, access: 'edit'}]
object.save
login_as(user, :scope => :user, :run_callbacks => false)
- visit fcrepo_admin.object_datastream_path(object, dsid)
+ visit fcrepo_admin.object_datastream_path(object, datastream)
end
after do
user.delete
Warden.test_reset!
end
- it "should have a link to the edit page" do
- page.should have_link("", :href => fcrepo_admin.edit_object_datastream_path(object, dsid))
+ context "datastream content is editable" do
+ let(:datastream) { object.descMetadata }
+ it "should have an edit link" do
+ page.should have_link(I18n.t("fcrepo_admin.datastream.nav.items.edit"), :href => fcrepo_admin.edit_object_datastream_path(object, datastream))
+ end
+ end
+ context "datastream content is uploadable" do
+ let(:datastream) { object.descMetadata }
+ it "should have an upload link" do
+ page.should have_link(I18n.t("fcrepo_admin.datastream.nav.items.upload"), :href => fcrepo_admin.upload_object_datastream_path(object, datastream))
+ end
end
end
end