npo_assets 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/generators/npo_assets/npo_assets_generator.rb +20 -0
- data/{generators → lib/generators}/npo_assets/templates/initializer.rb +0 -0
- data/{generators → lib/generators}/npo_assets/templates/migration.rb +1 -0
- data/lib/npo_assets/asset.rb +3 -0
- data/npo_assets.gemspec +5 -5
- data/spec/npo_assets/asset_spec.rb +20 -3
- data/spec/spec_helper.rb +2 -1
- metadata +8 -8
- data/generators/npo_assets/npo_assets_generator.rb +0 -8
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class NpoAssetsGenerator < Rails::Generators::Base
|
2
|
+
include Rails::Generators::Migration
|
3
|
+
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
# Implement the required interface for Rails::Generators::Migration.
|
7
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
8
|
+
def self.next_migration_number(dirname)
|
9
|
+
if ActiveRecord::Base.timestamped_migrations
|
10
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
11
|
+
else
|
12
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_npo_assets
|
17
|
+
migration_template('migration.rb', 'db/migrate/create_assets.rb')
|
18
|
+
copy_file('initializer.rb', 'config/initializers/npo_assets.rb')
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
data/lib/npo_assets/asset.rb
CHANGED
@@ -75,6 +75,9 @@ module NPO
|
|
75
75
|
vars['errors']['error'].each { |msg| errors.add_to_base(msg) }
|
76
76
|
false
|
77
77
|
else
|
78
|
+
if self.respond_to?(:original_url=) && attrs[:url]
|
79
|
+
self.original_url = attrs[:url]
|
80
|
+
end
|
78
81
|
self.url = vars['asset']['url']
|
79
82
|
self.remote_id = vars['asset']['id']
|
80
83
|
true
|
data/npo_assets.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{npo_assets}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bart Zonneveld"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-08-16}
|
13
13
|
s.description = %q{Wrapper for media db}
|
14
14
|
s.email = %q{loop@superinfinite.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -22,9 +22,9 @@ Gem::Specification.new do |s|
|
|
22
22
|
"README.rdoc",
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION",
|
25
|
-
"generators/npo_assets/npo_assets_generator.rb",
|
26
|
-
"generators/npo_assets/templates/initializer.rb",
|
27
|
-
"generators/npo_assets/templates/migration.rb",
|
25
|
+
"lib/generators/npo_assets/npo_assets_generator.rb",
|
26
|
+
"lib/generators/npo_assets/templates/initializer.rb",
|
27
|
+
"lib/generators/npo_assets/templates/migration.rb",
|
28
28
|
"lib/npo_assets.rb",
|
29
29
|
"lib/npo_assets/asset.rb",
|
30
30
|
"npo_assets.gemspec",
|
@@ -64,7 +64,24 @@ describe NPO::Assets::Asset do
|
|
64
64
|
do_create
|
65
65
|
@asset.attributes['remote_id'].should == 1
|
66
66
|
end
|
67
|
+
|
68
|
+
describe "with original url column" do
|
69
|
+
it "should assign the original url to the asset" do
|
70
|
+
@asset = NPO::Assets::Asset.new(:remote_url => "my_remote_image")
|
71
|
+
do_create
|
72
|
+
@asset.attributes['original_url'].should == "my_remote_image"
|
73
|
+
end
|
74
|
+
end
|
67
75
|
|
76
|
+
describe "without original url column" do
|
77
|
+
it "should not assign the original url to the asset" do
|
78
|
+
@asset = NPO::Assets::Asset.new(:remote_url => "my_remote_image")
|
79
|
+
@asset.stub!(:respond_to?).and_return false
|
80
|
+
do_create
|
81
|
+
@asset.attributes['original_url'].should be_nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
68
85
|
it "should save the asset" do
|
69
86
|
do_create
|
70
87
|
@asset.should_not be_new_record
|
@@ -263,10 +280,10 @@ describe NPO::Assets::Asset do
|
|
263
280
|
|
264
281
|
it "should save the assets with the correct attributes" do
|
265
282
|
do_list
|
266
|
-
NPO::Assets::Asset.first.attributes.should == {"remote_id" => 10, "url" => "000/000/001.jpg", "id" => 1}
|
267
|
-
NPO::Assets::Asset.last.attributes.should == {"remote_id" => 20, "url" => "000/000/002.jpg", "id" => 2}
|
283
|
+
NPO::Assets::Asset.first.attributes.should == {"remote_id" => 10, "url" => "000/000/001.jpg", "id" => 1, "original_url"=>nil}
|
284
|
+
NPO::Assets::Asset.last.attributes.should == {"remote_id" => 20, "url" => "000/000/002.jpg", "id" => 2, "original_url"=>nil}
|
268
285
|
end
|
269
|
-
|
286
|
+
|
270
287
|
it "should return the created objects" do
|
271
288
|
do_list.should == NPO::Assets::Asset.all
|
272
289
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,7 @@ require 'spec/autorun'
|
|
10
10
|
begin
|
11
11
|
require 'sqlite3'
|
12
12
|
rescue MissingSourceFile => e
|
13
|
-
puts "Gem sqlite3
|
13
|
+
puts "Gem sqlite3 could not be found, please install it"
|
14
14
|
exit
|
15
15
|
end
|
16
16
|
|
@@ -23,6 +23,7 @@ def setup_db
|
|
23
23
|
ActiveRecord::Schema.define(:version => 1) do
|
24
24
|
create_table :assets do |t|
|
25
25
|
t.string :url
|
26
|
+
t.text :original_url
|
26
27
|
t.integer :remote_id
|
27
28
|
end
|
28
29
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: npo_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bart Zonneveld
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-16 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -63,9 +63,9 @@ files:
|
|
63
63
|
- README.rdoc
|
64
64
|
- Rakefile
|
65
65
|
- VERSION
|
66
|
-
- generators/npo_assets/npo_assets_generator.rb
|
67
|
-
- generators/npo_assets/templates/initializer.rb
|
68
|
-
- generators/npo_assets/templates/migration.rb
|
66
|
+
- lib/generators/npo_assets/npo_assets_generator.rb
|
67
|
+
- lib/generators/npo_assets/templates/initializer.rb
|
68
|
+
- lib/generators/npo_assets/templates/migration.rb
|
69
69
|
- lib/npo_assets.rb
|
70
70
|
- lib/npo_assets/asset.rb
|
71
71
|
- npo_assets.gemspec
|