hydra-batch-edit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,2 +1,40 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ ENV["RAILS_ROOT"] = 'spec/internal'
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
9
+
10
+ desc "Run specs"
11
+ RSpec::Core::RakeTask.new(:spec => :generate) do |t|
12
+ t.rspec_opts = "--colour"
13
+ end
14
+
15
+
16
+ describe "Create the test rails app"
17
+ task :generate do
18
+ unless File.exists?('spec/internal/Rakefile')
19
+ puts "Generating rails app"
20
+ `rails new spec/internal`
21
+ puts "Copying gemfile"
22
+ `cp spec/support/Gemfile spec/internal`
23
+ puts "Copying generator"
24
+ `cp -r spec/support/lib/generators spec/internal/lib`
25
+
26
+ FileUtils.cd('spec/internal')
27
+ puts "Bundle install"
28
+ `bundle install`
29
+ puts "running generator"
30
+ puts `rails generate test_app`
31
+ FileUtils.cd('../..')
32
+ end
33
+ puts "Running specs"
34
+ end
35
+
36
+ describe "Clean out the test rails app"
37
+ task :clean do
38
+ puts "Removing sample rails app"
39
+ `rm -rf spec/internal`
40
+ end
@@ -14,4 +14,8 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "hydra-batch-edit"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Hydra::BatchEdit::VERSION
17
+
18
+ gem.add_development_dependency 'rake'
19
+ gem.add_development_dependency 'rails'
20
+ gem.add_development_dependency 'rspec-rails'
17
21
  end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module BatchEdit
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/spec/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /internal
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ describe BatchEditsController do
4
+ before :all do
5
+ module ActiveFedora
6
+ module Base; end
7
+ end
8
+ end
9
+ before(:each) do
10
+ request.env["HTTP_REFERER"] = "/"
11
+ end
12
+
13
+ it "should add items to list" do
14
+ @mock_response = mock()
15
+ @mock_document = mock()
16
+ @mock_document2 = mock()
17
+ @mock_document.stub(:export_formats => {})
18
+ controller.stub(:get_solr_response_for_field_values => [@mock_response, [@mock_document, @mock_document2]])
19
+
20
+ put :add, :id =>"77826928"
21
+ session[:batch_document_ids].length.should == 1
22
+ put :add, :id => "94120425"
23
+ session[:batch_document_ids].length.should == 2
24
+ session[:batch_document_ids].should include("77826928")
25
+ get :index
26
+ assigns[:documents].length.should == 2
27
+ assigns[:documents].first.should == @mock_document
28
+ end
29
+ it "should delete an item from list" do
30
+ put :add, :id =>"77826928"
31
+ put :add, :id => "94120425"
32
+ delete :destroy, :id =>"77826928"
33
+ session[:batch_document_ids].length.should == 1
34
+ session[:batch_document_ids].should_not include("77826928")
35
+ end
36
+ it "should clear list" do
37
+ put :add, :id =>"77826928"
38
+ put :add, :id => "94120425"
39
+ put :clear
40
+ session[:batch_document_ids].length.should == 0
41
+ end
42
+
43
+ it "should generate flash messages for normal requests" do
44
+ put :add, :id => "77826928"
45
+ flash[:notice].length.should_not == 0
46
+ end
47
+ it "should clear flash messages after xhr request" do
48
+ xhr :put, :add, :id => "77826928"
49
+ flash[:notice].should == nil
50
+ end
51
+
52
+ describe "edit" do
53
+ before do
54
+ @one = Sample.new
55
+ @two = Sample.new
56
+ @one.save
57
+ @two.save
58
+ end
59
+ it "should draw the form" do
60
+ put :add, :id =>@one.pid
61
+ put :add, :id =>@two.pid
62
+ controller.should_receive(:can?).with(:edit, @one.pid).and_return(true)
63
+ controller.should_receive(:can?).with(:edit, @two.pid).and_return(true)
64
+ get :edit
65
+ response.should be_successful
66
+
67
+ end
68
+ end
69
+
70
+
71
+ describe "update" do
72
+ before :all do
73
+ @one = Sample.create
74
+ @two = Sample.create
75
+ end
76
+ before do
77
+ controller.stub(:catalog_index_path).and_return('/catalog')
78
+ end
79
+ it "should complain when none are in the batch " do
80
+ put :update, :multiresimage=>{:titleSet_display=>'My title' }
81
+ response.should redirect_to '/catalog'
82
+ flash[:notice].should == "Select something first"
83
+ end
84
+ it "should not update when the user doesn't have permissions" do
85
+ put :add, :id =>@one.pid
86
+ put :add, :id => @two.pid
87
+ controller.should_receive(:can?).with(:edit, @one.pid).and_return(false)
88
+ controller.should_receive(:can?).with(:edit, @two.pid).and_return(false)
89
+ put :update, :multiresimage=>{:titleSet_display=>'My title' }
90
+ response.should redirect_to '/catalog'
91
+ flash[:notice].should == "You do not have permission to edit the documents: #{@one.pid}, #{@two.pid}"
92
+ end
93
+ describe "when current user has access to the documents" do
94
+ before do
95
+ @one.save
96
+ @two.save
97
+ put :add, :id =>@one.pid
98
+ put :add, :id => @two.pid
99
+ end
100
+ it "should update all the field" do
101
+ controller.should_receive(:can?).with(:edit, @one.pid).and_return(true)
102
+ controller.should_receive(:can?).with(:edit, @two.pid).and_return(true)
103
+ ActiveFedora::Base.should_receive(:find).with( @one.pid, :cast=>true).and_return(@one)
104
+ ActiveFedora::Base.should_receive(:find).with( @two.pid, :cast=>true).and_return(@two)
105
+ put :update, :sample=>{:titleSet_display=>'My title' }
106
+ response.should redirect_to '/catalog'
107
+ flash[:notice].should == "Batch update complete"
108
+ Sample.find(@one.pid).titleSet_display.should == "My title"
109
+ end
110
+ end
111
+ end
112
+
113
+
114
+ describe "state" do
115
+ it "should save state on" do
116
+ xhr :put, :state, :state=>'on'
117
+ response.should be_successful
118
+ session[:batch_edit_state].should == 'on'
119
+ end
120
+ it "should save state off" do
121
+ xhr :put, :state, :state=>'off'
122
+ response.should be_successful
123
+ session[:batch_edit_state].should == 'off'
124
+ end
125
+ end
126
+
127
+
128
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe BatchEditHelper do
4
+ describe "batch_edit_active?" do
5
+ it "when nil" do
6
+ helper.batch_edit_state.should == 'off'
7
+ end
8
+ it "should be off" do
9
+ session[:batch_edit_state] = 'off'
10
+ helper.batch_edit_state.should == 'off'
11
+ end
12
+ it "should be on" do
13
+ session[:batch_edit_state] = 'on'
14
+ helper.batch_edit_state.should == 'on'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+
5
+ require File.expand_path("config/environment", ENV['RAILS_ROOT'] || File.expand_path("../internal", __FILE__))
6
+ require 'rspec/rails'
7
+ require 'hydra-batch-edit'
8
+
9
+
10
+
11
+ RSpec.configure do |config|
12
+ config.use_transactional_fixtures = true
13
+ end
@@ -0,0 +1,26 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '3.2.6'
4
+
5
+ # Bundle edge Rails instead:
6
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
+
8
+ gem 'sqlite3'
9
+
10
+
11
+ # Gems used only for assets and not required
12
+ # in production environments by default.
13
+ group :assets do
14
+ gem 'sass-rails', '~> 3.2.3'
15
+ gem 'coffee-rails', '~> 3.2.1'
16
+
17
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
18
+ # gem 'therubyracer', :platforms => :ruby
19
+
20
+ gem 'uglifier', '>= 1.0.3'
21
+ end
22
+
23
+ gem 'jquery-rails'
24
+
25
+ gem 'hydra-batch-edit', :path=>'../../'
26
+ gem 'rspec-rails'
@@ -0,0 +1,34 @@
1
+ class Sample
2
+ # This is a stub model for testing.
3
+
4
+ cattr_accessor :objects
5
+ self.objects = {}
6
+
7
+ def self.create(params={})
8
+ obj = Sample.new
9
+ obj.save
10
+ obj
11
+ end
12
+
13
+ def save()
14
+ @pid ||= "sample:#{(rand * 1000).to_i}"
15
+ self.class.objects[@pid] = self
16
+ end
17
+
18
+ def update_attributes(attributes)
19
+ metaclass = class << self; self; end
20
+ attributes.each do |k, v|
21
+ metaclass.send(:define_method, k) do
22
+ v
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.find(pid)
28
+ objects[pid]
29
+ end
30
+
31
+ def pid
32
+ @pid
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails/generators'
2
+
3
+ class TestAppGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../../../support", __FILE__)
5
+
6
+ # Inject call to Hydra::BatchEdit.add_routes in config/routes.rb
7
+ def inject_routes
8
+ insert_into_file "config/routes.rb", :after => '.draw do' do
9
+ "\n # Add BatchEdit routes."
10
+ "\n Hydra::BatchEdit.add_routes(self)"
11
+ end
12
+ end
13
+
14
+ def copy_test_models
15
+ copy_file "app/models/sample.rb"
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-batch-edit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,56 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-15 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2012-06-18 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rails
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
15
63
  description: Rails engine to do batch editing with hydra-head
16
64
  email:
17
65
  - justin.coyne@yourmediashelf.com
@@ -37,6 +85,13 @@ files:
37
85
  - lib/hydra/batch_edit/routes.rb
38
86
  - lib/hydra/batch_edit/version.rb
39
87
  - lib/hydra/batch_edit_behavior.rb
88
+ - spec/.gitignore
89
+ - spec/controllers/batch_edits_controller_spec.rb
90
+ - spec/helpers/batch_edit_helper_spec.rb
91
+ - spec/spec_helper.rb
92
+ - spec/support/Gemfile
93
+ - spec/support/app/models/sample.rb
94
+ - spec/support/lib/generators/test_app_generator.rb
40
95
  - vendor/assets/javascripts/batch_edit.js.coffee
41
96
  - vendor/assets/stylesheets/batch_edit.css.scss
42
97
  homepage: https://github.com/projecthydra/hydra-batch-edit
@@ -59,8 +114,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
114
  version: '0'
60
115
  requirements: []
61
116
  rubyforge_project:
62
- rubygems_version: 1.8.24
117
+ rubygems_version: 1.8.21
63
118
  signing_key:
64
119
  specification_version: 3
65
120
  summary: Rails engine to do batch editing with hydra-head
66
- test_files: []
121
+ test_files:
122
+ - spec/.gitignore
123
+ - spec/controllers/batch_edits_controller_spec.rb
124
+ - spec/helpers/batch_edit_helper_spec.rb
125
+ - spec/spec_helper.rb
126
+ - spec/support/Gemfile
127
+ - spec/support/app/models/sample.rb
128
+ - spec/support/lib/generators/test_app_generator.rb