spec/factories/generic_works.rb in hyrax-2.1.0.beta1 vs spec/factories/generic_works.rb in hyrax-2.1.0.beta2

- old
+ new

@@ -86,34 +86,98 @@ work.ordered_members << create(:work, user: evaluator.user) end end factory :with_embargo_date do + # build with defaults: + # let(:work) { create(:embargoed_work) } + + # build with specific values: + # let(:embargo_attributes) do + # { embargo_date: Date.tomorrow.to_s, + # current_state: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, + # future_state: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC } + # end + # let(:work) { create(:embargoed_work, with_embargo_attributes: embargo_attributes) } + transient do + with_embargo_attributes false embargo_date { Date.tomorrow.to_s } current_state { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE } future_state { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC } end factory :embargoed_work do - after(:build) { |work, evaluator| work.apply_embargo(evaluator.embargo_date, evaluator.current_state, evaluator.future_state) } + after(:build) do |work, evaluator| + if evaluator.with_embargo_attributes + work.apply_embargo(evaluator.with_embargo_attributes[:embargo_date], + evaluator.with_embargo_attributes[:current_state], + evaluator.with_embargo_attributes[:future_state]) + else + work.apply_embargo(evaluator.embargo_date, + evaluator.current_state, + evaluator.future_state) + end + end end factory :embargoed_work_with_files do - after(:build) { |work, evaluator| work.apply_embargo(evaluator.embargo_date, evaluator.current_state, evaluator.future_state) } + after(:build) do |work, evaluator| + if evaluator.with_embargo_attributes + work.apply_embargo(evaluator.with_embargo_attributes[:embargo_date], + evaluator.with_embargo_attributes[:current_state], + evaluator.with_embargo_attributes[:future_state]) + else + work.apply_embargo(evaluator.embargo_date, + evaluator.current_state, + evaluator.future_state) + end + end after(:create) { |work, evaluator| 2.times { work.ordered_members << create(:file_set, user: evaluator.user) } } end end factory :with_lease_date do + # build with defaults: + # let(:work) { create(:leased_work) } + + # build with specific values: + # let(:lease_attributes) do + # { lease_date: Date.tomorrow.to_s, + # current_state: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC, + # future_state: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED } + # end + # let(:work) { create(:leased_work, with_lease_attributes: lease_attributes) } + transient do + with_lease_attributes false lease_date { Date.tomorrow.to_s } current_state { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC } future_state { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE } end factory :leased_work do - after(:build) { |work, evaluator| work.apply_lease(evaluator.lease_date, evaluator.current_state, evaluator.future_state) } + after(:build) do |work, evaluator| + if evaluator.with_lease_attributes + work.apply_lease(evaluator.with_lease_attributes[:lease_date], + evaluator.with_lease_attributes[:current_state], + evaluator.with_lease_attributes[:future_state]) + else + work.apply_lease(evaluator.lease_date, + evaluator.current_state, + evaluator.future_state) + end + end end factory :leased_work_with_files do - after(:build) { |work, evaluator| work.apply_lease(evaluator.lease_date, evaluator.current_state, evaluator.future_state) } + after(:build) do |work, evaluator| + if evaluator.with_lease_attributes + work.apply_lease(evaluator.with_lease_attributes[:lease_date], + evaluator.with_lease_attributes[:current_state], + evaluator.with_lease_attributes[:future_state]) + else + work.apply_lease(evaluator.lease_date, + evaluator.current_state, + evaluator.future_state) + end + end after(:create) { |work, evaluator| 2.times { work.ordered_members << create(:file_set, user: evaluator.user) } } end end end