Skip to content

Commit

Permalink
more work on getting SQLite support up and running; only 2 failing te…
Browse files Browse the repository at this point in the history
…sts left
  • Loading branch information
mpeters committed Mar 28, 2006
1 parent 7b45122 commit 87e0b12
Show file tree
Hide file tree
Showing 31 changed files with 311 additions and 207 deletions.
2 changes: 1 addition & 1 deletion lib/Smolder.pm
@@ -1,5 +1,5 @@
package Smolder;

our $VERSION = '0.1';
our $VERSION = '0.2';

1;
8 changes: 5 additions & 3 deletions lib/Smolder/Control/Admin/Developers.pm
Expand Up @@ -6,7 +6,9 @@ use Smolder::DB::Project;
use Smolder::DB::Developer;
use Smolder::Email;
use Smolder::Constraints qw(email unsigned_int length_max length_between bool unique_field_value);
use Smolder::DBPlatform;
use Email::Valid;
my $DB_PLATFORM = Smolder::DBPlatform->load();

sub setup {
my $self = shift;
Expand Down Expand Up @@ -113,7 +115,7 @@ sub process_edit {
if ($@) {

# if it was a duplicate developer, then we can handle that
if ( $@ =~ /Duplicate entry/ ) {
if ( $DB_PLATFORM->unique_failure_msg($@) ) {
return $self->add( { err_unique_username => 1 } );

# else it's something else, so just throw it again
Expand Down Expand Up @@ -173,7 +175,7 @@ sub process_add {
my $valid = $results->valid();

# create a new preference for this developer;
my $pref = Smolder::DB::Preference->create( {} );
my $pref = Smolder::DB::Preference->create( { email_type => 'full', email_freq => 'on_new'} );
$valid->{preference} = $pref;
my $developer;

Expand All @@ -184,7 +186,7 @@ sub process_add {
if ($@) {

# if it was a duplicate developer, then we can handle that
if ( $@ =~ /Duplicate entry/ ) {
if ( $DB_PLATFORM->unique_failure_msg($@) ) {
return $self->add( { err_unique_username => 1 } );

# else it's something else, so just throw it again
Expand Down
8 changes: 5 additions & 3 deletions lib/Smolder/Control/Admin/Projects.pm
Expand Up @@ -13,6 +13,8 @@ use Smolder::Constraints qw(
use Smolder::DB::Project;
use Smolder::DB::Developer;
use Smolder::DB::ProjectDeveloper;
use Smolder::DBPlatform;
my $DB_PLATFORM = Smolder::DBPlatform->load();

sub setup {
my $self = shift;
Expand Down Expand Up @@ -77,13 +79,13 @@ sub add_developer {
);
};
if ($@) {
die $@ unless $@ =~ /Duplicate entry/i;
die $@ unless $DB_PLATFORM->unique_failure_msg($@);
} else {
Smolder::DB->dbi_commit();
}
}

return $self->tt_process( 'Admin/Projects/project_container.tmpl', { project => $project, } );
return $self->tt_process( 'Admin/Projects/project_container.tmpl', { project => $project } );
}

sub remove_developer {
Expand Down Expand Up @@ -198,7 +200,7 @@ sub process_add {
if ($@) {

# if it was a duplicate project name, then we can handle that
if ( $@ =~ /Duplicate entry/ ) {
if ( $DB_PLATFORM->unique_failure_msg($@) ) {
return $self->add( { err_unique_project_name => 1 } );

# else it's something else, so just throw it again
Expand Down
4 changes: 3 additions & 1 deletion lib/Smolder/Control/Developer/Projects.pm
Expand Up @@ -14,11 +14,13 @@ use Smolder::Constraints qw(
file_mtype
);
use Smolder::Conf qw(InstallRoot);
use Smolder::DBPlatform;
use Test::TAP::Model;
use Test::TAP::XML;
use File::Temp;
use File::Spec::Functions qw(catdir catfile);
use File::Copy qw(move);
my $DB_PLATFORM = Smolder::DBPlatform->load();

sub setup {
my $self = shift;
Expand Down Expand Up @@ -387,7 +389,7 @@ sub add_category {
# try to insert
eval { $project->add_category( $valid->{category} ) };
if ($@) {
if ( $@ =~ /Duplicate entry/i ) {
if ( $DB_PLATFORM->unique_failure_msg($@) ) {
return $self->categories( { err_duplicate_category => 1 } );
} else {
die $@;
Expand Down
2 changes: 1 addition & 1 deletion lib/Smolder/Control/Public/Auth.pm
Expand Up @@ -43,7 +43,7 @@ sub login {

sub process_login {
my $self = shift;
my $form = { required => [qw(username password)], };
my $form = { required => [qw(username password)] };
my $results = $self->check_rm( 'login', $form )
|| return $self->check_rm_error_page();

Expand Down
7 changes: 7 additions & 0 deletions lib/Smolder/DB/Project.pm
Expand Up @@ -38,11 +38,18 @@ __PACKAGE__->has_a(
);

# make sure we delete any test_report directories associated with us
# also delete any categories too
__PACKAGE__->add_trigger(
before_delete => sub {
my $self = shift;
my $dir = catdir( InstallRoot, 'data', 'smoke_reports', $self->id );
rmtree($dir) if ( -d $dir );
foreach my $cat ($self->categories) {
my $sth = $self->db_Main->prepare_cached(qq(
DELETE FROM project_category WHERE project = ? AND category = ?
));
$sth->execute($self->id, $cat);
}
}
);

Expand Down
7 changes: 3 additions & 4 deletions lib/Smolder/DB/SmokeReport.pm
Expand Up @@ -236,10 +236,9 @@ sub send_emails {

my $sql = qq(
SELECT d.email, pref.email_type
FROM developer d
JOIN (project_developer pd, project p, preference pref )
ON (pd.developer = d.id AND pd.project = p.id AND pd.preference = pref.id)
WHERE p.id = ? AND $freq_clause
FROM developer d, project_developer pd, project p, preference pref
WHERE pd.developer = d.id AND pd.project = p.id AND pd.preference = pref.id
AND p.id = ? AND $freq_clause
);
my $sth = $self->db_Main->prepare_cached($sql);
$sth->execute( $self->project->id );
Expand Down
8 changes: 8 additions & 0 deletions lib/Smolder/DBPlatform.pm
Expand Up @@ -202,6 +202,14 @@ sub get_enum_values {
die "get_enum_values() must be implemented in the $class";
}

=head2 unique_failure_msg
=cut

sub unique_failure_msg {
my $class = shift;
die "unique_failure_msg() must be implemented in the $class";
}


1;
10 changes: 10 additions & 0 deletions lib/Smolder/DBPlatform/MySQL.pm
Expand Up @@ -253,5 +253,15 @@ sub get_enum_values {
return eval "[$text]";
}

=head2 unique_failure_msg
=cut

sub unique_failure_msg {
my ($class, $msg) = @_;
return $msg =~ /Duplicate entry/i;
}



1;
10 changes: 10 additions & 0 deletions lib/Smolder/DBPlatform/SQLite.pm
Expand Up @@ -192,6 +192,16 @@ sub get_enum_values {
return $enums->{$table}->{$column} || [];
}

=head2 unique_failure_msg
=cut

sub unique_failure_msg {
my ($class, $msg) = @_;
return $msg =~ /not unique\(1\)/i;
}


sub _get_db_file {
my ($class, $db_name) = @_;
return catfile($ENV{SMOLDER_ROOT}, 'data', "$db_name.sqlite");
Expand Down
59 changes: 0 additions & 59 deletions lib/Smolder/TestData.pm
Expand Up @@ -18,7 +18,6 @@ our @EXPORT_OK = qw(
delete_preferences
create_smoke_report
delete_smoke_reports
login
logout
is_apache_running
base_url
Expand Down Expand Up @@ -245,64 +244,6 @@ Will delete all test reports create by L<create_smoke_report>.
}
}

=head2 login
This routine will go to the login form, provide credentials
and login. It receives the following named args, all required:
=over
=item mech
The L<Test::WWW::Mechanize> object to use.
=item username
The text to use for the username field
=item password
The text to use for the password field. If none is given, it will use
'testing'.
=back
login(
mech => $mech,
username => $username,
password => 's3cr3t',
);
=cut

sub login {
my %args = @_;
my $mech = $args{mech};
my $url = base_url() . '/public_auth/login';
$mech->get($url);
$mech->form_name('login');
$mech->set_fields(
username => $args{username},
password => $args{password},
);
$mech->submit();
}

=head2 logout
Logout the current user given a L<Test::WWW::Mechanize> object
logout( mech => $mech );
=cut

sub logout {
my %args = @_;
my $mech = $args{mech};
my $url = base_url() . '/public_auth/logout';
$mech->get($url);
}

=head2 is_apache_running
Returns true if the Smolder Apache is up and running. Else returns false.
Expand Down

0 comments on commit 87e0b12

Please sign in to comment.