Permalink
Browse files

Move appropriate tests into the right dists, and split out Makefile.PL's

git-svn-id: svn+ssh://svn.bestpractical.com/svn/jifty.org/jifty/trunk@6464 e84bef0a-9b06-0410-84ba-c4c9edb13aeb
  • Loading branch information...
1 parent 26e15c2 commit 1da150ac997239f316e1aab5085405f796317072 @alexmv alexmv committed Feb 25, 2009
View
@@ -0,0 +1,10 @@
+use inc::Module::Install 0.46;
+name('Jifty-Plugin-Attributes');
+version_from('lib/Jifty/Plugin/Attributes.pm');
+
+requires('Jifty');
+
+auto_install();
+tests(qw( t/*/t/*.t ));
+
+WriteAll;
@@ -0,0 +1,7 @@
+use inc::Module::Install;
+
+name 'TestApp-Plugin-Attributes';
+version '0.01';
+requires 'Jifty' => '0.71129';
+
+WriteAll;
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use File::Basename qw(dirname);
+use UNIVERSAL::require;
+
+use Jifty;
+use Jifty::Script;
+
+local $SIG{INT} = sub { warn "Stopped\n"; exit; };
+Jifty::Script->dispatch();
@@ -0,0 +1,60 @@
+---
+framework:
+ AdminMode: 1
+ ApplicationClass: TestApp::Plugin::Attributes
+ ApplicationName: TestApp-Plugin-Attributes
+ ApplicationUUID: CCAA95B8-D400-11DC-990A-966E8CB3492A
+ ConfigFileVersion: 3
+ Database:
+ AutoUpgrade: 1
+ CheckSchema: 1
+ Database: testapp_plugin_attributes
+ Driver: SQLite
+ Host: localhost
+ Password: ''
+ RecordBaseClass: Jifty::DBI::Record::Cachable
+ User: ''
+ Version: 0.0.1
+ DevelMode: 1
+ L10N:
+ PoDir: share/po
+ LogLevel: INFO
+ Mailer: Sendmail
+ MailerArgs: []
+
+ Plugins:
+ - AdminUI: {}
+ - CompressedCSSandJS: {}
+ - ErrorTemplates: {}
+ - Halo: {}
+ - LetMe: {}
+ - OnlineDocs: {}
+ - REST: {}
+ - SkeletonApp: {}
+
+ - Attributes: {}
+
+ PubSub:
+ Backend: Memcached
+ Enable: ~
+ SkipAccessControl: 0
+ TemplateClass: TestApp::Plugin::Attributes::View
+ View:
+ Handlers:
+ - Jifty::View::Static::Handler
+ - Jifty::View::Declare::Handler
+ - Jifty::View::Mason::Handler
+ Web:
+ BaseURL: http://localhost
+ DataDir: var/mason
+ Globals: []
+
+ MasonConfig:
+ autoflush: 0
+ default_escape_flags: h
+ error_format: text
+ error_mode: fatal
+ Port: 8888
+ ServeStaticFiles: 1
+ StaticRoot: share/web/static
+ TemplateRoot: share/web/templates
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+package TestApp::Plugin::Attributes::Model::Song;
+use strict;
+use warnings;
+
+use Jifty::Plugin::Attributes::Mixin::Attributes;
+use Jifty::DBI::Schema;
+use Jifty::Record schema {
+ column 'name' =>
+ type is 'text',
+ is mandatory;
+
+ column 'artist' =>
+ type is 'text',
+ is mandatory;
+
+ column 'album' =>
+ type is 'text',
+ is mandatory;
+};
+
+our %rights;
+
+sub current_user_can {
+ my $self = shift;
+ my $right = shift;
+ my %args = @_;
+
+ return $rights{$right} if exists $rights{$right};
+
+ $self->SUPER::current_user_can($right, @_);
+}
+
+sub set_right {
+ my $self = shift;
+ my $right = shift;
+ my $val = shift;
+
+ return delete $rights{$right} if !defined($val);
+ $rights{$right} = $val;
+}
+
+1;
+
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use Jifty::Test::Dist tests => 12;
+
+my $song = TestApp::Plugin::Attributes::Model::Song->new;
+my ($ok, $msg) = $song->create(
+ name => 'Arco Arena',
+ artist => 'Cake',
+ album => 'Comfort Eagle',
+);
+ok($ok, $msg);
+
+can_ok($song, qw/attributes first_attribute add_attribute set_attribute delete_attribute/);
+
+is($song->first_attribute('instrumental'), undef, "unknown attributes return undef for ->first_attribute");
+
+my $attrs = $song->attributes;
+isa_ok($attrs, "Jifty::Plugin::Attributes::Model::AttributeCollection", "->attributes returns an AttributeCollection");
+can_ok($attrs, qw/named limit_to_object/);
+
+ok($song->set_attribute(
+ name => 'is_instrumental',
+ description => 'Is this song an instrumental?',
+ content => 1,
+));
+
+my $attr = $song->first_attribute('is_instrumental');
+can_ok($attr, qw/name description content object_type object_id object/);
+
+is($attr->name, 'is_instrumental', "name of the attribute was saved");
+is($attr->description, 'Is this song an instrumental?', "description of the attribute was saved");
+is($attr->content, 1, "content of the attribute was saved");
+
+my $song2 = TestApp::Plugin::Attributes::Model::Song->new;
+($ok, $msg) = $song2->create(
+ name => 'A Passage to Bangkok',
+ artist => 'Rush',
+ album => '2112',
+);
+ok($ok, $msg);
+
+ok(!defined($song2->first_attribute('is_instrumental')), "second song has no is_instrumental attribute");
+
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use Jifty::Test::Dist tests => 7;
+
+my $song = TestApp::Plugin::Attributes::Model::Song->new;
+my ($ok, $msg) = $song->create(
+ name => 'Home',
+ artist => 'Dream Theater',
+ album => 'Scenes from a Memory',
+);
+ok($ok, $msg);
+
+$song->add_attribute(name => 'artists', content => [qw/LaBrie Myung Petrucci Portroy Rudess/]);
+is_deeply($song->first_attribute('artists')->content, [qw/LaBrie Myung Petrucci Portroy Rudess/], "attribute content can be an arrayref");
+
+$song->add_attribute(name => 'guests', content => {Thomason => "additional vocals", Brown => "hypnotherapist"});
+is_deeply($song->first_attribute('guests')->content, {Thomason => "additional vocals", Brown => "hypnotherapist"}, "attribute content can be a hashref");
+
+is($song->attributes->count, 2, "two attributes");
+is($song->attributes->named('artists')->count, 1, "one attribute named artists");
+is($song->attributes->named('guests')->count, 1, "one attribute named guests");
+
+my $complex = {
+ a => [qw/a b c/],
+ b => {
+ c => 'd',
+ e => [qw/f g h/],
+ i => {
+ j => 'k',
+ l => 'm',
+ },
+ n => [],
+ },
+ o => undef,
+};
+
+$song->add_attribute(
+ name => 'complex',
+ content => $complex,
+);
+
+is_deeply($song->first_attribute('complex')->content, $complex, "complex content can be saved");
+
@@ -0,0 +1,51 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use Jifty::Test::Dist tests => 8;
+
+my $song = TestApp::Plugin::Attributes::Model::Song->new;
+my ($ok, $msg) = $song->create(
+ name => 'Backdrifts',
+ artist => 'Radiohead',
+ album => 'Hail to the Thief',
+);
+ok($ok, $msg);
+
+$song->add("radiohead");
+$song->has_tags(qw/radiohead/);
+
+$song->add("2003");
+$song->has_tags(qw/radiohead 2003/);
+
+$song->set("httt");
+$song->has_tags(qw/httt/);
+
+$song->add("radiohead");
+$song->has_tags(qw/httt radiohead/);
+
+$song->add("2003");
+$song->has_tags(qw/httt radiohead 2003/);
+
+$song->delete_attribute('tag');
+$song->has_tags(qw//);
+
+$song->add("radiohead");
+$song->has_tags(qw/radiohead/);
+
+sub TestApp::Plugin::Attributes::Model::Song::add {
+ $_[0]->add_attribute(name => 'tag', content => $_[1]);
+}
+
+sub TestApp::Plugin::Attributes::Model::Song::set {
+ $_[0]->set_attribute(name => 'tag', content => $_[1]);
+}
+
+sub TestApp::Plugin::Attributes::Model::Song::has_tags {
+ my $self = shift;
+ my %expected = map { $_ => 1 } @_;
+ my %got = map { $_->content => 1 }
+ @{ $self->attributes->named("tag")->items_array_ref };
+
+ ::is_deeply(\%got, \%expected, "attributes set correctly");
+}
+
@@ -0,0 +1,54 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use Jifty::Test::Dist tests => 30;
+
+my $song = TestApp::Plugin::Attributes::Model::Song->new;
+my ($ok, $msg) = $song->create(
+ name => 'Hysteria',
+ artist => 'Muse',
+ album => 'Absolution',
+);
+ok($ok, $msg);
+
+ok($song->add_attribute(name => 'stars', content => 5), "can add attributes");
+my $attr = $song->first_attribute('stars');
+
+has_right($_) for qw/create read update delete/;
+
+$song->set_right(create => 0);
+has_right($_) for qw/create read update delete/;
+
+$song->set_right(delete => 0);
+has_right($_) for qw/create read update delete/;
+
+$song->set_right(update => 0);
+lacks_right($_, "$_ checks object's update right") for qw/create update delete/;
+has_right('read', "read checks object's read right");
+
+$song->set_right(read => 0);
+lacks_right($_) for qw/create read update delete/;
+
+$song->set_right(update => undef);
+has_right($_, "$_ checks object's update right") for qw/create update delete/;
+lacks_right('read', "read checks object's read right");
+
+$song->set_right(read => undef);
+has_right($_) for qw/create read update delete/;
+
+sub has_right {
+ my $right = shift;
+ my $has_right = $attr->current_user_can($right, object => $song);
+
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ ok($has_right, shift || "current_user_can $right");
+}
+
+sub lacks_right {
+ my $right = shift;
+ my $has_right = $attr->current_user_can($right, object => $song);
+
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ ok(!$has_right, shift || "current_user_cannot $right");
+}
+
Oops, something went wrong.

0 comments on commit 1da150a

Please sign in to comment.